Skip to content

Commit 08af173

Browse files
authored
Merge release/22.7 into trunk (#15851)
2 parents bc805ac + c767d31 commit 08af173

File tree

37 files changed

+1090
-8396
lines changed

37 files changed

+1090
-8396
lines changed

WooCommerce/Classes/POS/Presentation/Barcode Scanning/HIDBarcodeParser.swift

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,26 +26,51 @@ final class HIDBarcodeParser {
2626
/// Process a key press event
2727
/// - Parameter key: The key that was pressed
2828
func processKeyPress(_ key: UIKey) {
29-
let currentTime = timeProvider.now()
30-
31-
// If characters are entered too slowly, it's probably typing and we should ignore it
32-
if let lastTime = lastKeyPressTime,
33-
currentTime.timeIntervalSince(lastTime) > configuration.maximumInterCharacterTime {
34-
onScan(.failure(HIDBarcodeParserError.timedOut(barcode: buffer)))
35-
resetScan()
29+
guard shouldRecogniseAsScanKeystroke(key) else {
30+
return
3631
}
3732

38-
lastKeyPressTime = currentTime
39-
4033
let character = key.characters
4134
if configuration.terminatingStrings.contains(character) {
4235
processScan()
4336
} else {
4437
guard !excludedKeys.contains(key.keyCode) else { return }
38+
checkForTimeoutBetweenKeystrokes()
4539
buffer.append(character)
4640
}
4741
}
4842

43+
private func shouldRecogniseAsScanKeystroke(_ key: UIKey) -> Bool {
44+
guard key.characters.isNotEmpty else {
45+
// This prevents a double-trigger-pull on a Star scanner from adding an error row –
46+
// Star use this as a shortcut to switch to the software keyboard. They send keycode 174 0xAE, which is
47+
// undefined and reserved in UIKeyboardHIDUsage. The scanner doesn't send a character with the code.
48+
// There seems to be no reason to handle empty input when considering scans.
49+
return false
50+
}
51+
52+
if buffer.isEmpty && configuration.terminatingStrings.contains(key.characters) {
53+
// We prefer to show all partial scans, but if we just get an enter with no numbers, ignoring it makes testing easier
54+
return false
55+
}
56+
57+
return true
58+
}
59+
60+
private func checkForTimeoutBetweenKeystrokes() {
61+
// If characters are entered too slowly, it's probably typing and we should ignore the old input.
62+
// The key we just received is still considered for adding to the buffer – we may simply reset the buffer first.
63+
let currentTime = timeProvider.now()
64+
65+
if let lastTime = lastKeyPressTime,
66+
currentTime.timeIntervalSince(lastTime) > configuration.maximumInterCharacterTime {
67+
onScan(.failure(HIDBarcodeParserError.timedOut(barcode: buffer)))
68+
resetScan()
69+
}
70+
71+
lastKeyPressTime = currentTime
72+
}
73+
4974
private let excludedKeys: [UIKeyboardHIDUsage] = [
5075
.keyboardCapsLock,
5176
.keyboardF1,
@@ -138,6 +163,7 @@ final class HIDBarcodeParser {
138163
}
139164

140165
private func processScan() {
166+
checkForTimeoutBetweenKeystrokes()
141167
if buffer.count >= configuration.minimumBarcodeLength {
142168
onScan(.success(buffer))
143169
} else {

WooCommerce/Classes/POS/Presentation/ItemRowView.swift

Lines changed: 79 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ struct ItemRowView: View {
2626

2727
var body: some View {
2828
itemRow
29-
.background(Color.posSurfaceContainerLowest)
30-
.frame(maxWidth: .infinity, idealHeight: dynamicTypeSize.isAccessibilitySize ? nil : dimension)
31-
.posItemCardBorderStyles()
3229
.padding(.horizontal, Constants.horizontalPadding)
3330
.geometryGroup()
3431
.accessibilityLabel(accessibilityLabel)
@@ -86,6 +83,9 @@ struct ItemRowView: View {
8683
}
8784
}
8885
.padding(.trailing, Constants.cardContentHorizontalPadding)
86+
.frame(maxWidth: .infinity, minHeight: dimension, alignment: .leading)
87+
.background(Color.posSurfaceContainerLowest)
88+
.posItemCardBorderStyles()
8989
}
9090

9191
@ViewBuilder
@@ -152,39 +152,84 @@ private extension ItemRowView {
152152

153153
#if DEBUG
154154
@available(iOS 17.0, *)
155-
#Preview(traits: .sizeThatFitsLayout) {
156-
ItemRowView(cartItem: Cart.PurchasableItem(id: UUID(),
157-
item: PointOfSalePreviewItemService().providePointOfSaleItem(),
158-
title: "Item Title",
159-
subtitle: "Item Subtitle",
160-
quantity: 2),
161-
onItemRemoveTapped: { })
162-
}
155+
#Preview {
156+
ScrollView {
157+
ItemRowView(
158+
cartItem: Cart.PurchasableItem(
159+
id: UUID(),
160+
item: PointOfSalePreviewItemService().providePointOfSaleItem(),
161+
title: "Item Title",
162+
subtitle: "Item Subtitle",
163+
quantity: 2
164+
),
165+
onItemRemoveTapped: { }
166+
)
163167

164-
@available(iOS 17.0, *)
165-
#Preview(traits: .sizeThatFitsLayout) {
166-
ItemRowView(cartItem: Cart.PurchasableItem(id: UUID(),
167-
item: PointOfSalePreviewItemService().providePointOfSaleItem(),
168-
title: "Item Title",
169-
subtitle: nil,
170-
quantity: 2),
171-
onItemRemoveTapped: { })
172-
}
168+
ItemRowView(
169+
cartItem: Cart.PurchasableItem(
170+
id: UUID(),
171+
item: PointOfSalePreviewItemService().providePointOfSaleItem(),
172+
title: "Item Title With incredible long title that goes incredibly far and beyond",
173+
subtitle: "Item Subtitle",
174+
quantity: 2
175+
),
176+
onItemRemoveTapped: { }
177+
)
173178

174-
@available(iOS 17.0, *)
175-
#Preview(traits: .sizeThatFitsLayout) {
176-
ItemRowView(cartItem: Cart.PurchasableItem.loading(id: UUID()),
177-
onCancelLoading: { })
178-
}
179+
ItemRowView(
180+
cartItem: Cart.PurchasableItem(
181+
id: UUID(),
182+
item: PointOfSalePreviewItemService().providePointOfSaleItem(),
183+
title: "Item Title",
184+
subtitle: nil,
185+
quantity: 2
186+
),
187+
onItemRemoveTapped: { }
188+
)
179189

180-
@available(iOS 17.0, *)
181-
#Preview(traits: .sizeThatFitsLayout) {
182-
ItemRowView.init(cartItem: Cart.PurchasableItem(
183-
id: UUID(),
184-
title: "123-123-123",
185-
subtitle: "Unspported product type",
186-
quantity: 1,
187-
state: .error
188-
))
190+
ItemRowView(
191+
cartItem: Cart.PurchasableItem.loading(id: UUID()),
192+
onCancelLoading: { }
193+
)
194+
195+
ItemRowView(
196+
cartItem: Cart.PurchasableItem(
197+
id: UUID(),
198+
title: "123-123-123",
199+
subtitle: "Unspported product type",
200+
quantity: 1,
201+
state: .error
202+
)
203+
)
204+
205+
ItemRowView(
206+
cartItem: Cart.PurchasableItem(
207+
id: UUID(),
208+
title: "123-123-123",
209+
subtitle: "Unspported product type with an incredibly long error message that goes on and on",
210+
quantity: 1,
211+
state: .error
212+
)
213+
)
214+
215+
ItemRowView(
216+
cartItem: Cart.PurchasableItem(
217+
id: UUID(),
218+
item: PointOfSalePreviewItemService().providePointOfSaleItem(),
219+
title: "Item Title",
220+
subtitle: nil,
221+
quantity: 2
222+
),
223+
showImage: .constant(false),
224+
onItemRemoveTapped: { }
225+
)
226+
227+
ItemRowView(
228+
cartItem: Cart.PurchasableItem.loading(id: UUID()),
229+
showImage: .constant(false),
230+
onCancelLoading: { }
231+
)
232+
}
233+
.frame(width: 400)
189234
}
190235
#endif

0 commit comments

Comments
 (0)