Skip to content

Commit a1e219e

Browse files
committed
Update POSFontStyle to use dynamicTypeSize instead of maximumContentSizeCategory
POSFontStyle should react to global dynamicTypeSize changes to make it more versatile
1 parent a477857 commit a1e219e

File tree

6 files changed

+39
-14
lines changed

6 files changed

+39
-14
lines changed

WooCommerce/Classes/POS/Presentation/CardReaderConnection/CardReaderConnectionStatusView.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ struct CardReaderConnectionStatusView: View {
5858
}
5959
}
6060
}
61-
.font(Constants.font, maximumContentSizeCategory: .accessibilityLarge)
61+
.font(Constants.font)
62+
.dynamicTypeSize(...DynamicTypeSize.accessibility2)
6263
.opacity(isEnabled ? 1 : 0.5)
6364
}
6465
}

WooCommerce/Classes/POS/Presentation/Item Selector/ChildItemList.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ private extension ChildItemList {
5050
dismiss()
5151
} label: {
5252
Image(systemName: "chevron.backward")
53-
.font(.posBodyLargeBold, maximumContentSizeCategory: .accessibilityLarge)
53+
.font(.posBodyLargeBold)
54+
.dynamicTypeSize(...DynamicTypeSize.accessibility2)
5455
.foregroundColor(.posOnSurface)
5556
}
5657
POSHeaderTitleView(title: title)

WooCommerce/Classes/POS/Presentation/ItemListView.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,9 @@ private extension ItemListView {
122122
.padding(.bottom, Constants.bannerCardPadding)
123123
}
124124

125-
private var bannerHintAndLearnMoreText: Text {
126-
Text(headerBannerHint + " ") +
127-
Text(Localization.headerBannerLearnMoreHint)
128-
.font(POSFontStyle.posBodySmallBold.font())
125+
private var bannerHintAndLearnMoreText: some View {
126+
Text("\(headerBannerHint) \(Localization.headerBannerLearnMoreHint)")
127+
.font(.posBodySmallBold)
129128
.foregroundColor(Color(.posPrimary))
130129
}
131130

WooCommerce/Classes/POS/Presentation/POSFloatingControlView.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ struct POSFloatingControlView: View {
5050
VStack {
5151
Spacer()
5252
Image(systemName: "ellipsis")
53-
.font(.posBodyLargeBold, maximumContentSizeCategory: .accessibilityLarge)
53+
.font(.posBodyLargeBold)
54+
.dynamicTypeSize(...DynamicTypeSize.accessibility2)
5455
.foregroundStyle(fontColor)
5556
Spacer()
5657
}

WooCommerce/Classes/POS/Presentation/PointOfSaleCollectCashView.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ private extension PointOfSaleCollectCashView {
104104
var navigationHeader: some View {
105105
HStack(alignment: .top) {
106106
Image(systemName: "chevron.backward")
107-
.font(.posBodyLargeBold, maximumContentSizeCategory: .accessibilityLarge)
107+
.font(.posBodyLargeBold)
108+
.dynamicTypeSize(...DynamicTypeSize.accessibility2)
108109
DynamicVStack(horizontalAlignment: .leading, spacing: Constants.navigationButtonSpacing) {
109110
Text(Localization.backNavigationTitle)
110111
.font(.posHeading)

WooCommerce/Classes/POS/Utils/POSFontStyle.swift

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ enum POSFontStyle {
1717
case posButtonSymbolMedium
1818
case posButtonSymbolLarge
1919

20-
func font(maximumContentSizeCategory: UIContentSizeCategory? = nil) -> Font {
20+
fileprivate func font(maximumContentSizeCategory: UIContentSizeCategory? = nil) -> Font {
2121
switch self {
2222
case .posHeading:
2323
Font.system(size: scaledValue(FontSize.heading, maximumContentSizeCategory: maximumContentSizeCategory ?? .accessibilityLarge), weight: .bold)
@@ -81,11 +81,12 @@ private struct POSScaledFont: ViewModifier {
8181
// Declaring dynamicTypeSize ensures it's automatically observed
8282
@Environment(\.dynamicTypeSize) var dynamicTypeSize
8383
var style: POSFontStyle
84-
var maximumContentSizeCategory: UIContentSizeCategory? = nil
8584

8685
func body(content: Content) -> some View {
87-
content
88-
.font(style.font(maximumContentSizeCategory: maximumContentSizeCategory))
86+
let category = UIContentSizeCategory(dynamicTypeSize)
87+
88+
return content
89+
.font(style.font(maximumContentSizeCategory: category))
8990
.if(shouldUnderline()) { view in
9091
view.underline()
9192
}
@@ -104,8 +105,29 @@ private struct POSScaledFont: ViewModifier {
104105
}
105106

106107
extension View {
107-
func font(_ style: POSFontStyle, maximumContentSizeCategory: UIContentSizeCategory? = nil) -> some View {
108-
return self.modifier(POSScaledFont(style: style, maximumContentSizeCategory: maximumContentSizeCategory))
108+
func font(_ style: POSFontStyle) -> some View {
109+
return self.modifier(POSScaledFont(style: style))
110+
}
111+
}
112+
113+
// Helper to convert DynamicTypeSize to UIContentSizeCategory
114+
extension UIContentSizeCategory {
115+
init(_ dynamicTypeSize: DynamicTypeSize) {
116+
switch dynamicTypeSize {
117+
case .xSmall: self = .extraSmall
118+
case .small: self = .small
119+
case .medium: self = .medium
120+
case .large: self = .large
121+
case .xLarge: self = .extraLarge
122+
case .xxLarge: self = .extraExtraLarge
123+
case .xxxLarge: self = .extraExtraExtraLarge
124+
case .accessibility1: self = .accessibilityMedium
125+
case .accessibility2: self = .accessibilityLarge
126+
case .accessibility3: self = .accessibilityExtraLarge
127+
case .accessibility4: self = .accessibilityExtraExtraLarge
128+
case .accessibility5: self = .accessibilityExtraExtraExtraLarge
129+
@unknown default: self = .large
130+
}
109131
}
110132
}
111133

0 commit comments

Comments
 (0)