Skip to content

Commit

Permalink
Fix runtime warnings for missing Text environment values
Browse files Browse the repository at this point in the history
  • Loading branch information
PavelHolec committed Nov 12, 2024
1 parent 3a7a349 commit e37ff52
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
6 changes: 5 additions & 1 deletion Sources/Orbit/Components/Icon.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ public struct Icon: View, TextBuildable, PotentiallyEmptyView {

@Environment(\.iconColor) private var iconColor
@Environment(\.iconSize) private var iconSize
@Environment(\.lineSpacing) private var lineSpacing
@Environment(\.locale) private var locale
@Environment(\.localizationBundle) private var localizationBundle
@Environment(\.multilineTextAlignment) private var multilineTextAlignment
@Environment(\.textColor) private var textColor
@Environment(\.textFontWeight) private var textFontWeight
@Environment(\.textSize) private var textSize
Expand Down Expand Up @@ -112,11 +114,13 @@ public struct Icon: View, TextBuildable, PotentiallyEmptyView {
.init(
iconColor: iconColor,
iconSize: iconSize,
lineSpacing: lineSpacing,
locale: locale,
localizationBundle: localizationBundle,
textAccentColor: nil,
textAlignment: multilineTextAlignment,
textColor: textColor,
textFontWeight: textFontWeight,
textFontWeight: textFontWeight,
textLineHeight: nil,
textSize: textSize,
sizeCategory: sizeCategory
Expand Down
6 changes: 4 additions & 2 deletions Sources/Orbit/Components/Text.swift
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,11 @@ public struct Text: View, FormattedTextBuildable, PotentiallyEmptyView, CustomSt
.init(
iconColor: nil,
iconSize: nil,
lineSpacing: lineSpacing,
locale: locale,
localizationBundle: localizationBundle,
textAccentColor: textAccentColor,
textAlignment: multilineTextAlignment,
textColor: textColor,
textFontWeight: textFontWeight,
textLineHeight: lineHeight,
Expand Down Expand Up @@ -331,7 +333,7 @@ public struct Text: View, FormattedTextBuildable, PotentiallyEmptyView, CustomSt
) -> NSAttributedString {
TagAttributedStringBuilder.all.attributedString(
content(environment),
alignment: multilineTextAlignment,
alignment: environment.textAlignment ?? .leading,
fontSize: environment.scaledSize(size),
fontWeight: environment.resolvedFontWeight(fontWeight, isBold: isBold),
lineSpacing: lineSpacingAdjusted(environment: environment),
Expand All @@ -343,7 +345,7 @@ public struct Text: View, FormattedTextBuildable, PotentiallyEmptyView, CustomSt
}

private func lineSpacingAdjusted(environment: TextRepresentableEnvironment) -> CGFloat {
environment.lineSpacingAdjusted(lineSpacing, lineHeight: lineHeight, size: size)
environment.lineSpacingAdjusted(environment.lineSpacing ?? 0, lineHeight: lineHeight, size: size)
}

private init(localization: TextLocalization?, description: String) {
Expand Down
3 changes: 3 additions & 0 deletions Sources/Orbit/Support/Text/ConcatenatedText.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ struct ConcatenatedText: View {
@Environment(\.lineSpacing) var lineSpacing
@Environment(\.locale) var locale
@Environment(\.localizationBundle) var localizationBundle
@Environment(\.multilineTextAlignment) var multilineTextAlignment
@Environment(\.sizeCategory) var sizeCategory
@Environment(\.textAccentColor) var textAccentColor
@Environment(\.textColor) var textColor
Expand Down Expand Up @@ -34,9 +35,11 @@ struct ConcatenatedText: View {
.init(
iconColor: iconColor,
iconSize: iconSize,
lineSpacing: lineSpacing,
locale: locale,
localizationBundle: localizationBundle,
textAccentColor: textAccentColor,
textAlignment: multilineTextAlignment,
textColor: textColor,
textFontWeight: textFontWeight,
textLineHeight: textLineHeight,
Expand Down
8 changes: 8 additions & 0 deletions Sources/Orbit/Support/Text/TextRepresentable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ public struct TextRepresentableEnvironment {

public let iconColor: Color?
public let iconSize: CGFloat?
public let lineSpacing: CGFloat?
public let locale: Locale
public let localizationBundle: Bundle
public let textAccentColor: Color?
public let textAlignment: TextAlignment?
public let textColor: Color?
public let textFontWeight: Font.Weight?
public let textLineHeight: CGFloat?
Expand All @@ -26,9 +28,11 @@ public struct TextRepresentableEnvironment {
public init(
iconColor: Color?,
iconSize: CGFloat?,
lineSpacing: CGFloat?,
locale: Locale,
localizationBundle: Bundle,
textAccentColor: Color?,
textAlignment: TextAlignment?,
textColor: Color?,
textFontWeight: Font.Weight?,
textLineHeight: CGFloat?,
Expand All @@ -37,9 +41,11 @@ public struct TextRepresentableEnvironment {
) {
self.iconColor = iconColor
self.iconSize = iconSize
self.lineSpacing = lineSpacing
self.locale = locale
self.localizationBundle = localizationBundle
self.textAccentColor = textAccentColor
self.textAlignment = textAlignment
self.textColor = textColor
self.textFontWeight = textFontWeight
self.textLineHeight = textLineHeight
Expand All @@ -51,9 +57,11 @@ public struct TextRepresentableEnvironment {
public init(locale: Locale, localizationBundle: Bundle) {
self.iconColor = nil
self.iconSize = nil
self.lineSpacing = nil
self.locale = locale
self.localizationBundle = localizationBundle
self.textAccentColor = nil
self.textAlignment = nil
self.textColor = nil
self.textFontWeight = nil
self.textLineHeight = nil
Expand Down

0 comments on commit e37ff52

Please sign in to comment.