react-native-scanbot-barcode-scanner-sdk 4.2.0 → 4.3.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/Libraries.txt +31 -31
  2. package/RNScanbotBarcodeSDK.podspec +1 -4
  3. package/android/build.gradle +6 -5
  4. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/ScanbotBarcodeSdkPackage.kt +9 -7
  5. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/barcode_scanner_view/ScanbotBarcodeScannerView.kt +114 -0
  6. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/barcode_scanner_view/ScanbotBarcodeScannerViewEvents.kt +56 -0
  7. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/barcode_scanner_view/ScanbotBarcodeScannerViewManager.kt +256 -0
  8. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/extensions/JSONObject.kt +18 -2
  9. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/extensions/ReadableMap.kt +3 -4
  10. package/android/src/newarch/ScanbotBarcodeScannerViewManagerSpec.kt +19 -0
  11. package/android/src/oldarch/ScanbotBarcodeScannerViewManagerSpec.kt +29 -0
  12. package/dist/components/barcode-camera-view/ScanbotBarcodeCameraView.d.ts +3 -0
  13. package/dist/components/barcode-camera-view/ScanbotBarcodeCameraView.js +122 -0
  14. package/dist/components/barcode-camera-view/ScanbotBarcodeCameraViewProperties.d.ts +89 -0
  15. package/dist/components/barcode-camera-view/ScanbotBarcodeCameraViewProperties.js +2 -0
  16. package/dist/components/spec/ScanbotBarcodeScannerViewNativeComponent.d.ts +54 -0
  17. package/dist/components/spec/ScanbotBarcodeScannerViewNativeComponent.js +12 -0
  18. package/dist/configurations.d.ts +241 -0
  19. package/dist/configurations.js +2 -0
  20. package/dist/customConfigurations.d.ts +94 -0
  21. package/dist/customConfigurations.js +2 -0
  22. package/dist/customResults.d.ts +5 -0
  23. package/dist/customResults.js +2 -0
  24. package/dist/customTypes.d.ts +7 -0
  25. package/dist/customTypes.js +2 -0
  26. package/dist/index.d.ts +26 -0
  27. package/dist/index.js +34 -0
  28. package/dist/results.d.ts +29 -0
  29. package/dist/results.js +2 -0
  30. package/dist/types.d.ts +1194 -0
  31. package/dist/types.js +2 -0
  32. package/ios/Components/BarcodeScannerView/RNScanbotBarcodeScannerLegacyView.h +25 -0
  33. package/ios/Components/BarcodeScannerView/RNScanbotBarcodeScannerLegacyView.m +194 -0
  34. package/ios/Components/BarcodeScannerView/RNScanbotBarcodeScannerView.h +20 -0
  35. package/ios/Components/BarcodeScannerView/RNScanbotBarcodeScannerView.mm +259 -0
  36. package/ios/Components/BarcodeScannerView/RNScanbotBarcodeScannerViewControllerWrapper.h +99 -0
  37. package/ios/Components/BarcodeScannerView/RNScanbotBarcodeScannerViewControllerWrapper.m +196 -0
  38. package/ios/Components/BarcodeScannerView/RNScanbotBarcodeScannerViewManager.mm +73 -0
  39. package/package.json +16 -21
  40. package/src/components/barcode-camera-view/ScanbotBarcodeCameraView.tsx +112 -0
  41. package/src/components/barcode-camera-view/ScanbotBarcodeCameraViewProperties.ts +106 -0
  42. package/src/components/spec/ScanbotBarcodeScannerViewNativeComponent.ts +59 -0
  43. package/src/index.ts +58 -0
  44. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/barcodecameraview/ScanbotBarcodeCameraView.java +0 -401
  45. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/base/communication/ScanbotEventEmitter.java +0 -78
  46. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/base/communication/ScanbotEventReceiver.java +0 -119
  47. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/base/ui/ScanbotViewWrapper.java +0 -26
  48. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/utils/JSONUtils.kt +0 -24
  49. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/utils/ScanbotViewUtils.java +0 -43
  50. package/android/src/new-architecture/io/scanbot/barcodesdk/plugin/reactnative/components/barcodecameraview/ScanbotBarcodeCameraViewManager.java +0 -125
  51. package/android/src/old-architecture/io/scanbot/barcodesdk/plugin/reactnative/components/barcodecameraview/ScanbotBarcodeCameraViewManager.java +0 -114
  52. package/index.d.ts +0 -42
  53. package/index.js +0 -20
  54. package/ios/Components/BarcodeCameraView/NewArchitecture/RTNScanbotBarcodeCameraView.h +0 -44
  55. package/ios/Components/BarcodeCameraView/NewArchitecture/RTNScanbotBarcodeCameraView.mm +0 -338
  56. package/ios/Components/BarcodeCameraView/NewArchitecture/RTNScanbotBarcodeCameraViewManager.mm +0 -71
  57. package/ios/Components/BarcodeCameraView/OldArchitecture/RNScanbotBarcodeCameraView.h +0 -36
  58. package/ios/Components/BarcodeCameraView/OldArchitecture/RNScanbotBarcodeCameraView.mm +0 -181
  59. package/ios/Components/BarcodeCameraView/OldArchitecture/RNScanbotBarcodeCameraViewManager.h +0 -28
  60. package/ios/Components/BarcodeCameraView/OldArchitecture/RNScanbotBarcodeCameraViewManager.mm +0 -89
  61. package/js/RTNScanbotBarcodeCameraViewNativeComponent.ts +0 -186
  62. package/src/components/barcode-camera-view/scanbot-barcode-camera-view-types.ts +0 -175
  63. package/src/components/barcode-camera-view/scanbot-barcode-camera-view.tsx +0 -270
  64. package/src/components/barcode-camera-view/scanbot-native-barcode-camera-view.ts +0 -7
@@ -1,125 +0,0 @@
1
- package io.scanbot.barcodesdk.plugin.reactnative.components.barcodecameraview;
2
-
3
- import androidx.annotation.NonNull;
4
- import androidx.annotation.Nullable;
5
-
6
- import com.facebook.react.bridge.ReadableArray;
7
- import com.facebook.react.bridge.ReadableMap;
8
- import com.facebook.react.module.annotations.ReactModule;
9
- import com.facebook.react.uimanager.ThemedReactContext;
10
- import com.facebook.react.uimanager.ViewGroupManager;
11
- import com.facebook.react.uimanager.annotations.ReactProp;
12
- import com.facebook.react.viewmanagers.RTNScanbotBarcodeCameraViewManagerInterface;
13
-
14
- import java.util.Map;
15
-
16
- import io.scanbot.barcodesdk.plugin.reactnative.components.base.communication.ScanbotEventEmitter;
17
- import io.scanbot.barcodesdk.plugin.reactnative.components.base.communication.ScanbotEventEmitter.NativeEvent;
18
- import io.scanbot.barcodesdk.plugin.reactnative.components.base.communication.ScanbotEventReceiver;
19
- import io.scanbot.barcodesdk.plugin.reactnative.components.base.communication.ScanbotEventReceiver.CommonEvents;
20
-
21
- @ReactModule(name = ScanbotBarcodeCameraViewManager.NAME)
22
- public class ScanbotBarcodeCameraViewManager
23
- extends ViewGroupManager<ScanbotBarcodeCameraView>
24
- implements RTNScanbotBarcodeCameraViewManagerInterface<ScanbotBarcodeCameraView>, ScanbotEventReceiver.IEventHandler
25
- {
26
- static final String NAME = "RTNScanbotBarcodeCameraView";
27
- @NonNull @Override public String getName() { return NAME; }
28
-
29
- private ScanbotBarcodeCameraView barcodeCameraView;
30
- private final ScanbotEventReceiver eventReceiver;
31
- private boolean shouldRefreshConfig = false;
32
-
33
- public ScanbotBarcodeCameraViewManager() {
34
- super();
35
- this.eventReceiver = new ScanbotEventReceiver(this, new ScanbotEventReceiver.JavaScriptEvent[] {});
36
- }
37
-
38
- @NonNull
39
- @Override
40
- protected ScanbotBarcodeCameraView createViewInstance(@NonNull ThemedReactContext context) {
41
- this.barcodeCameraView = new ScanbotBarcodeCameraView(context);
42
- return this.barcodeCameraView;
43
- }
44
-
45
- /*-----------------------*
46
- * Component Lifecycle
47
- *------------------------*/
48
- @Override
49
- public void componentDidUpdate(ScanbotBarcodeCameraView view) {
50
- if (shouldRefreshConfig) {
51
- this.barcodeCameraView.refreshConfiguration();
52
- shouldRefreshConfig = false;
53
- }
54
- }
55
- @Override
56
- public void orientationChanged(ScanbotBarcodeCameraView view) {
57
- shouldRefreshConfig = true;
58
- }
59
-
60
- @Override
61
- public void componentDidMount(ScanbotBarcodeCameraView view) {
62
- }
63
-
64
- @Override
65
- public void componentWillUnmount(ScanbotBarcodeCameraView view) {
66
- }
67
-
68
- /*-----------------------*
69
- * Events Handling
70
- *------------------------*/
71
- @Override
72
- public void receiveCommand(@NonNull ScanbotBarcodeCameraView root, String commandId, @Nullable ReadableArray args) {
73
- super.receiveCommand(root, commandId, args);
74
- eventReceiver.receiveCommand(commandId, args);
75
- }
76
-
77
- @Nullable
78
- @Override
79
- public Map<String, Object> getExportedCustomDirectEventTypeConstants() {
80
- final NativeEvent[] commonEvents = ScanbotEventEmitter.CommonEvents.values();
81
- final NativeEvent[] customEvents = ScanbotBarcodeCameraView.getNativeEvents();
82
- final NativeEvent[] allEvents = ScanbotEventEmitter.concatEvents(commonEvents, customEvents);
83
- return ScanbotEventEmitter.getMapForNativeEvents(allEvents);
84
- }
85
-
86
- @Override
87
- public void eventHandler_eventReceived(ScanbotEventReceiver.JavaScriptEvent event, @Nullable ReadableArray args) {
88
- CommonEvents commonEvent = eventReceiver.getCommonEventFromName(event.getName());
89
- if (commonEvent == null) {
90
- return;
91
- }
92
- this.handleCommonEvent(commonEvent, args);
93
- }
94
-
95
- private void handleCommonEvent(CommonEvents commonEvent, @Nullable ReadableArray ignoredArgs) {
96
- switch (commonEvent) {
97
- case COMPONENT_DID_UPDATE:
98
- componentDidUpdate(null);
99
- break;
100
- case COMPONENT_DID_MOUNT:
101
- componentDidMount(null);
102
- break;
103
- case COMPONENT_WILL_UNMOUNT:
104
- componentWillUnmount(null);
105
- break;
106
- case ORIENTATION_CHANGED:
107
- orientationChanged(null);
108
- break;
109
- }
110
- }
111
-
112
- @Nullable
113
- @Override
114
- public Map<String, Integer> getCommandsMap() {
115
- return eventReceiver.getCommandsMap();
116
- }
117
-
118
- @Override
119
- @ReactProp(name = "configuration")
120
- public void setConfiguration(ScanbotBarcodeCameraView view, @Nullable ReadableMap value) {
121
- if (barcodeCameraView == null) { return; }
122
- if (value == null) { return; }
123
- barcodeCameraView.applyConfiguration(value);
124
- }
125
- }
@@ -1,114 +0,0 @@
1
- package io.scanbot.barcodesdk.plugin.reactnative.components.barcodecameraview;
2
-
3
- import android.widget.FrameLayout;
4
-
5
- import androidx.annotation.NonNull;
6
- import androidx.annotation.Nullable;
7
-
8
- import com.facebook.react.bridge.ReadableArray;
9
- import com.facebook.react.bridge.ReadableMap;
10
- import com.facebook.react.uimanager.ThemedReactContext;
11
- import com.facebook.react.uimanager.ViewGroupManager;
12
- import com.facebook.react.uimanager.annotations.ReactProp;
13
-
14
- import java.util.Map;
15
-
16
- import io.scanbot.barcodesdk.plugin.reactnative.components.base.communication.ScanbotEventEmitter;
17
- import io.scanbot.barcodesdk.plugin.reactnative.components.base.communication.ScanbotEventEmitter.NativeEvent;
18
- import io.scanbot.barcodesdk.plugin.reactnative.components.base.communication.ScanbotEventReceiver;
19
- import io.scanbot.barcodesdk.plugin.reactnative.components.base.communication.ScanbotEventReceiver.CommonEvents;
20
-
21
- public class ScanbotBarcodeCameraViewManager extends ViewGroupManager<ScanbotBarcodeCameraView> implements ScanbotEventReceiver.IEventHandler {
22
- private static final String TAG = "RTNScanbotBarcodeCameraView";
23
- @NonNull @Override public String getName() { return TAG; }
24
-
25
- private ScanbotBarcodeCameraView barcodeCameraView;
26
- private final ScanbotEventReceiver eventReceiver;
27
- private boolean shouldRefreshConfig = false;
28
-
29
- public ScanbotBarcodeCameraViewManager() {
30
- super();
31
- this.eventReceiver = new ScanbotEventReceiver(this, new ScanbotEventReceiver.JavaScriptEvent[] {});
32
- }
33
-
34
- @SuppressWarnings("unused")
35
- @ReactProp(name = "configuration")
36
- public void setConfiguration(FrameLayout frameLayout, ReadableMap configuration) {
37
- if (barcodeCameraView == null) { return; }
38
- barcodeCameraView.applyConfiguration(configuration);
39
- }
40
-
41
- @NonNull
42
- @Override
43
- protected ScanbotBarcodeCameraView createViewInstance(@NonNull ThemedReactContext context) {
44
- this.barcodeCameraView = new ScanbotBarcodeCameraView(context);
45
- return this.barcodeCameraView;
46
- }
47
-
48
- /*-----------------------*
49
- * Component Lifecycle
50
- *------------------------*/
51
- protected void componentDidUpdate() {
52
- if (shouldRefreshConfig) {
53
- this.barcodeCameraView.refreshConfiguration();
54
- shouldRefreshConfig = false;
55
- }
56
- }
57
-
58
- protected void orientationChanged() {
59
- shouldRefreshConfig = true;
60
- }
61
-
62
- protected void componentDidMount() {}
63
- protected void componentWillUnmount() {}
64
-
65
- /*-----------------------*
66
- * Events Handling
67
- *------------------------*/
68
- @Override
69
- public void receiveCommand(@NonNull ScanbotBarcodeCameraView root, String commandId, @Nullable ReadableArray args) {
70
- super.receiveCommand(root, commandId, args);
71
- eventReceiver.receiveCommand(commandId, args);
72
- }
73
-
74
- @Nullable
75
- @Override
76
- public Map<String, Object> getExportedCustomDirectEventTypeConstants() {
77
- final NativeEvent[] commonEvents = ScanbotEventEmitter.CommonEvents.values();
78
- final NativeEvent[] customEvents = ScanbotBarcodeCameraView.getNativeEvents();
79
- final NativeEvent[] allEvents = ScanbotEventEmitter.concatEvents(commonEvents, customEvents);
80
- return ScanbotEventEmitter.getMapForNativeEvents(allEvents);
81
- }
82
-
83
- @Override
84
- public void eventHandler_eventReceived(ScanbotEventReceiver.JavaScriptEvent event, @Nullable ReadableArray args) {
85
- CommonEvents commonEvent = eventReceiver.getCommonEventFromName(event.getName());
86
- if (commonEvent == null) {
87
- return;
88
- }
89
- this.handleCommonEvent(commonEvent, args);
90
- }
91
-
92
- private void handleCommonEvent(CommonEvents commonEvent, @Nullable ReadableArray args) {
93
- switch (commonEvent) {
94
- case COMPONENT_DID_UPDATE:
95
- componentDidUpdate();
96
- break;
97
- case COMPONENT_DID_MOUNT:
98
- componentDidMount();
99
- break;
100
- case COMPONENT_WILL_UNMOUNT:
101
- componentWillUnmount();
102
- break;
103
- case ORIENTATION_CHANGED:
104
- orientationChanged();
105
- break;
106
- }
107
- }
108
-
109
- @Nullable
110
- @Override
111
- public Map<String, Integer> getCommandsMap() {
112
- return eventReceiver.getCommandsMap();
113
- }
114
- }
package/index.d.ts DELETED
@@ -1,42 +0,0 @@
1
- import { BarcodeScannerConfiguration, BatchBarcodeScannerConfiguration, ScanbotBarcodeSdkConfiguration } from "./src/configurations";
2
- import { DetectBarcodesOnImageArguments, ExtractImagesFromPdfArguments } from "./src/customConfigurations";
3
- import { ResultWrapper } from "./src/customResults";
4
- import { BarcodeScannerResult, BatchBarcodeScannerResult, GetLicenseInfoResult } from "./src/results";
5
-
6
- export interface ScanbotBarcodeSdk {
7
- // SDK Internal
8
- initializeSdk(config: ScanbotBarcodeSdkConfiguration): Promise<ResultWrapper<string>>;
9
- getLicenseInfo(): Promise<ResultWrapper<GetLicenseInfoResult>>;
10
-
11
- cleanup(): Promise<ResultWrapper<string>>;
12
-
13
- // RTU-UI Barcode Scanning
14
- startBarcodeScanner(config: BarcodeScannerConfiguration): Promise<ResultWrapper<BarcodeScannerResult>>;
15
- closeBarcodeScanner(): Promise<ResultWrapper<undefined>>;
16
-
17
- startBatchBarcodeScanner(config: BatchBarcodeScannerConfiguration): Promise<ResultWrapper<BatchBarcodeScannerResult>>;
18
- closeBatchBarcodeScanner(): Promise<ResultWrapper<undefined>>;
19
-
20
- // Other Barcode Scanning functionalities
21
- detectBarcodesOnImage(
22
- args: DetectBarcodesOnImageArguments
23
- ): Promise<ResultWrapper<BarcodeScannerResult>>;
24
-
25
- extractImagesFromPDF(
26
- args: ExtractImagesFromPdfArguments
27
- ): Promise<ResultWrapper<string[]>>;
28
- }
29
-
30
- declare var ScanbotBarcodeSDK: ScanbotBarcodeSdk;
31
-
32
- export default ScanbotBarcodeSDK;
33
-
34
- export * from './src/components/barcode-camera-view/scanbot-barcode-camera-view';
35
- export * from './src/components/barcode-camera-view/scanbot-barcode-camera-view-types';
36
-
37
- export * from './src/types'
38
- export * from './src/customTypes'
39
- export * from './src/results'
40
- export * from './src/customResults'
41
- export * from './src/configurations'
42
- export * from './src/customConfigurations'
package/index.js DELETED
@@ -1,20 +0,0 @@
1
- /*
2
- Scanbot Barcode Scanner SDK React Native Plugin
3
- Copyright (c) 2024 Scanbot SDK GmbH. All rights reserved.
4
- https://scanbot.io/sdk
5
- */
6
- import { NativeModules } from 'react-native';
7
-
8
- const { ScanbotBarcodeSdk } = NativeModules;
9
-
10
- export default ScanbotBarcodeSdk;
11
-
12
- export * from './src/components/barcode-camera-view/scanbot-barcode-camera-view';
13
- export * from './src/components/barcode-camera-view/scanbot-barcode-camera-view-types';
14
-
15
- export * from './src/types'
16
- export * from './src/customTypes'
17
- export * from './src/results'
18
- export * from './src/customResults'
19
- export * from './src/configurations'
20
- export * from './src/customConfigurations'
@@ -1,44 +0,0 @@
1
- //
2
- // RTNScanbotBarcodeCameraView.h
3
- // RTNScanbotSDK
4
- //
5
- // Created by Marco Saia on 18.05.21.
6
- //
7
-
8
- // We use this compilation pragma to expose this implementation for the NEW ARCHITECTURE only
9
- #ifdef RCT_NEW_ARCH_ENABLED
10
-
11
- #ifndef RTNScanbotCameraView_h
12
- #define RTNScanbotCameraView_h
13
-
14
- #import <React/RCTViewComponentView.h>
15
- #import <React/RCTView.h>
16
- #import <UIKit/UIKit.h>
17
- #import <ScanbotBarcodeScannerSDK/ScanbotBarcodeScannerSDK.h>
18
- #import <react/renderer/components/RTNScanbotBarcodeCameraViewSpecs/Props.h>
19
-
20
- NS_ASSUME_NONNULL_BEGIN
21
-
22
- @interface RTNScanbotBarcodeCameraView: RCTViewComponentView<SBSDKBarcodeScannerViewControllerDelegate>
23
-
24
- @property SBSDKBarcodeScannerViewController* _Nullable cameraViewController;
25
-
26
- // TODO: Check if required
27
- @property (nonatomic, copy) RCTBubblingEventBlock _Nullable requestComponentReload;
28
-
29
- @property (nonatomic) facebook::react::RTNScanbotBarcodeCameraViewConfigurationStruct configuration;
30
-
31
- - (void) createCameraViewController;
32
- - (UIViewController* _Nullable) getParentViewController;
33
-
34
- - (void) componentDidMount;
35
- - (void) componentDidUpdate;
36
- - (void) componentWillUnmount;
37
- - (void) orientationChanged;
38
-
39
- @end
40
-
41
- NS_ASSUME_NONNULL_END
42
-
43
- #endif /* RTNScanbotCameraView_h */
44
- #endif // ifdef RCT_NEW_ARCH_ENABLED
@@ -1,338 +0,0 @@
1
- //
2
- // RTNScanbotBarcodeCameraView.mm
3
- // RNScanbotSDK
4
- //
5
- // Created by Marco Saia on 18.05.21.
6
- //
7
-
8
- // We use this compilation pragma to expose this implementation for the NEW ARCHITECTURE only
9
- #ifdef RCT_NEW_ARCH_ENABLED
10
-
11
- #import <react/renderer/components/RTNScanbotBarcodeCameraViewSpecs/ComponentDescriptors.h>
12
- #import <react/renderer/components/RTNScanbotBarcodeCameraViewSpecs/EventEmitters.h>
13
- #import <react/renderer/components/RTNScanbotBarcodeCameraViewSpecs/Props.h>
14
- #import <react/renderer/components/RTNScanbotBarcodeCameraViewSpecs/RCTComponentViewHelpers.h>
15
-
16
- #import "RTNScanbotBarcodeCameraView.h"
17
- #import "RCTFabricComponentsPlugins.h"
18
-
19
- #import <ScanbotBarcodeScannerSDK/ScanbotBarcodeScannerSDK.h>
20
- #import <ScanbotBarcodeSDKWrapper/ScanbotBarcodeSDKWrapper-Swift.h>
21
- #import <Foundation/Foundation.h>
22
-
23
- using namespace facebook::react;
24
-
25
- static inline NSString* toNSString(std::string value) {
26
- return [[NSString alloc] initWithCString:value.c_str() encoding:NSUTF8StringEncoding];
27
- }
28
-
29
- static inline bool isFloatDefined(facebook::react::Float value) {
30
- // If value is not set from the typescript, by default -1 is allocated from the props
31
- return !(isnan(value) || value == -1);
32
- }
33
-
34
- static inline bool isIntDefined(int value) {
35
- // If value is not set from the typescript, by default -1 is allocated from the props
36
- return !(isnan(value) || value == -1);
37
- }
38
-
39
- @interface RTNScanbotBarcodeCameraView () <RCTRTNScanbotBarcodeCameraViewViewProtocol>
40
- @property(nonatomic, strong) SBSDKBarcodeScannerViewController *viewController;
41
- @property(nonatomic) BOOL isFirstLaunch;
42
- @property(nonatomic) BOOL scanningEnabled;
43
- @end
44
-
45
- @implementation RTNScanbotBarcodeCameraView
46
-
47
- + (ComponentDescriptorProvider)componentDescriptorProvider
48
- {
49
- return concreteComponentDescriptorProvider<RTNScanbotBarcodeCameraViewComponentDescriptor>();
50
- }
51
-
52
- - (instancetype)initWithFrame:(CGRect)frame {
53
- self = [super initWithFrame:frame];
54
- if (self) {
55
- _isFirstLaunch = true;
56
- static const auto defaultProps = std::make_shared<const RTNScanbotBarcodeCameraViewProps>();
57
- _props = defaultProps;
58
-
59
- _scanningEnabled = true;
60
- }
61
- return self;
62
- }
63
-
64
- - (void)layoutSubviews {
65
- if (_cameraViewController) {
66
- _cameraViewController.view.frame = [self bounds];
67
- return;
68
- }
69
-
70
- __weak RTNScanbotBarcodeCameraView* weakSelf = self;
71
-
72
- dispatch_async(dispatch_get_main_queue(), ^{
73
- [weakSelf createCameraViewController];
74
- });
75
- }
76
-
77
- - (void)createCameraViewController {
78
- UIViewController* parentViewController = [self getParentViewController];
79
- if (!parentViewController) {
80
- return;
81
- }
82
-
83
- if (!_cameraViewController) {
84
- self.viewController = [[SBSDKBarcodeScannerViewController alloc] initWithParentViewController:parentViewController
85
- parentView:self
86
- delegate:self];
87
-
88
- self.cameraViewController = self.viewController;
89
- }
90
- }
91
-
92
- - (void)handleCommand:(const NSString *)commandName args:(const NSArray *)args {
93
- if ([commandName isEqualToString:@"componentDidMount"]) {
94
- [self componentDidMount];
95
- } else if ([commandName isEqualToString:@"componentDidUpdate"]) {
96
- [self componentDidUpdate];
97
- } else if ([commandName isEqualToString:@"componentWillUnmount"]) {
98
- [self componentWillUnmount];
99
- } else if ([commandName isEqualToString:@"orientationChanged"]) {
100
- [self orientationChanged];
101
- } else {
102
- NSLog(@"Unhandled React Native Command: %@", commandName);
103
- }
104
- }
105
-
106
- - (UIViewController* _Nullable)getParentViewController {
107
- UIResponder* parentResponder = self;
108
- while (parentResponder) {
109
- parentResponder = parentResponder.nextResponder;
110
- if (parentResponder && [parentResponder isKindOfClass:[UIViewController class]]) {
111
- return (UIViewController*) parentResponder;
112
- }
113
- }
114
- return NULL;
115
- }
116
-
117
- - (void)sendScanResults:(NSArray<SBSDKBarcodeScannerResult*>*) results {
118
- if (_eventEmitter == nullptr) {
119
- return;
120
- }
121
-
122
- if(!results || results.count == 0) {
123
- return;
124
- }
125
-
126
- NSDictionary* _Nullable result = [SBBWrapperBarcodeScannerResult nativeResultsToDictionary:results];
127
-
128
- if(result != NULL) {
129
- NSDictionary* outResult = @{
130
- @"result": result
131
- };
132
-
133
- NSData *data = [NSJSONSerialization dataWithJSONObject:outResult options:NSJSONWritingFragmentsAllowed error:nil];
134
- NSString *jsonResult = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
135
-
136
- const auto &eventEmitter = std::dynamic_pointer_cast<const facebook::react::RTNScanbotBarcodeCameraViewEventEmitter>(_eventEmitter);
137
-
138
- eventEmitter->onNativeBarcodeScannerResult(facebook::react::RTNScanbotBarcodeCameraViewEventEmitter::OnNativeBarcodeScannerResult{.jsonResult = std::string([jsonResult UTF8String])});
139
- }
140
- }
141
-
142
- // MARK: - React Native Lifecycle
143
- - (void)applyProps:(const facebook::react::Props::Shared &)props oldProps:(const facebook::react::Props::Shared &)oldProps forceUpdate:(bool)forceUpdate {
144
-
145
- const auto &oldViewProps = *std::static_pointer_cast<RTNScanbotBarcodeCameraViewProps const>(_props);
146
- const auto &newViewProps = *std::static_pointer_cast<RTNScanbotBarcodeCameraViewProps const>(props);
147
-
148
- NSDictionary *oldViewPropsAsDictionary = [[NSDictionary alloc] init];
149
- oldViewPropsAsDictionary = [self barcodeCameraViewConfigurationStructToDictionary:oldViewProps.configuration];
150
-
151
- SBBWrapperBarcodeCameraViewConfiguration* oldBarcodeCameraViewConfiguration = [SBBWrapperBarcodeCameraViewConfiguration fromDicitonary:oldViewPropsAsDictionary];
152
-
153
- NSDictionary *newViewPropsAsDictionary = [[NSDictionary alloc] init];
154
- newViewPropsAsDictionary = [self barcodeCameraViewConfigurationStructToDictionary:newViewProps.configuration];
155
-
156
- SBBWrapperBarcodeCameraViewConfiguration* newBarcodeCameraViewConfiguration = [SBBWrapperBarcodeCameraViewConfiguration fromDicitonary:newViewPropsAsDictionary];
157
-
158
- if(newBarcodeCameraViewConfiguration == NULL || oldBarcodeCameraViewConfiguration == NULL) {
159
- return;
160
- }
161
-
162
- // -----------------------------------------
163
- // START OF ViewFinderConfiguration MAPPING
164
- // -----------------------------------------
165
-
166
- // In order for the mapping to work we need to alloc, init and set a new SBSDKBaseScannerViewFinderConfiguration object
167
- // in the Scanbot SDK ViewController configuration. Applying hot changes on the existing object does not update
168
- // the component.
169
-
170
- SBSDKBaseScannerViewFinderConfiguration* viewFinderConfiguration = [SBSDKBaseScannerViewFinderConfiguration defaultConfiguration];
171
-
172
- viewFinderConfiguration.viewFinderEnabled = newBarcodeCameraViewConfiguration.shouldUseFinderView;
173
-
174
- if (isIntDefined(newBarcodeCameraViewConfiguration.finderLineWidth)) {
175
- viewFinderConfiguration.lineWidth = newBarcodeCameraViewConfiguration.finderLineWidth;
176
- }
177
-
178
- if(![newBarcodeCameraViewConfiguration.finderLineColor isEqual: @""]) {
179
- viewFinderConfiguration.lineColor = newBarcodeCameraViewConfiguration.finderLineColorAsUIColor;
180
- }
181
-
182
- if(![newBarcodeCameraViewConfiguration.finderBackgroundColor isEqual: @""] && isFloatDefined(newBarcodeCameraViewConfiguration.finderBackgroundOpacity)) {
183
- viewFinderConfiguration.backgroundColor = [newBarcodeCameraViewConfiguration.finderBackgroundColorAsUIColor colorWithAlphaComponent:newBarcodeCameraViewConfiguration.finderBackgroundOpacity];
184
- }
185
-
186
- if (isIntDefined(newBarcodeCameraViewConfiguration.finderAspectRatio.width) && isIntDefined(newBarcodeCameraViewConfiguration.finderAspectRatio.height)) {
187
- viewFinderConfiguration.aspectRatio = [[SBSDKAspectRatio alloc] initWithWidth:newBarcodeCameraViewConfiguration.finderAspectRatio.width andHeight:newBarcodeCameraViewConfiguration.finderAspectRatio.height];
188
- }
189
-
190
- if (newBarcodeCameraViewConfiguration.finderInset.insetsAreSet) {
191
- viewFinderConfiguration.minimumInset = newBarcodeCameraViewConfiguration.finderInset.insets;
192
- }
193
-
194
- self.viewController.viewFinderConfiguration = viewFinderConfiguration;
195
- // ---------------------------------------
196
- // END OF ViewFinderConfiguration MAPPING
197
- // ---------------------------------------
198
-
199
- if (isIntDefined(newBarcodeCameraViewConfiguration.minimumTextLength) && (forceUpdate || oldBarcodeCameraViewConfiguration.minimumTextLength != newBarcodeCameraViewConfiguration.minimumTextLength)) {
200
- self.viewController.additionalDetectionParameters.minimumTextLength = newBarcodeCameraViewConfiguration.minimumTextLength;
201
- }
202
-
203
- if (isIntDefined(newBarcodeCameraViewConfiguration.maximumTextLength) && (forceUpdate || oldBarcodeCameraViewConfiguration.maximumTextLength != newBarcodeCameraViewConfiguration.maximumTextLength)) {
204
- self.viewController.additionalDetectionParameters.maximumTextLength = newBarcodeCameraViewConfiguration.maximumTextLength;
205
- }
206
-
207
- if (isIntDefined(newBarcodeCameraViewConfiguration.minimum1DBarcodesQuietZone) && (forceUpdate || oldBarcodeCameraViewConfiguration.minimum1DBarcodesQuietZone != newBarcodeCameraViewConfiguration.minimum1DBarcodesQuietZone)) {
208
- self.viewController.additionalDetectionParameters.minimum1DBarcodesQuietZone = newBarcodeCameraViewConfiguration.minimum1DBarcodesQuietZone;
209
- }
210
-
211
- if (forceUpdate || oldBarcodeCameraViewConfiguration.stripCheckDigits != newBarcodeCameraViewConfiguration.stripCheckDigits) {
212
- self.viewController.additionalDetectionParameters.stripCheckDigits = newBarcodeCameraViewConfiguration.stripCheckDigits;
213
- }
214
-
215
- if (forceUpdate || oldBarcodeCameraViewConfiguration.gs1Handling != newBarcodeCameraViewConfiguration.gs1Handling) {
216
- self.viewController.additionalDetectionParameters.gs1Handling = newBarcodeCameraViewConfiguration.gs1Handling;
217
- }
218
-
219
- if (forceUpdate || oldBarcodeCameraViewConfiguration.msiPlesseyChecksumAlgorithm != newBarcodeCameraViewConfiguration.msiPlesseyChecksumAlgorithm) {
220
- self.viewController.additionalDetectionParameters.msiPlesseyChecksumAlgorithm = newBarcodeCameraViewConfiguration.msiPlesseyChecksumAlgorithm;
221
- }
222
-
223
- if (forceUpdate || oldBarcodeCameraViewConfiguration.codeDensity != newBarcodeCameraViewConfiguration.codeDensity) {
224
- self.viewController.additionalDetectionParameters.codeDensity = newBarcodeCameraViewConfiguration.codeDensity;
225
- }
226
-
227
- if (forceUpdate || oldBarcodeCameraViewConfiguration.flashEnabled != newBarcodeCameraViewConfiguration.flashEnabled) {
228
- self.viewController.flashLightEnabled = newBarcodeCameraViewConfiguration.flashEnabled;
229
- }
230
-
231
- if (forceUpdate || oldBarcodeCameraViewConfiguration.acceptedBarcodeTypes != newBarcodeCameraViewConfiguration.acceptedBarcodeTypes) {
232
- self.viewController.acceptedBarcodeTypes = newBarcodeCameraViewConfiguration.acceptedBarcodeTypes;
233
- }
234
-
235
- if (forceUpdate || oldBarcodeCameraViewConfiguration.acceptedDocumentTypes != newBarcodeCameraViewConfiguration.acceptedDocumentTypes) {
236
- self.viewController.acceptedDocumentTypes = newBarcodeCameraViewConfiguration.acceptedDocumentTypes;
237
- }
238
-
239
- if (forceUpdate || oldBarcodeCameraViewConfiguration.engineMode != newBarcodeCameraViewConfiguration.engineMode) {
240
- self.viewController.engineMode = newBarcodeCameraViewConfiguration.engineMode;
241
- }
242
-
243
- if (isFloatDefined(newBarcodeCameraViewConfiguration.cameraZoomFactor) && (forceUpdate || oldBarcodeCameraViewConfiguration.cameraZoomFactor != newBarcodeCameraViewConfiguration.cameraZoomFactor)) {
244
- self.viewController.cameraZoomFactor = newBarcodeCameraViewConfiguration.cameraZoomFactor;
245
- }
246
-
247
- if (forceUpdate || oldBarcodeCameraViewConfiguration.barcodesExtensionFilter != newBarcodeCameraViewConfiguration.barcodesExtensionFilter) {
248
- self.viewController.extensionFilter = newBarcodeCameraViewConfiguration.barcodesExtensionFilter;
249
- }
250
-
251
- _scanningEnabled = newBarcodeCameraViewConfiguration.scanningEnabled;
252
- }
253
-
254
- - (void)updateProps:(const facebook::react::Props::Shared &)props oldProps:(const facebook::react::Props::Shared &)oldProps {
255
- const auto &newViewProps = *std::static_pointer_cast<RTNScanbotBarcodeCameraViewProps const>(props);
256
-
257
- self.configuration = newViewProps.configuration;
258
-
259
- [self applyProps:props oldProps:oldProps forceUpdate:_isFirstLaunch];
260
- _isFirstLaunch = false;
261
-
262
- [super updateProps:props oldProps:oldProps];
263
- }
264
-
265
- - barcodeCameraViewConfigurationStructToDictionary:(facebook::react::RTNScanbotBarcodeCameraViewConfigurationStruct) configurationStruct
266
- {
267
- return @{
268
- @"flashEnabled": @(configurationStruct.flashEnabled),
269
- @"barcodeFormats": [self vectorStringToNSArray:configurationStruct.barcodeFormats],
270
- @"acceptedDocumentFormats": [self vectorStringToNSArray:configurationStruct.acceptedDocumentFormats],
271
- @"engineMode": toNSString(configurationStruct.engineMode),
272
- @"cameraZoomFactor": @(configurationStruct.cameraZoomFactor),
273
- @"barcodesExtensionFilter": toNSString(configurationStruct.barcodesExtensionFilter),
274
- @"scanningEnabled": @(configurationStruct.scanningEnabled),
275
- @"minimumTextLength": @(configurationStruct.minimumTextLength),
276
- @"maximumTextLength": @(configurationStruct.maximumTextLength),
277
- @"minimum1DBarcodesQuietZone": @(configurationStruct.minimum1DBarcodesQuietZone),
278
- @"stripCheckDigits": @(configurationStruct.stripCheckDigits),
279
- @"gs1HandlingMode": toNSString(configurationStruct.gs1HandlingMode),
280
- @"msiPlesseyChecksumAlgorithm": toNSString(configurationStruct.msiPlesseyChecksumAlgorithm),
281
- @"codeDensity": toNSString(configurationStruct.codeDensity),
282
- @"shouldUseFinderView": @(configurationStruct.shouldUseFinderView),
283
- @"finderLineWidth": @(configurationStruct.finderLineWidth),
284
- @"finderLineColor": toNSString(configurationStruct.finderLineColor),
285
- @"finderBackgroundColor": toNSString(configurationStruct.finderBackgroundColor),
286
- @"finderBackgroundOpacity": @(configurationStruct.finderBackgroundOpacity),
287
- @"finderAspectRatio": @{@"width": @(configurationStruct.finderAspectRatio.width), @"height": @(configurationStruct.finderAspectRatio.height)},
288
- @"finderInset": @{@"left": @(configurationStruct.finderInset.left), @"top": @(configurationStruct.finderInset.top), @"bottom": @(configurationStruct.finderInset.bottom), @"right": @(configurationStruct.finderInset.right)}
289
- };
290
- }
291
-
292
- - (NSArray*)vectorStringToNSArray:(std::vector<std::string>) vector {
293
- NSMutableArray* nsArray = [NSMutableArray array];
294
-
295
- for (auto const& value : vector) {
296
- [nsArray addObject: toNSString(value)];
297
- }
298
-
299
- return nsArray;
300
- }
301
-
302
- - (void)componentDidMount {
303
- _isFirstLaunch = true;
304
- [self applyProps:_props oldProps:_props forceUpdate:_isFirstLaunch];
305
- }
306
- - (void)componentDidUpdate {}
307
- - (void)componentWillUnmount {
308
- [self.cameraViewController removeFromParentViewController];
309
- self.cameraViewController = NULL;
310
- }
311
- - (void)orientationChanged {}
312
-
313
- // MARK: - SBSDKBarcodeScannerViewControllerDelegate
314
-
315
- - (void)barcodeScannerController:(SBSDKBarcodeScannerViewController *)controller
316
- didDetectBarcodes:(NSArray<SBSDKBarcodeScannerResult *> *)codes
317
- onImage:(nonnull UIImage *)image {
318
-
319
- [self sendScanResults:codes];
320
- }
321
-
322
- - (BOOL)barcodeScannerControllerShouldDetectBarcodes:(SBSDKBarcodeScannerViewController *)controller {
323
- return _scanningEnabled;
324
- }
325
-
326
- - (void)barcodeScannerController:(nonnull SBSDKBarcodeScannerViewController *)controller didDetectBarcodes:(nonnull NSArray<SBSDKBarcodeScannerResult *> *)codes {
327
- [self sendScanResults:codes];
328
- }
329
-
330
- @end
331
-
332
- Class<RCTComponentViewProtocol> RTNScanbotBarcodeCameraViewCls(void)
333
- {
334
- return RTNScanbotBarcodeCameraView.class;
335
- }
336
-
337
- #endif // ifdef RCT_NEW_ARCH_ENABLED
338
-