@@ -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+ }
0 commit comments