Skip to content

Commit a1dd2e5

Browse files
committed
Support both TextInput and GameController based scanning in the BarcodeScannerContainer
1 parent e65cea9 commit a1dd2e5

File tree

2 files changed

+50
-7
lines changed

2 files changed

+50
-7
lines changed

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

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,23 @@ struct BarcodeScannerContainerRepresentable: UIViewControllerRepresentable {
3939
let configuration: HIDBarcodeParserConfiguration
4040
let onScan: (Result<String, Error>) -> Void
4141

42-
func makeUIViewController(context: Context) -> BarcodeScannerHostingController {
43-
let controller = BarcodeScannerHostingController(
44-
configuration: configuration,
45-
onScan: onScan
46-
)
47-
return controller
42+
func makeUIViewController(context: Context) -> UIViewController {
43+
let featureFlagService = ServiceLocator.featureFlagService
44+
45+
if featureFlagService.isFeatureFlagEnabled(.pointOfSaleBarcodeScanningi2) {
46+
return GameControllerBarcodeScannerHostingController(
47+
configuration: configuration,
48+
onScan: onScan
49+
)
50+
} else {
51+
return BarcodeScannerHostingController(
52+
configuration: configuration,
53+
onScan: onScan
54+
)
55+
}
4856
}
4957

50-
func updateUIViewController(_ uiViewController: BarcodeScannerHostingController, context: Context) {}
58+
func updateUIViewController(_ uiViewController: UIViewController, context: Context) {}
5159
}
5260

5361
/// A UIHostingController that handles keyboard input events for barcode scanning.
@@ -115,3 +123,26 @@ class BarcodeScannerHostingController: UIHostingController<EmptyView> {
115123
super.pressesCancelled(presses, with: event)
116124
}
117125
}
126+
127+
/// A UIHostingController that handles GameController keyboard input events for barcode scanning.
128+
/// This controller uses GameController framework exclusively for language-independent barcode scanning.
129+
final class GameControllerBarcodeScannerHostingController: UIHostingController<EmptyView> {
130+
private var gameControllerBarcodeObserver: GameControllerBarcodeObserver?
131+
132+
init(
133+
configuration: HIDBarcodeParserConfiguration,
134+
onScan: @escaping (Result<String, Error>) -> Void
135+
) {
136+
super.init(rootView: EmptyView())
137+
138+
gameControllerBarcodeObserver = GameControllerBarcodeObserver(configuration: configuration, onScan: onScan)
139+
}
140+
141+
@MainActor required dynamic init?(coder aDecoder: NSCoder) {
142+
fatalError("init(coder:) has not been implemented")
143+
}
144+
145+
deinit {
146+
gameControllerBarcodeObserver = nil
147+
}
148+
}

WooCommerce/WooCommerce.xcodeproj/project.pbxproj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@
5252
0188CA0F2C65622A0051BF1C /* PointOfSaleCardPresentPaymentValidatingOrderErrorMessageViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0188CA0E2C65622A0051BF1C /* PointOfSaleCardPresentPaymentValidatingOrderErrorMessageViewModel.swift */; };
5353
0188CA112C6565320051BF1C /* PointOfSaleCardPresentPaymentValidatingOrderErrorMessageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0188CA102C6565320051BF1C /* PointOfSaleCardPresentPaymentValidatingOrderErrorMessageView.swift */; };
5454
018D5C7E2CA6B4A60085EBEE /* CurrencySettings+Sanitized.swift in Sources */ = {isa = PBXBuildFile; fileRef = 018D5C7D2CA6B49D0085EBEE /* CurrencySettings+Sanitized.swift */; };
55+
0190B44A2E1BDC7C00E1EC48 /* GameControllerBarcodeParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0190B4492E1BDC7C00E1EC48 /* GameControllerBarcodeParser.swift */; };
56+
0190B44C2E1BDC8E00E1EC48 /* GameControllerBarcodeParserTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0190B44B2E1BDC8E00E1EC48 /* GameControllerBarcodeParserTests.swift */; };
57+
0190B80A2E1C02DD00E1EC48 /* GameControllerBarcodeObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0190B8092E1C02DD00E1EC48 /* GameControllerBarcodeObserver.swift */; };
5558
019130192CF49A77008C0C88 /* TapToPayEducationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 019130182CF49A77008C0C88 /* TapToPayEducationView.swift */; };
5659
0191301B2CF4E782008C0C88 /* TapToPayEducationStepViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0191301A2CF4E77F008C0C88 /* TapToPayEducationStepViewModel.swift */; };
5760
0191301D2CF4E7B7008C0C88 /* TapToPayEducationViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0191301C2CF4E7B6008C0C88 /* TapToPayEducationViewModel.swift */; };
@@ -3208,6 +3211,9 @@
32083211
0188CA0E2C65622A0051BF1C /* PointOfSaleCardPresentPaymentValidatingOrderErrorMessageViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PointOfSaleCardPresentPaymentValidatingOrderErrorMessageViewModel.swift; sourceTree = "<group>"; };
32093212
0188CA102C6565320051BF1C /* PointOfSaleCardPresentPaymentValidatingOrderErrorMessageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PointOfSaleCardPresentPaymentValidatingOrderErrorMessageView.swift; sourceTree = "<group>"; };
32103213
018D5C7D2CA6B49D0085EBEE /* CurrencySettings+Sanitized.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CurrencySettings+Sanitized.swift"; sourceTree = "<group>"; };
3214+
0190B4492E1BDC7C00E1EC48 /* GameControllerBarcodeParser.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GameControllerBarcodeParser.swift; sourceTree = "<group>"; };
3215+
0190B44B2E1BDC8E00E1EC48 /* GameControllerBarcodeParserTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GameControllerBarcodeParserTests.swift; sourceTree = "<group>"; };
3216+
0190B8092E1C02DD00E1EC48 /* GameControllerBarcodeObserver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GameControllerBarcodeObserver.swift; sourceTree = "<group>"; };
32113217
019130182CF49A77008C0C88 /* TapToPayEducationView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TapToPayEducationView.swift; sourceTree = "<group>"; };
32123218
0191301A2CF4E77F008C0C88 /* TapToPayEducationStepViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TapToPayEducationStepViewModel.swift; sourceTree = "<group>"; };
32133219
0191301C2CF4E7B6008C0C88 /* TapToPayEducationViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TapToPayEducationViewModel.swift; sourceTree = "<group>"; };
@@ -8298,6 +8304,8 @@
82988304
20D557572DF9D57800D9EC8B /* Barcode Scanning */ = {
82998305
isa = PBXGroup;
83008306
children = (
8307+
0190B8092E1C02DD00E1EC48 /* GameControllerBarcodeObserver.swift */,
8308+
0190B4492E1BDC7C00E1EC48 /* GameControllerBarcodeParser.swift */,
83018309
202235F02DFAEAE500E13DE9 /* HIDBarcodeParser.swift */,
83028310
20CEBF222E02C760001F3300 /* TimeProvider.swift */,
83038311
20D5575C2DFADF5400D9EC8B /* BarcodeScannerContainer.swift */,
@@ -8309,6 +8317,7 @@
83098317
20D5575E2DFAE3D500D9EC8B /* Barcode Scanning */ = {
83108318
isa = PBXGroup;
83118319
children = (
8320+
0190B44B2E1BDC8E00E1EC48 /* GameControllerBarcodeParserTests.swift */,
83128321
202235F22DFAEC2700E13DE9 /* HIDBarcodeParserTests.swift */,
83138322
20CEBF242E02C7E6001F3300 /* MockTimeProvider.swift */,
83148323
);
@@ -15306,6 +15315,7 @@
1530615315
026A50282D2F6BD1002C42C2 /* InfiniteScrollTriggerDeterminable.swift in Sources */,
1530715316
2004E2CA2C07771400D62521 /* CardPresentPaymentReaderConnectionResult.swift in Sources */,
1530815317
860B85F12ADE3A0E00E85884 /* BulletPointView.swift in Sources */,
15318+
0190B44A2E1BDC7C00E1EC48 /* GameControllerBarcodeParser.swift in Sources */,
1530915319
D817586222BB64C300289CFE /* OrderDetailsNotices.swift in Sources */,
1531015320
022F7A0324A05F6400012601 /* LinkedProductsListSelectorViewController.swift in Sources */,
1531115321
2602A63F27BD880A00B347F1 /* NewOrderInitialStatusResolver.swift in Sources */,
@@ -16051,6 +16061,7 @@
1605116061
B6C78B8E293BAE68008934A1 /* AnalyticsHubLastMonthRangeData.swift in Sources */,
1605216062
B517EA18218B232700730EC4 /* StringFormatter+Notes.swift in Sources */,
1605316063
318109DC25E5B51900EE0BE7 /* ImageTableViewCell.swift in Sources */,
16064+
0190B80A2E1C02DD00E1EC48 /* GameControllerBarcodeObserver.swift in Sources */,
1605416065
262EB5B0298C7C3A009DCC36 /* SupportFormsDataSources.swift in Sources */,
1605516066
57C5FF7F250925C90074EC26 /* OrderListViewModel.swift in Sources */,
1605616067
029D02602C231F5F00CB1E75 /* PointOfSaleCardPresentPaymentReaderUpdateCompletionView.swift in Sources */,
@@ -17429,6 +17440,7 @@
1742917440
02C2756F24F5F5EE00286C04 /* ProductShippingSettingsViewModel+ProductVariationTests.swift in Sources */,
1743017441
EEBB9B402D8FE5B6008D6CE5 /* WooShippingSplitShipmentsViewModelTests.swift in Sources */,
1743117442
571FDDAE24C768DC00D486A5 /* MockZendeskManager.swift in Sources */,
17443+
0190B44C2E1BDC8E00E1EC48 /* GameControllerBarcodeParserTests.swift in Sources */,
1743217444
01AB2D122DDC7AD300AA67FD /* PointOfSaleItemListAnalyticsTrackerTests.swift in Sources */,
1743317445
45FBDF3C238D4EA800127F77 /* ExtendedAddProductImageCollectionViewCellTests.swift in Sources */,
1743417446
2609797C2A13D31500442249 /* PrivacyBannerPresentationUseCaseTests.swift in Sources */,

0 commit comments

Comments
 (0)