Skip to content

Commit 0244aae

Browse files
committed
Track isShiftPressed state
Shift press and un-press events are reported by keyChangedHandler. We need to use those to determine whether the shift key needs to be applied to the next character.
1 parent dc4f86e commit 0244aae

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

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

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ final class GameControllerBarcodeObserver {
2121
private var barcodeParser: GameControllerBarcodeParser?
2222
private let configuration: HIDBarcodeParserConfiguration
2323

24+
/// Tracks current shift state to be applied to the next character key
25+
private var isShiftPressed: Bool = false
26+
2427
/// Initializes a new barcode scanner observer.
2528
/// - Parameters:
2629
/// - configuration: The configuration to use for the barcode parser. Defaults to the standard configuration.
@@ -89,11 +92,16 @@ final class GameControllerBarcodeObserver {
8992
barcodeParser = GameControllerBarcodeParser(configuration: configuration, onScan: onScan)
9093

9194
keyboard.keyboardInput?.keyChangedHandler = { [weak self] _, _, keyCode, pressed in
92-
guard let self = self, pressed else { return }
93-
let leftShiftPressed = keyboard.keyboardInput?.button(forKeyCode: .leftShift)?.isPressed == true
94-
let rightShiftPressed = keyboard.keyboardInput?.button(forKeyCode: .rightShift)?.isPressed == true
95-
let shiftPressed = leftShiftPressed || rightShiftPressed
96-
self.barcodeParser?.processKeyPress(keyCode, isShiftPressed: shiftPressed)
95+
guard let self = self else { return }
96+
97+
if keyCode == .leftShift || keyCode == .rightShift {
98+
self.isShiftPressed = pressed
99+
return
100+
}
101+
102+
guard pressed else { return }
103+
104+
self.barcodeParser?.processKeyPress(keyCode, isShiftPressed: isShiftPressed)
97105
}
98106
}
99107

@@ -103,5 +111,6 @@ final class GameControllerBarcodeObserver {
103111
barcodeParser?.cancel()
104112
coalescedKeyboard = nil
105113
barcodeParser = nil
114+
isShiftPressed = false
106115
}
107116
}

WooCommerce/WooCommerce.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
015D99AA2C58C780001D7186 /* PointOfSaleCardPresentPaymentLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 015D99A92C58C780001D7186 /* PointOfSaleCardPresentPaymentLayout.swift */; };
4343
01620C4E2C5394B200D3EA2F /* POSProgressViewStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01620C4D2C5394B200D3EA2F /* POSProgressViewStyle.swift */; };
4444
01664F9E2C50E685007CB5DD /* POSFontStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01664F9D2C50E685007CB5DD /* POSFontStyle.swift */; };
45+
016910982E1D019500B731DA /* GameControllerBarcodeObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 016910972E1D019500B731DA /* GameControllerBarcodeObserver.swift */; };
4546
016A77692D9D24B00004FCD6 /* POSCouponCreationSheet.swift in Sources */ = {isa = PBXBuildFile; fileRef = 016A77682D9D24A70004FCD6 /* POSCouponCreationSheet.swift */; };
4647
016C6B972C74AB17000D86FD /* POSConnectivityView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 016C6B962C74AB17000D86FD /* POSConnectivityView.swift */; };
4748
0174DDBB2CE5FD60005D20CA /* ReceiptEmailViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0174DDBA2CE5FD5D005D20CA /* ReceiptEmailViewModel.swift */; };
@@ -3200,6 +3201,7 @@
32003201
015D99A92C58C780001D7186 /* PointOfSaleCardPresentPaymentLayout.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PointOfSaleCardPresentPaymentLayout.swift; sourceTree = "<group>"; };
32013202
01620C4D2C5394B200D3EA2F /* POSProgressViewStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = POSProgressViewStyle.swift; sourceTree = "<group>"; };
32023203
01664F9D2C50E685007CB5DD /* POSFontStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = POSFontStyle.swift; sourceTree = "<group>"; };
3204+
016910972E1D019500B731DA /* GameControllerBarcodeObserver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GameControllerBarcodeObserver.swift; sourceTree = "<group>"; };
32033205
016A77682D9D24A70004FCD6 /* POSCouponCreationSheet.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = POSCouponCreationSheet.swift; sourceTree = "<group>"; };
32043206
016C6B962C74AB17000D86FD /* POSConnectivityView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = POSConnectivityView.swift; sourceTree = "<group>"; };
32053207
0174DDBA2CE5FD5D005D20CA /* ReceiptEmailViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReceiptEmailViewModel.swift; sourceTree = "<group>"; };
@@ -8302,6 +8304,7 @@
83028304
20D557572DF9D57800D9EC8B /* Barcode Scanning */ = {
83038305
isa = PBXGroup;
83048306
children = (
8307+
016910972E1D019500B731DA /* GameControllerBarcodeObserver.swift */,
83058308
0177250B2E1CFF7F00016148 /* GameControllerBarcodeParser.swift */,
83068309
202235F02DFAEAE500E13DE9 /* HIDBarcodeParser.swift */,
83078310
20CEBF222E02C760001F3300 /* TimeProvider.swift */,
@@ -15075,6 +15078,7 @@
1507515078
451A9973260E39270059D135 /* ShippingLabelPackageNumberRow.swift in Sources */,
1507615079
AEE2610F26E664CE00B142A0 /* EditOrderAddressFormViewModel.swift in Sources */,
1507715080
025C00BA25514A7100FAC222 /* BarcodeScannerFrameScaler.swift in Sources */,
15081+
016910982E1D019500B731DA /* GameControllerBarcodeObserver.swift in Sources */,
1507815082
EE9D031B2B89E4470077CED1 /* FilterOrdersByProduct+Analytics.swift in Sources */,
1507915083
20C6E7512CDE4AEA00CD124C /* ItemListState.swift in Sources */,
1508015084
DEC17AE02D82C513005A6E6D /* WooShippingHazmatDetailView.swift in Sources */,

0 commit comments

Comments
 (0)