Skip to content

Commit bb33741

Browse files
committed
Use a scaled metric property to scale the stepper with the font size
1 parent b3e196e commit bb33741

File tree

1 file changed

+11
-32
lines changed

1 file changed

+11
-32
lines changed

WooCommerce/Classes/ViewRelated/Orders/Order Creation/NewOrder.swift

Lines changed: 11 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -148,33 +148,33 @@ private struct ProductsSection: View {
148148
/// Used to change the product quantity in the order.
149149
///
150150
struct ProductStepper: View {
151-
@State var textSize: CGSize = .zero
151+
152+
// Tracks the scale of the view due to accessibility changes
153+
@ScaledMetric private var scale: CGFloat = 1
152154

153155
var body: some View {
154-
HStack(spacing: textSize.height) {
156+
HStack(spacing: NewOrder.Layout.stepperSpacing * scale) {
155157
Button {
156158
// TODO: Decrement the product quantity
157159
} label: {
158160
Image(uiImage: .minusSmallImage)
159161
.resizable()
160162
.aspectRatio(contentMode: .fit)
161-
.frame(height: textSize.height)
163+
.frame(height: NewOrder.Layout.stepperButtonSize * scale)
162164
}
165+
163166
Text("1") // Fake data - quantity
164-
.background(ViewGeometry())
165-
.onPreferenceChange(ViewSizeKey.self) {
166-
textSize = $0
167-
}
167+
168168
Button {
169169
// TODO: Increment the product quantity
170170
} label: {
171171
Image(uiImage: .plusSmallImage)
172172
.resizable()
173173
.aspectRatio(contentMode: .fit)
174-
.frame(height: textSize.height)
174+
.frame(height: NewOrder.Layout.stepperButtonSize * scale)
175175
}
176176
}
177-
.padding(textSize.height/2)
177+
.padding(NewOrder.Layout.stepperSpacing/2 * scale)
178178
.overlay(
179179
RoundedRectangle(cornerRadius: NewOrder.Layout.stepperBorderRadius)
180180
.stroke(Color(UIColor.separator), lineWidth: NewOrder.Layout.stepperBorderWidth)
@@ -193,29 +193,6 @@ private struct ProductsSection: View {
193193
}
194194
}
195195
}
196-
197-
/// Custom preference key to get the size of a view
198-
///
199-
struct ViewSizeKey: PreferenceKey {
200-
static var defaultValue: CGSize = .zero
201-
202-
static func reduce(value: inout CGSize, nextValue: () -> CGSize) {
203-
value = nextValue()
204-
}
205-
}
206-
207-
/// View that calculates its size and sets ViewSizeKey
208-
///
209-
/// Used to ensure that stepper button height matches text height, and overlay border is set correctly at larger text sizes.
210-
///
211-
struct ViewGeometry: View {
212-
var body: some View {
213-
GeometryReader { geometry in
214-
Color.clear
215-
.preference(key: ViewSizeKey.self, value: geometry.size)
216-
}
217-
}
218-
}
219196
}
220197
}
221198

@@ -248,6 +225,8 @@ private extension NewOrder {
248225
static let productImageSize: CGFloat = 44.0
249226
static let stepperBorderWidth: CGFloat = 1.0
250227
static let stepperBorderRadius: CGFloat = 4.0
228+
static let stepperButtonSize: CGFloat = 22.0
229+
static let stepperSpacing: CGFloat = 22.0
251230
}
252231

253232
enum Localization {

0 commit comments

Comments
 (0)