react-native-scanbot-barcode-scanner-sdk 3.3.1-beta1 → 3.3.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 (27) hide show
  1. package/LICENSE +1 -1
  2. package/Libraries.txt +2 -2
  3. package/android/.gradle/6.2/executionHistory/executionHistory.lock +0 -0
  4. package/android/build.gradle +1 -1
  5. package/android/src/main/java/com/reactlibrary/ScanbotBarcodeSdkModule.java +0 -6
  6. package/android/src/main/java/com/reactlibrary/ScanbotBarcodeSdkPackage.java +7 -10
  7. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/ScanbotBarcodeSdkPackage.java +6 -10
  8. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/barcodecameraview/ScanbotBarcodeCameraView.java +380 -0
  9. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/barcodecameraview/{RNScanbotBarcodeCameraConfiguration.java → ScanbotBarcodeCameraViewConfiguration.java} +18 -21
  10. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/barcodecameraview/ScanbotBarcodeCameraViewManager.java +114 -0
  11. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/base/communication/{RNScanbotEventEmitter.java → ScanbotEventEmitter.java} +7 -7
  12. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/base/communication/{RNScanbotEventReceiver.java → ScanbotEventReceiver.java} +7 -7
  13. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/base/models/ScanbotFinderInset.java +8 -0
  14. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/base/ui/ScanbotViewWrapper.java +26 -0
  15. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/utils/ScanbotViewUtils.java +52 -0
  16. package/ios/Components/BarcodeCameraView/RNScanbotBarcodeCameraView.m +1 -1
  17. package/package.json +1 -1
  18. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/barcodecameraview/RNScanbotBarcodeCameraComponent.java +0 -283
  19. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/barcodecameraview/RNScanbotBarcodeCameraUi.java +0 -81
  20. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/base/RNScanbotNativeComponent.java +0 -90
  21. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/base/RNScanbotNativeComponentManager.java +0 -133
  22. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/base/RNScanbotNativeComponentManagerFactory.java +0 -40
  23. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/base/RNScanbotNativeComponentUi.java +0 -131
  24. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/base/views/RNScanbotNativeComponentFrameLayout.java +0 -53
  25. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/base/views/RNScanbotNativeComponentRootView.java +0 -154
  26. package/android/src/main/res/layout/component_barcode_camera_view.xml +0 -28
  27. package/android/src/main/res/layout/fragment_barcode_scanner.xml +0 -23
@@ -0,0 +1,114 @@
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 = "ScanbotBarcodeCameraView";
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
+ }
@@ -9,13 +9,13 @@ import com.facebook.react.uimanager.events.RCTEventEmitter;
9
9
 
10
10
  import java.util.Map;
11
11
 
12
- public class RNScanbotEventEmitter {
12
+ public class ScanbotEventEmitter {
13
13
 
14
14
  public interface NativeEvent {
15
15
  String getName();
16
16
  }
17
17
 
18
- public enum CommonEvents implements RNScanbotEventEmitter.NativeEvent {
18
+ public enum CommonEvents implements NativeEvent {
19
19
  REQUEST_COMPONENT_RELOAD("requestComponentReload");
20
20
 
21
21
  private final String name;
@@ -32,7 +32,7 @@ public class RNScanbotEventEmitter {
32
32
  private final ReactContext reactContext;
33
33
  private final ViewGroup rootViewGroup;
34
34
 
35
- public RNScanbotEventEmitter(final ReactContext reactContext, final ViewGroup rootViewGroup) {
35
+ public ScanbotEventEmitter(final ReactContext reactContext, final ViewGroup rootViewGroup) {
36
36
  this.reactContext = reactContext;
37
37
  this.jsEventEmitter = reactContext.getJSModule(RCTEventEmitter.class);
38
38
  this.rootViewGroup = rootViewGroup;
@@ -56,15 +56,15 @@ public class RNScanbotEventEmitter {
56
56
  return builder.build();
57
57
  }
58
58
 
59
- public static RNScanbotEventEmitter.NativeEvent[] concatEvents(
60
- RNScanbotEventEmitter.NativeEvent[] arr1,
61
- RNScanbotEventEmitter.NativeEvent[] arr2
59
+ public static NativeEvent[] concatEvents(
60
+ NativeEvent[] arr1,
61
+ NativeEvent[] arr2
62
62
  ) {
63
63
  final int len1 = arr1.length;
64
64
  final int len2 = arr2.length;
65
65
  final int min = Math.min(len1, len2);
66
66
  final int max = Math.max(len1, len2);
67
- final RNScanbotEventEmitter.NativeEvent[] out = new RNScanbotEventEmitter.NativeEvent[len1 + len2];
67
+ final NativeEvent[] out = new NativeEvent[len1 + len2];
68
68
 
69
69
  for (int i = 0; i<max; ++i) {
70
70
  out[i] = len2 > len1 ? arr2[i] : arr1[i];
@@ -8,13 +8,13 @@ import com.facebook.react.bridge.ReadableArray;
8
8
  import java.util.HashMap;
9
9
  import java.util.Map;
10
10
 
11
- public class RNScanbotEventReceiver {
11
+ public class ScanbotEventReceiver {
12
12
 
13
13
  public interface JavaScriptEvent {
14
14
  String getName();
15
15
  }
16
16
 
17
- public enum CommonEvents implements RNScanbotEventReceiver.JavaScriptEvent {
17
+ public enum CommonEvents implements JavaScriptEvent {
18
18
  COMPONENT_DID_UPDATE("componentDidUpdate"),
19
19
  COMPONENT_DID_MOUNT("componentDidMount"),
20
20
  COMPONENT_WILL_UNMOUNT("componentWillUnmount"),
@@ -38,7 +38,7 @@ public class RNScanbotEventReceiver {
38
38
  private final JavaScriptEvent[] events;
39
39
  private final HashMap<Integer, String> eventsMap = new HashMap<>();
40
40
 
41
- public RNScanbotEventReceiver(@NonNull final IEventHandler handler, @NonNull final JavaScriptEvent[] events) {
41
+ public ScanbotEventReceiver(@NonNull final IEventHandler handler, @NonNull final JavaScriptEvent[] events) {
42
42
  this.handler = handler;
43
43
  this.events = concatEvents(CommonEvents.values(), events);
44
44
  prepare();
@@ -88,15 +88,15 @@ public class RNScanbotEventReceiver {
88
88
  return (CommonEvents) event;
89
89
  }
90
90
 
91
- public static RNScanbotEventReceiver.JavaScriptEvent[] concatEvents(
92
- RNScanbotEventReceiver.JavaScriptEvent[] arr1,
93
- RNScanbotEventReceiver.JavaScriptEvent[] arr2
91
+ public static JavaScriptEvent[] concatEvents(
92
+ JavaScriptEvent[] arr1,
93
+ JavaScriptEvent[] arr2
94
94
  ) {
95
95
  final int len1 = arr1.length;
96
96
  final int len2 = arr2.length;
97
97
  final int min = Math.min(len1, len2);
98
98
  final int max = Math.max(len1, len2);
99
- final RNScanbotEventReceiver.JavaScriptEvent[] out = new RNScanbotEventReceiver.JavaScriptEvent[len1 + len2];
99
+ final JavaScriptEvent[] out = new JavaScriptEvent[len1 + len2];
100
100
 
101
101
  for (int i = 0; i<max; ++i) {
102
102
  out[i] = len2 > len1 ? arr2[i] : arr1[i];
@@ -0,0 +1,8 @@
1
+ package io.scanbot.barcodesdk.plugin.reactnative.components.base.models;
2
+
3
+ public class ScanbotFinderInset {
4
+ public int left = 0;
5
+ public int top = 0;
6
+ public int right = 0;
7
+ public int bottom = 0;
8
+ }
@@ -0,0 +1,26 @@
1
+ package io.scanbot.barcodesdk.plugin.reactnative.components.base.ui;
2
+
3
+ import android.content.Context;
4
+ import android.view.View;
5
+ import android.view.ViewGroup;
6
+
7
+ import com.facebook.react.views.view.ReactViewGroup;
8
+
9
+ import io.scanbot.barcodesdk.plugin.reactnative.utils.ScanbotViewUtils;
10
+
11
+ public class ScanbotViewWrapper extends ReactViewGroup {
12
+ public ScanbotViewWrapper(Context context) {
13
+ super(context);
14
+ }
15
+
16
+ public static ScanbotViewWrapper wrap(final View view) {
17
+ final ScanbotViewWrapper wrapper = new ScanbotViewWrapper(view.getContext());
18
+ if (view instanceof ViewGroup) {
19
+ ScanbotViewUtils.installHierarchyFitter((ViewGroup) view);
20
+ }
21
+ wrapper.addView(view);
22
+ wrapper.requestLayout();
23
+ view.requestLayout();
24
+ return wrapper;
25
+ }
26
+ }
@@ -0,0 +1,52 @@
1
+ package io.scanbot.barcodesdk.plugin.reactnative.utils;
2
+
3
+ import android.graphics.Color;
4
+ import android.util.Log;
5
+ import android.view.Choreographer;
6
+ import android.view.View;
7
+ import android.view.ViewGroup;
8
+
9
+ import androidx.annotation.ColorInt;
10
+
11
+ public class ScanbotViewUtils {
12
+ public static void installHierarchyFitter(final ViewGroup viewGroup) {
13
+ viewGroup.setOnHierarchyChangeListener(new ViewGroup.OnHierarchyChangeListener() {
14
+ @Override
15
+ public void onChildViewAdded(View parent, View child) {
16
+ if (parent == null) { return; }
17
+ parent.measure(
18
+ View.MeasureSpec.makeMeasureSpec(viewGroup.getMeasuredWidth(), View.MeasureSpec.EXACTLY),
19
+ View.MeasureSpec.makeMeasureSpec(viewGroup.getMeasuredHeight(), View.MeasureSpec.EXACTLY)
20
+ );
21
+ parent.layout(0, 0, parent.getMeasuredWidth(), parent.getMeasuredHeight());
22
+ }
23
+
24
+ @Override
25
+ public void onChildViewRemoved(View parent, View child) {}
26
+ });
27
+ }
28
+
29
+ public static void remeasureChildren(final ViewGroup view) {
30
+ Choreographer.getInstance().postFrameCallback(frameTimeNanos -> {
31
+ for (int i = 0; i < view.getChildCount(); i++) {
32
+ View child = view.getChildAt(i);
33
+ if (child instanceof ViewGroup) {
34
+ child.measure(View.MeasureSpec.makeMeasureSpec(view.getMeasuredWidth(), View.MeasureSpec.EXACTLY),
35
+ View.MeasureSpec.makeMeasureSpec(view.getMeasuredHeight(), View.MeasureSpec.EXACTLY));
36
+ child.layout(0, 0, child.getMeasuredWidth(), child.getMeasuredHeight());
37
+ }
38
+ }
39
+ view.getViewTreeObserver().dispatchOnGlobalLayout();
40
+ });
41
+ }
42
+
43
+ @ColorInt
44
+ public static int colorWithAlpha(@ColorInt int color, float factor) {
45
+ int alpha = Math.round(Color.alpha(color) * factor);
46
+ int red = Color.red(color);
47
+ int green = Color.green(color);
48
+ int blue = Color.blue(color);
49
+ return Color.argb(alpha, red, green, blue);
50
+ }
51
+
52
+ }
@@ -86,7 +86,7 @@
86
86
  cameraViewConfiguration.codeDensity = extractBarcodeDensity(config);
87
87
  cameraViewConfiguration.finderInset = [self populateFinderInset:config];
88
88
 
89
- self.shouldUseFinderView = [config objectForKey:@"shouldUseFinderView"];
89
+ self.shouldUseFinderView = [[config objectForKey:@"shouldUseFinderView"] boolValue];
90
90
 
91
91
  } @catch (NSException *exception) {
92
92
  NSLog(@"%@", [exception reason]);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "react-native-scanbot-barcode-scanner-sdk",
3
3
  "title": "Scanbot Barcode Scanner SDK for React Native",
4
- "version": "3.3.1-beta1",
4
+ "version": "3.3.1",
5
5
  "description": "Scanbot Barcode Scanner SDK React Native Plugin for Android and iOS",
6
6
  "main": "index.js",
7
7
  "files": [
@@ -1,283 +0,0 @@
1
- package io.scanbot.barcodesdk.plugin.reactnative.components.barcodecameraview;;
2
-
3
- import android.Manifest;
4
- import android.app.Activity;
5
- import android.content.pm.PackageManager;
6
- import android.graphics.Color;
7
- import android.view.View;
8
-
9
- import androidx.annotation.ColorInt;
10
- import androidx.annotation.NonNull;
11
- import androidx.annotation.Nullable;
12
- import androidx.core.app.ActivityCompat;
13
- import androidx.core.content.ContextCompat;
14
-
15
- import com.facebook.react.bridge.ReactContext;
16
- import com.facebook.react.bridge.ReadableArray;
17
- import com.facebook.react.bridge.ReadableMap;
18
- import com.facebook.react.bridge.WritableArray;
19
- import com.facebook.react.bridge.WritableMap;
20
- import com.facebook.react.bridge.WritableNativeArray;
21
-
22
- import org.jetbrains.annotations.NotNull;
23
-
24
- import java.util.Collections;
25
- import java.util.List;
26
-
27
- import io.scanbot.sdk.SdkLicenseError;
28
- import io.scanbot.sdk.barcode.BarcodeDetectorFrameHandler;
29
- import io.scanbot.sdk.barcode.DefaultScanbotBarcodeDetector;
30
- import io.scanbot.sdk.barcode.ScanbotBarcodeDetector;
31
- import io.scanbot.sdk.barcode.entity.BarcodeItem;
32
- import io.scanbot.sdk.barcode.entity.BarcodeScannerAdditionalConfig;
33
- import io.scanbot.sdk.barcode.entity.BarcodeScanningResult;
34
- import io.scanbot.sdk.camera.FrameHandlerResult;
35
- import io.scanbot.barcodesdk.plugin.reactnative.utils.JSONUtils;
36
- import io.scanbot.barcodesdk.plugin.reactnative.components.base.communication.RNScanbotEventEmitter;
37
- import io.scanbot.barcodesdk.plugin.reactnative.components.base.communication.RNScanbotEventReceiver;
38
- import io.scanbot.barcodesdk.plugin.reactnative.components.base.RNScanbotNativeComponent;
39
- import io.scanbot.barcodesdk.plugin.reactnative.components.base.RNScanbotNativeComponentUi;
40
- import io.scanbot.barcodesdk.plugin.reactnative.components.base.views.RNScanbotNativeComponentRootView;
41
- import io.scanbot.sdk.ui.camera.FinderOverlayView;
42
- import io.scanbot.sdk.ui.camera.ScanbotCameraXView;
43
- import kotlin.Unit;
44
-
45
- /*
46
- * The core logic of the ScanbotBarcodeCameraView Component
47
- */
48
- public class RNScanbotBarcodeCameraComponent extends RNScanbotNativeComponent implements BarcodeDetectorFrameHandler.ResultHandler {
49
-
50
- private static final int REQUEST_PERMISSION_CODE = 200;
51
-
52
- // From Java to JavaScript
53
- public enum NativeEvents implements RNScanbotEventEmitter.NativeEvent {
54
- BARCODE_SCANNER_RESULT("onBarcodeScannerResult");
55
-
56
- private final String name;
57
- NativeEvents(final String name) {
58
- this.name = name;
59
- }
60
-
61
- public String getName() {
62
- return name;
63
- }
64
- }
65
-
66
- // UI
67
- private RNScanbotBarcodeCameraUi barcodeCameraUi;
68
- private ScanbotBarcodeDetector barcodeDetector;
69
- private BarcodeDetectorFrameHandler frameHandler;
70
-
71
- // Communication
72
- private RNScanbotEventEmitter eventEmitter;
73
-
74
- // Configuration
75
- private RNScanbotBarcodeCameraConfiguration configuration = new RNScanbotBarcodeCameraConfiguration();
76
- private float userDefinedCameraZoomFactor = -1;
77
-
78
- // Dependencies
79
- private final ReactContext reactContext;
80
-
81
- // State handling
82
- private boolean isInitialized = false;
83
-
84
- public RNScanbotBarcodeCameraComponent(@NonNull final ReactContext reactContext) {
85
- super(reactContext);
86
- this.reactContext = reactContext;
87
- this.barcodeCameraUi = new RNScanbotBarcodeCameraUi(reactContext);
88
- }
89
-
90
- // ---------------------
91
- // Component Lifecycle
92
- // ---------------------
93
- @Override
94
- public void onComponentWillUnmount() {
95
- super.onComponentWillUnmount();
96
- final ScanbotCameraXView cameraView = this.barcodeCameraUi.getCameraView();
97
- cameraView.stopPreview();
98
- }
99
-
100
- @Override
101
- public void onOrientationChanged() {
102
- super.onOrientationChanged();
103
- }
104
- // ---------------------
105
-
106
- @Override
107
- public void initializeComponent() {
108
- final ScanbotCameraXView cameraView = this.barcodeCameraUi.getCameraView();
109
- cameraView.startPreview();
110
-
111
- this.barcodeDetector = new DefaultScanbotBarcodeDetector();
112
-
113
- this.frameHandler = BarcodeDetectorFrameHandler.attach(cameraView, barcodeDetector);
114
- this.frameHandler.setDetectionInterval(0);
115
- this.frameHandler.addResultHandler(this);
116
-
117
- cameraView.addFrameHandler(frameHandler);
118
- cameraView.setCameraOpenCallback(cameraView::continuousFocus);
119
-
120
- cameraView.post(this::checkPermissions);
121
-
122
- this.eventEmitter = new RNScanbotEventEmitter(this.reactContext, this.barcodeCameraUi.getRootView());
123
-
124
- applyConfiguration();
125
-
126
- reactContext.runOnUiQueueThread(() -> isInitialized = true);
127
- }
128
-
129
- private void applyConfiguration() {
130
- reactContext.runOnUiQueueThread(() -> {
131
- final FinderOverlayView finderOverlayView = barcodeCameraUi.getFinderOverlayView();
132
- final ScanbotCameraXView cameraView = barcodeCameraUi.getCameraView();
133
-
134
- finderOverlayView.setVisibility(configuration.shouldUseFinderView() ? View.VISIBLE : View.INVISIBLE);
135
- finderOverlayView.setStrokeWidth(configuration.getFinderLineWidth());
136
- finderOverlayView.setStrokeColor(configuration.getFinderLineColor());
137
- finderOverlayView.setOverlayColor(colorWithAlpha(
138
- configuration.getFinderBackgroundColor(),
139
- configuration.getFinderBackgroundOpacity()));
140
- if (configuration.finderInset != null) {
141
- finderOverlayView.setFinderInset(configuration.finderInset.left,
142
- configuration.finderInset.top,
143
- configuration.finderInset.right,
144
- configuration.finderInset.bottom);
145
- }
146
-
147
- finderOverlayView.setRequiredAspectRatios(Collections.singletonList(configuration.getFinderAspectRatio()));
148
- finderOverlayView.requestLayout();
149
-
150
- cameraView.useFlash(configuration.isFlashEnabled());
151
-
152
- if (configuration.getCameraZoomFactor() != -1) {
153
- if (configuration.getCameraZoomFactor() != userDefinedCameraZoomFactor || userDefinedCameraZoomFactor == -1) {
154
- cameraView.setOpticalZoomLevel(configuration.getCameraZoomFactor());
155
- userDefinedCameraZoomFactor = configuration.getCameraZoomFactor();
156
- }
157
- }
158
- barcodeDetector.modifyConfig(b -> {
159
- if(!configuration.barcodeFormats.isEmpty()) {
160
- b.setBarcodeFormats(configuration.barcodeFormats);
161
- }
162
- if(!configuration.acceptedDocumentFormats.isEmpty()) {
163
- b.setAcceptedDocumentFormats(configuration.acceptedDocumentFormats);
164
- }
165
- b.setEngineMode(configuration.engineMode);
166
- if (configuration.additionalConfiguration != null) {
167
- b.modifyAdditionalConfig(ab -> {
168
- final BarcodeScannerAdditionalConfig config = configuration.additionalConfiguration;
169
- ab.setMinimumTextLength(config.getMinimumTextLength());
170
- ab.setMaximumTextLength(config.getMaximumTextLength());
171
- ab.setMsiPlesseyChecksumAlgorithms(config.getMsiPlesseyChecksumAlgorithms());
172
- ab.setStripCheckDigits(config.getStripCheckDigits());
173
- ab.setGs1DecodingEnabled(config.getGs1DecodingEnabled());
174
- ab.setMinimum1DQuietZoneSize(config.getMinimum1DQuietZoneSize());
175
- ab.setLowPowerMode(config.getLowPowerMode());
176
- return Unit.INSTANCE;
177
- });
178
- }
179
-
180
- return Unit.INSTANCE;
181
- });
182
- });
183
-
184
- }
185
-
186
- // Barcode Detector Frame Handler - Result Handler
187
- @Override
188
- @SuppressWarnings("unchecked")
189
- public boolean handle(@NotNull FrameHandlerResult<? extends BarcodeScanningResult, ? extends SdkLicenseError> frameHandlerResult) {
190
- if (frameHandlerResult instanceof FrameHandlerResult.Success) {
191
- handleSuccess((FrameHandlerResult.Success<BarcodeScanningResult>) frameHandlerResult);
192
- }
193
- return false;
194
- }
195
-
196
- private void handleSuccess(final FrameHandlerResult.Success<BarcodeScanningResult> result) {
197
- if (result == null || result.getValue() == null) {
198
- return;
199
- }
200
-
201
- List<BarcodeItem> barcodeItems;
202
- if (configuration.barcodeFilter != null) {
203
- barcodeItems = JSONUtils.getBarcodeItemsFromItemListWithFilter(result.getValue().getBarcodeItems(), configuration.barcodeFilter);
204
- } else {
205
- barcodeItems = result.getValue().getBarcodeItems();
206
- }
207
-
208
- sendResult(barcodeItems);
209
- }
210
-
211
- private void sendResult(final List<BarcodeItem> barcodeItems) {
212
- if (barcodeItems == null || barcodeItems.size() == 0) {
213
- return;
214
- }
215
-
216
- final ReadableMap result = JSONUtils.jsonResultFromBarcodeItems(barcodeItems);
217
- final WritableMap data = new JSONUtils.WritableMapBuilder()
218
- .putMap("result", result)
219
- .build();
220
-
221
- eventEmitter.emitEvent(NativeEvents.BARCODE_SCANNER_RESULT, data);
222
- }
223
-
224
- @Override
225
- public RNScanbotNativeComponentUi createNativeComponentUi(@NonNull ReactContext reactContext) {
226
- this.barcodeCameraUi = new RNScanbotBarcodeCameraUi(reactContext);
227
- return this.barcodeCameraUi;
228
- }
229
-
230
- /*
231
- * Creates the root view for the component
232
- */
233
- @Override
234
- public RNScanbotNativeComponentRootView getRootView() { return this.barcodeCameraUi.getRootView(); }
235
-
236
- /*
237
- * Returns the list of native events
238
- */
239
- @Override
240
- public RNScanbotEventEmitter.NativeEvent[] getNativeEvents() { return NativeEvents.values(); }
241
-
242
- @Override
243
- public RNScanbotEventReceiver.JavaScriptEvent[] getJavascriptEvents() {
244
- return new RNScanbotEventReceiver.JavaScriptEvent[] {};
245
- }
246
-
247
- /*
248
- * Applies the given configuration to the component (JSON Configuration)
249
- */
250
- @Override
251
- public void applyConfiguration(@NonNull final ReadableMap configuration) {
252
- applyConfiguration(RNScanbotBarcodeCameraConfiguration.fromJsonMap(configuration));
253
- }
254
-
255
- /*
256
- * Applies the given configuration to the component (Native Configuration)
257
- */
258
- public void applyConfiguration(@NonNull final RNScanbotBarcodeCameraConfiguration configuration) {
259
- this.configuration = configuration;
260
- if (isInitialized) {
261
- applyConfiguration();
262
- }
263
- }
264
-
265
- private void checkPermissions() {
266
- if (this.reactContext == null) { return; }
267
- Activity activity = reactContext.getCurrentActivity();
268
-
269
- if (activity != null && ContextCompat.checkSelfPermission(activity, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
270
- ActivityCompat.requestPermissions(activity, new String[] { Manifest.permission.CAMERA }, REQUEST_PERMISSION_CODE);
271
- }
272
- }
273
-
274
- @ColorInt
275
- public static int colorWithAlpha(@ColorInt int color, float factor) {
276
- int alpha = Math.round(Color.alpha(color) * factor);
277
- int red = Color.red(color);
278
- int green = Color.green(color);
279
- int blue = Color.blue(color);
280
- return Color.argb(alpha, red, green, blue);
281
- }
282
-
283
- }
@@ -1,81 +0,0 @@
1
- package io.scanbot.barcodesdk.plugin.reactnative.components.barcodecameraview;
2
-
3
- import android.app.Activity;
4
- import android.util.Size;
5
- import android.view.LayoutInflater;
6
- import android.widget.FrameLayout;
7
-
8
- import androidx.annotation.NonNull;
9
-
10
- import com.facebook.react.bridge.ReactContext;
11
-
12
- import io.scanbot.barcodesdk.plugin.reactnative.R;
13
- import io.scanbot.barcodesdk.plugin.reactnative.components.base.RNScanbotNativeComponentUi;
14
- import io.scanbot.barcodesdk.plugin.reactnative.components.base.views.RNScanbotNativeComponentFrameLayout;
15
- import io.scanbot.barcodesdk.plugin.reactnative.components.base.views.RNScanbotNativeComponentRootView;
16
- import io.scanbot.sdk.ui.camera.FinderOverlayView;
17
- import io.scanbot.sdk.ui.camera.ScanbotCameraXView;
18
-
19
- public class RNScanbotBarcodeCameraUi extends RNScanbotNativeComponentUi {
20
-
21
- private FinderOverlayView finderOverlayView;
22
- private ScanbotCameraXView cameraView;
23
- private RNScanbotNativeComponentFrameLayout cameraLayout;
24
-
25
- public RNScanbotBarcodeCameraUi(@NonNull final ReactContext reactContext) {
26
- super(reactContext);
27
- }
28
-
29
- @Override
30
- protected RNScanbotNativeComponentRootView createRootView(@NonNull final ReactContext reactContext) {
31
- final Activity activity = reactContext.getCurrentActivity();
32
- if (activity == null) {
33
- throw new IllegalStateException("ERROR: Cannot retrieve current activity");
34
- }
35
- return setupUIAndGetRootView(activity);
36
- }
37
-
38
- public FinderOverlayView getFinderOverlayView() {
39
- return this.finderOverlayView;
40
- }
41
- public ScanbotCameraXView getCameraView() {
42
- return this.cameraView;
43
- }
44
-
45
- /*
46
- * Takes care of inflating the XML layout, retrieving the views and configuring them (UI)
47
- */
48
- private RNScanbotNativeComponentRootView setupUIAndGetRootView(@NonNull final Activity activity) {
49
- // Retrieves Root View from XML layout
50
- final RNScanbotNativeComponentRootView rootView = (RNScanbotNativeComponentRootView) LayoutInflater
51
- .from(activity)
52
- .inflate(R.layout.component_barcode_camera_view, null, false);
53
-
54
- // Retrieves the inner Camera Layout and configures it
55
- cameraLayout = rootView.findViewById(R.id.barcode_camera_layout);
56
- cameraLayout.setZ(-1.0f);
57
- cameraLayout.setLayoutParams(new FrameLayout.LayoutParams(
58
- FrameLayout.LayoutParams.MATCH_PARENT,
59
- FrameLayout.LayoutParams.MATCH_PARENT));
60
-
61
- finderOverlayView = rootView.findViewById(R.id.barcode_finder_overlay);
62
- cameraView = rootView.findViewById(R.id.barcode_camera);
63
-
64
- return rootView;
65
- }
66
-
67
- @Override
68
- protected void onViewsRemeasured() {
69
- cameraView.stopPreview();
70
-
71
- final Size cameraViewSize = new Size(
72
- cameraLayout.getWidth(),
73
- cameraLayout.getHeight()
74
- );
75
-
76
- cameraView.setPreviewFrameSize(cameraViewSize);
77
- cameraView.setAnalyzerFrameSize(cameraViewSize);
78
-
79
- cameraView.startPreview();
80
- }
81
- }