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.
- package/LICENSE +1 -1
- package/Libraries.txt +2 -2
- package/android/.gradle/6.2/executionHistory/executionHistory.lock +0 -0
- package/android/build.gradle +1 -1
- package/android/src/main/java/com/reactlibrary/ScanbotBarcodeSdkModule.java +0 -6
- package/android/src/main/java/com/reactlibrary/ScanbotBarcodeSdkPackage.java +7 -10
- package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/ScanbotBarcodeSdkPackage.java +6 -10
- package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/barcodecameraview/ScanbotBarcodeCameraView.java +380 -0
- package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/barcodecameraview/{RNScanbotBarcodeCameraConfiguration.java → ScanbotBarcodeCameraViewConfiguration.java} +18 -21
- package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/barcodecameraview/ScanbotBarcodeCameraViewManager.java +114 -0
- package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/base/communication/{RNScanbotEventEmitter.java → ScanbotEventEmitter.java} +7 -7
- package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/base/communication/{RNScanbotEventReceiver.java → ScanbotEventReceiver.java} +7 -7
- package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/base/models/ScanbotFinderInset.java +8 -0
- package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/base/ui/ScanbotViewWrapper.java +26 -0
- package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/utils/ScanbotViewUtils.java +52 -0
- package/ios/Components/BarcodeCameraView/RNScanbotBarcodeCameraView.m +1 -1
- package/package.json +1 -1
- package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/barcodecameraview/RNScanbotBarcodeCameraComponent.java +0 -283
- package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/barcodecameraview/RNScanbotBarcodeCameraUi.java +0 -81
- package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/base/RNScanbotNativeComponent.java +0 -90
- package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/base/RNScanbotNativeComponentManager.java +0 -133
- package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/base/RNScanbotNativeComponentManagerFactory.java +0 -40
- package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/base/RNScanbotNativeComponentUi.java +0 -131
- package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/base/views/RNScanbotNativeComponentFrameLayout.java +0 -53
- package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/base/views/RNScanbotNativeComponentRootView.java +0 -154
- package/android/src/main/res/layout/component_barcode_camera_view.xml +0 -28
- package/android/src/main/res/layout/fragment_barcode_scanner.xml +0 -23
package/LICENSE
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
All items and source code Copyright (c)
|
|
1
|
+
All items and source code Copyright (c) 2023 Scanbot SDK GmbH (https://scanbot.io).
|
|
2
2
|
|
|
3
3
|
Scanbot Document and Barcode Scanner SDK for React Native is a commercial
|
|
4
4
|
product and requires a license to be used in a production environment. It will
|
package/Libraries.txt
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Open Source libraries used in the Scanbot Barcode SDK for React Native version 3.3.
|
|
1
|
+
Open Source libraries used in the Scanbot Barcode SDK for React Native version 3.3.1
|
|
2
2
|
|
|
3
3
|
------------------------------------------------------------------------------------------------------------------------
|
|
4
4
|
|
|
@@ -1972,7 +1972,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
|
|
1972
1972
|
|
|
1973
1973
|
------------------------------------------------------------------------------------------------------------------------
|
|
1974
1974
|
|
|
1975
|
-
Open Source libraries used in the Scanbot Barcode Scanner SDK for Android version 3.3.1
|
|
1975
|
+
Open Source libraries used in the Scanbot Barcode Scanner SDK for Android version 3.3.1.244-SNAPSHOT
|
|
1976
1976
|
|
|
1977
1977
|
CWAC-Camera
|
|
1978
1978
|
|
|
Binary file
|
package/android/build.gradle
CHANGED
|
@@ -23,10 +23,4 @@ public class ScanbotBarcodeSdkModule extends ReactContextBaseJavaModule {
|
|
|
23
23
|
public String getName() {
|
|
24
24
|
return "ScanbotBarcodeSdk";
|
|
25
25
|
}
|
|
26
|
-
|
|
27
|
-
@ReactMethod
|
|
28
|
-
public void sampleMethod(String stringArgument, int numberArgument, Callback callback) {
|
|
29
|
-
// TODO: Implement some actually useful functionality
|
|
30
|
-
callback.invoke("Received numberArgument: " + numberArgument + " stringArgument: " + stringArgument);
|
|
31
|
-
}
|
|
32
26
|
}
|
|
@@ -8,6 +8,7 @@ package com.reactlibrary;
|
|
|
8
8
|
import androidx.annotation.NonNull;
|
|
9
9
|
|
|
10
10
|
import java.util.Arrays;
|
|
11
|
+
import java.util.Collections;
|
|
11
12
|
import java.util.List;
|
|
12
13
|
|
|
13
14
|
import com.facebook.react.ReactPackage;
|
|
@@ -15,13 +16,14 @@ import com.facebook.react.bridge.NativeModule;
|
|
|
15
16
|
import com.facebook.react.bridge.ReactApplicationContext;
|
|
16
17
|
import com.facebook.react.uimanager.ViewManager;
|
|
17
18
|
|
|
18
|
-
import io.scanbot.barcodesdk.plugin.reactnative.
|
|
19
|
-
import io.scanbot.barcodesdk.plugin.reactnative.components.
|
|
19
|
+
import io.scanbot.barcodesdk.plugin.reactnative.ScanbotBarcodeSdkModule;
|
|
20
|
+
import io.scanbot.barcodesdk.plugin.reactnative.components.barcodecameraview.ScanbotBarcodeCameraViewManager;
|
|
20
21
|
|
|
21
22
|
public class ScanbotBarcodeSdkPackage implements ReactPackage {
|
|
23
|
+
@NonNull
|
|
22
24
|
@Override
|
|
23
|
-
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
|
|
24
|
-
return
|
|
25
|
+
public List<NativeModule> createNativeModules(@NonNull ReactApplicationContext reactContext) {
|
|
26
|
+
return Collections.singletonList(new ScanbotBarcodeSdkModule(reactContext));
|
|
25
27
|
}
|
|
26
28
|
|
|
27
29
|
/*
|
|
@@ -31,11 +33,6 @@ public class ScanbotBarcodeSdkPackage implements ReactPackage {
|
|
|
31
33
|
@SuppressWarnings({ "rawtypes" })
|
|
32
34
|
@Override
|
|
33
35
|
public List<ViewManager> createViewManagers(@NonNull ReactApplicationContext reactContext) {
|
|
34
|
-
|
|
35
|
-
// RNScanbotNativeComponentManagerFactory
|
|
36
|
-
final RNScanbotNativeComponentManagerFactory factory = new RNScanbotNativeComponentManagerFactory(reactContext);
|
|
37
|
-
return Arrays.asList(new ViewManager[] {
|
|
38
|
-
factory.createManager(new RNScanbotBarcodeCameraComponent(reactContext), "ScanbotBarcodeCameraView")
|
|
39
|
-
});
|
|
36
|
+
return Collections.singletonList(new ScanbotBarcodeCameraViewManager());
|
|
40
37
|
}
|
|
41
38
|
}
|
package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/ScanbotBarcodeSdkPackage.java
CHANGED
|
@@ -8,6 +8,7 @@ package io.scanbot.barcodesdk.plugin.reactnative;
|
|
|
8
8
|
import androidx.annotation.NonNull;
|
|
9
9
|
|
|
10
10
|
import java.util.Arrays;
|
|
11
|
+
import java.util.Collections;
|
|
11
12
|
import java.util.List;
|
|
12
13
|
|
|
13
14
|
import com.facebook.react.ReactPackage;
|
|
@@ -15,13 +16,13 @@ import com.facebook.react.bridge.NativeModule;
|
|
|
15
16
|
import com.facebook.react.bridge.ReactApplicationContext;
|
|
16
17
|
import com.facebook.react.uimanager.ViewManager;
|
|
17
18
|
|
|
18
|
-
import io.scanbot.barcodesdk.plugin.reactnative.components.barcodecameraview.
|
|
19
|
-
import io.scanbot.barcodesdk.plugin.reactnative.components.base.RNScanbotNativeComponentManagerFactory;
|
|
19
|
+
import io.scanbot.barcodesdk.plugin.reactnative.components.barcodecameraview.ScanbotBarcodeCameraViewManager;
|
|
20
20
|
|
|
21
21
|
public class ScanbotBarcodeSdkPackage implements ReactPackage {
|
|
22
|
+
@NonNull
|
|
22
23
|
@Override
|
|
23
|
-
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
|
|
24
|
-
return
|
|
24
|
+
public List<NativeModule> createNativeModules(@NonNull ReactApplicationContext reactContext) {
|
|
25
|
+
return Collections.singletonList(new ScanbotBarcodeSdkModule(reactContext));
|
|
25
26
|
}
|
|
26
27
|
|
|
27
28
|
/*
|
|
@@ -31,11 +32,6 @@ public class ScanbotBarcodeSdkPackage implements ReactPackage {
|
|
|
31
32
|
@SuppressWarnings({ "rawtypes" })
|
|
32
33
|
@Override
|
|
33
34
|
public List<ViewManager> createViewManagers(@NonNull ReactApplicationContext reactContext) {
|
|
34
|
-
|
|
35
|
-
// RNScanbotNativeComponentManagerFactory
|
|
36
|
-
final RNScanbotNativeComponentManagerFactory factory = new RNScanbotNativeComponentManagerFactory(reactContext);
|
|
37
|
-
return Arrays.asList(new ViewManager[] {
|
|
38
|
-
factory.createManager(new RNScanbotBarcodeCameraComponent(reactContext), "ScanbotBarcodeCameraView")
|
|
39
|
-
});
|
|
35
|
+
return Collections.singletonList(new ScanbotBarcodeCameraViewManager());
|
|
40
36
|
}
|
|
41
37
|
}
|
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
package io.scanbot.barcodesdk.plugin.reactnative.components.barcodecameraview;
|
|
2
|
+
|
|
3
|
+
import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
|
|
4
|
+
import static io.scanbot.barcodesdk.plugin.reactnative.utils.ScanbotViewUtils.colorWithAlpha;
|
|
5
|
+
|
|
6
|
+
import android.Manifest;
|
|
7
|
+
import android.app.Activity;
|
|
8
|
+
import android.content.Context;
|
|
9
|
+
import android.content.pm.PackageManager;
|
|
10
|
+
import android.graphics.Color;
|
|
11
|
+
import android.util.Size;
|
|
12
|
+
import android.view.View;
|
|
13
|
+
import android.view.ViewGroup;
|
|
14
|
+
import android.widget.FrameLayout;
|
|
15
|
+
|
|
16
|
+
import androidx.annotation.NonNull;
|
|
17
|
+
import androidx.core.app.ActivityCompat;
|
|
18
|
+
import androidx.core.content.ContextCompat;
|
|
19
|
+
import androidx.lifecycle.LifecycleOwner;
|
|
20
|
+
|
|
21
|
+
import com.facebook.react.bridge.ReactContext;
|
|
22
|
+
import com.facebook.react.bridge.ReadableMap;
|
|
23
|
+
import com.facebook.react.bridge.WritableMap;
|
|
24
|
+
import com.facebook.react.views.view.ReactViewGroup;
|
|
25
|
+
|
|
26
|
+
import java.util.Collections;
|
|
27
|
+
import java.util.List;
|
|
28
|
+
|
|
29
|
+
import io.scanbot.barcodesdk.plugin.reactnative.R;
|
|
30
|
+
import io.scanbot.barcodesdk.plugin.reactnative.components.base.ui.ScanbotViewWrapper;
|
|
31
|
+
import io.scanbot.barcodesdk.plugin.reactnative.components.base.communication.ScanbotEventEmitter;
|
|
32
|
+
import io.scanbot.barcodesdk.plugin.reactnative.utils.JSONUtils;
|
|
33
|
+
import io.scanbot.barcodesdk.plugin.reactnative.utils.ScanbotViewUtils;
|
|
34
|
+
import io.scanbot.sdk.SdkLicenseError;
|
|
35
|
+
import io.scanbot.sdk.barcode.BarcodeDetectorFrameHandler;
|
|
36
|
+
import io.scanbot.sdk.barcode.DefaultScanbotBarcodeDetector;
|
|
37
|
+
import io.scanbot.sdk.barcode.ScanbotBarcodeDetector;
|
|
38
|
+
import io.scanbot.sdk.barcode.entity.BarcodeItem;
|
|
39
|
+
import io.scanbot.sdk.barcode.entity.BarcodeScannerAdditionalConfig;
|
|
40
|
+
import io.scanbot.sdk.barcode.entity.BarcodeScanningResult;
|
|
41
|
+
import io.scanbot.sdk.camera.FrameHandlerResult;
|
|
42
|
+
import io.scanbot.sdk.ui.camera.FinderOverlayView;
|
|
43
|
+
import io.scanbot.sdk.ui.camera.ScanbotCameraXView;
|
|
44
|
+
import kotlin.TypeCastException;
|
|
45
|
+
import kotlin.Unit;
|
|
46
|
+
|
|
47
|
+
public class ScanbotBarcodeCameraView extends FrameLayout implements BarcodeDetectorFrameHandler.ResultHandler {
|
|
48
|
+
// From Java to JavaScript
|
|
49
|
+
public enum NativeEvents implements ScanbotEventEmitter.NativeEvent {
|
|
50
|
+
BARCODE_SCANNER_RESULT("onBarcodeScannerResult");
|
|
51
|
+
|
|
52
|
+
private final String name;
|
|
53
|
+
NativeEvents(final String name) {
|
|
54
|
+
this.name = name;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
public String getName() {
|
|
58
|
+
return name;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Constants
|
|
63
|
+
private static final int REQUEST_PERMISSION_CODE = 200;
|
|
64
|
+
|
|
65
|
+
// Views
|
|
66
|
+
private ScanbotCameraXView cameraView;
|
|
67
|
+
private FinderOverlayView finderOverlayView;
|
|
68
|
+
private ViewGroup childrenContainerView;
|
|
69
|
+
|
|
70
|
+
// Barcode Detection
|
|
71
|
+
private BarcodeDetectorFrameHandler frameHandler;
|
|
72
|
+
private ScanbotBarcodeDetector barcodeDetector;
|
|
73
|
+
|
|
74
|
+
// Communication
|
|
75
|
+
private ScanbotEventEmitter eventEmitter;
|
|
76
|
+
|
|
77
|
+
// Configuration
|
|
78
|
+
private ScanbotBarcodeCameraViewConfiguration configuration = new ScanbotBarcodeCameraViewConfiguration();
|
|
79
|
+
private float userDefinedCameraZoomFactor = -1;
|
|
80
|
+
|
|
81
|
+
public ScanbotBarcodeCameraView(@NonNull Context context) {
|
|
82
|
+
super(context);
|
|
83
|
+
initCommunication();
|
|
84
|
+
createViews();
|
|
85
|
+
createFrameHandler();
|
|
86
|
+
refreshConfiguration();
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/*---------------------------*
|
|
90
|
+
* Barcode Detection
|
|
91
|
+
---------------------------*/
|
|
92
|
+
private void createFrameHandler() {
|
|
93
|
+
this.barcodeDetector = new DefaultScanbotBarcodeDetector();
|
|
94
|
+
this.frameHandler = BarcodeDetectorFrameHandler.attach(cameraView, barcodeDetector);
|
|
95
|
+
this.frameHandler.setDetectionInterval(0);
|
|
96
|
+
this.frameHandler.addResultHandler(this);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// Barcode Detector Frame Handler - Result Handler
|
|
100
|
+
@Override
|
|
101
|
+
public boolean handle(@NonNull FrameHandlerResult<? extends BarcodeScanningResult, ? extends SdkLicenseError> result) {
|
|
102
|
+
if (result instanceof FrameHandlerResult.Success) {
|
|
103
|
+
//noinspection unchecked
|
|
104
|
+
handleBarcodeScanningResult((FrameHandlerResult.Success<BarcodeScanningResult>) result);
|
|
105
|
+
}
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
private void handleBarcodeScanningResult(final FrameHandlerResult.Success<BarcodeScanningResult> result) {
|
|
110
|
+
if (result.getValue() == null) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
final List<BarcodeItem> barcodeItems = result.getValue().getBarcodeItems();
|
|
115
|
+
sendResultToJS(preprocessBarcodeItems(barcodeItems));
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
private List<BarcodeItem> preprocessBarcodeItems(final List<BarcodeItem> barcodeItems) {
|
|
119
|
+
if (configuration.barcodeFilter != null) {
|
|
120
|
+
return JSONUtils.getBarcodeItemsFromItemListWithFilter(barcodeItems, configuration.barcodeFilter);
|
|
121
|
+
}
|
|
122
|
+
return barcodeItems;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/*---------------------------*
|
|
126
|
+
* Communication
|
|
127
|
+
---------------------------*/
|
|
128
|
+
private void initCommunication() {
|
|
129
|
+
this.eventEmitter = new ScanbotEventEmitter(getReactContext(), this);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
private void sendResultToJS(final List<BarcodeItem> barcodeItems) {
|
|
133
|
+
if (barcodeItems == null || barcodeItems.size() == 0) {
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
final ReadableMap result = JSONUtils.jsonResultFromBarcodeItems(barcodeItems);
|
|
138
|
+
final WritableMap data = new JSONUtils.WritableMapBuilder()
|
|
139
|
+
.putMap("result", result)
|
|
140
|
+
.build();
|
|
141
|
+
|
|
142
|
+
eventEmitter.emitEvent(NativeEvents.BARCODE_SCANNER_RESULT, data);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/*---------------------------*
|
|
146
|
+
* Configuration
|
|
147
|
+
---------------------------*/
|
|
148
|
+
public void applyConfiguration(@NonNull final ReadableMap jsonConfig) {
|
|
149
|
+
this.configuration = ScanbotBarcodeCameraViewConfiguration.fromJsonMap(jsonConfig);
|
|
150
|
+
refreshConfiguration();
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
public void refreshConfiguration() {
|
|
154
|
+
getReactContext().runOnUiQueueThread(() -> {
|
|
155
|
+
|
|
156
|
+
final ScanbotBarcodeCameraViewConfiguration config = this.configuration;
|
|
157
|
+
|
|
158
|
+
// Finder Overlay View
|
|
159
|
+
finderOverlayView.setOverlayColor(colorWithAlpha(
|
|
160
|
+
config.getFinderBackgroundColor(),
|
|
161
|
+
config.getFinderBackgroundOpacity()
|
|
162
|
+
));
|
|
163
|
+
|
|
164
|
+
finderOverlayView.setVisibility(config.shouldUseFinderView() ? View.VISIBLE : View.INVISIBLE);
|
|
165
|
+
finderOverlayView.setStrokeWidth(config.getFinderLineWidth());
|
|
166
|
+
finderOverlayView.setStrokeColor(config.getFinderLineColor());
|
|
167
|
+
|
|
168
|
+
if (config.finderInset != null) {
|
|
169
|
+
finderOverlayView.setFinderInset(
|
|
170
|
+
config.finderInset.left,
|
|
171
|
+
config.finderInset.top,
|
|
172
|
+
config.finderInset.right,
|
|
173
|
+
config.finderInset.bottom);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
finderOverlayView.setFinderMinPadding(config.getFinderMinimumPadding());
|
|
177
|
+
finderOverlayView.setRequiredAspectRatios(Collections.singletonList(config.getFinderAspectRatio()));
|
|
178
|
+
finderOverlayView.requestLayout();
|
|
179
|
+
|
|
180
|
+
// Camera View
|
|
181
|
+
cameraView.useFlash(config.isFlashEnabled());
|
|
182
|
+
|
|
183
|
+
if (shouldSetCameraZoomFactor(config)) {
|
|
184
|
+
cameraView.setOpticalZoomLevel(config.getCameraZoomFactor());
|
|
185
|
+
userDefinedCameraZoomFactor = config.getCameraZoomFactor();
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// TODO: Re-use ScanbotBarcodeDetectorConfigBuilder
|
|
189
|
+
barcodeDetector.modifyConfig(b -> {
|
|
190
|
+
if(!config.barcodeFormats.isEmpty()) {
|
|
191
|
+
b.setBarcodeFormats(config.barcodeFormats);
|
|
192
|
+
}
|
|
193
|
+
if(!config.acceptedDocumentFormats.isEmpty()) {
|
|
194
|
+
b.setAcceptedDocumentFormats(config.acceptedDocumentFormats);
|
|
195
|
+
}
|
|
196
|
+
b.setEngineMode(config.engineMode);
|
|
197
|
+
if (config.additionalConfiguration != null) {
|
|
198
|
+
// TODO: Re-use ScanbotBarcodeDetectorAdditionalConfigBuilder
|
|
199
|
+
b.modifyAdditionalConfig(ab -> {
|
|
200
|
+
final BarcodeScannerAdditionalConfig cfg = config.additionalConfiguration;
|
|
201
|
+
ab.setMinimumTextLength(cfg.getMinimumTextLength());
|
|
202
|
+
ab.setMaximumTextLength(cfg.getMaximumTextLength());
|
|
203
|
+
ab.setMsiPlesseyChecksumAlgorithms(cfg.getMsiPlesseyChecksumAlgorithms());
|
|
204
|
+
ab.setStripCheckDigits(cfg.getStripCheckDigits());
|
|
205
|
+
ab.setGs1DecodingEnabled(cfg.getGs1DecodingEnabled());
|
|
206
|
+
ab.setMinimum1DQuietZoneSize(cfg.getMinimum1DQuietZoneSize());
|
|
207
|
+
ab.setLowPowerMode(cfg.getLowPowerMode());
|
|
208
|
+
return Unit.INSTANCE;
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
return Unit.INSTANCE;
|
|
213
|
+
});
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
private boolean shouldSetCameraZoomFactor(final ScanbotBarcodeCameraViewConfiguration config) {
|
|
218
|
+
return (
|
|
219
|
+
config.getCameraZoomFactor() != -1 &&
|
|
220
|
+
(config.getCameraZoomFactor() != userDefinedCameraZoomFactor || userDefinedCameraZoomFactor == -1)
|
|
221
|
+
);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/*---------------------------*
|
|
225
|
+
* Views Creation
|
|
226
|
+
---------------------------*/
|
|
227
|
+
private void createViews() {
|
|
228
|
+
final Context context = getReactContext().getCurrentActivity();
|
|
229
|
+
|
|
230
|
+
cameraView = createScanbotCameraView(context);
|
|
231
|
+
finderOverlayView = createFinderOverlayView(context);
|
|
232
|
+
childrenContainerView = createChildrenContainerView(context);
|
|
233
|
+
|
|
234
|
+
addView(cameraView);
|
|
235
|
+
addView(finderOverlayView);
|
|
236
|
+
addView(childrenContainerView);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
private ViewGroup createChildrenContainerView(final Context context) {
|
|
240
|
+
final ReactViewGroup containerView = new ReactViewGroup(context);
|
|
241
|
+
|
|
242
|
+
containerView.setLayoutParams(new LayoutParams(MATCH_PARENT, MATCH_PARENT));
|
|
243
|
+
containerView.setZ(2.0f);
|
|
244
|
+
|
|
245
|
+
return containerView;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
private FinderOverlayView createFinderOverlayView(final Context context) {
|
|
249
|
+
final FinderOverlayView finderView = new FinderOverlayView(context, null);
|
|
250
|
+
|
|
251
|
+
finderView.setLayoutParams(new LayoutParams(MATCH_PARENT, MATCH_PARENT));
|
|
252
|
+
finderView.setId(R.id.finder_overlay);
|
|
253
|
+
|
|
254
|
+
ScanbotViewUtils.installHierarchyFitter(finderView);
|
|
255
|
+
|
|
256
|
+
return finderView;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
private ScanbotCameraXView createScanbotCameraView(final Context context) {
|
|
260
|
+
final ScanbotCameraXView cameraView = new ScanbotCameraXView(context);
|
|
261
|
+
|
|
262
|
+
cameraView.setLifecycleOwner(getLifecycleOwner());
|
|
263
|
+
cameraView.setLayoutParams(new LayoutParams(MATCH_PARENT, MATCH_PARENT));
|
|
264
|
+
cameraView.setBackgroundColor(Color.BLACK);
|
|
265
|
+
cameraView.setCameraOpenCallback(cameraView::continuousFocus);
|
|
266
|
+
cameraView.post(this::checkPermissions);
|
|
267
|
+
|
|
268
|
+
applyWorkaroundForReactNativeIssue17968(cameraView);
|
|
269
|
+
|
|
270
|
+
return cameraView;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/*---------------------------*
|
|
274
|
+
* View Lifecycle Handling
|
|
275
|
+
---------------------------*/
|
|
276
|
+
@Override
|
|
277
|
+
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
|
|
278
|
+
super.onLayout(changed, left, top, right, bottom);
|
|
279
|
+
remeasureCameraFrame();
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/*---------------------------*
|
|
283
|
+
* React Views Handling
|
|
284
|
+
---------------------------*/
|
|
285
|
+
@Override
|
|
286
|
+
public void addView(View child, int index, ViewGroup.LayoutParams params) {
|
|
287
|
+
if (isReactChildView(child)) {
|
|
288
|
+
addReactChildView(child);
|
|
289
|
+
} else {
|
|
290
|
+
super.addView(child, index, params);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* WORKAROUND FOR ISSUE: react child views are not measured / positioned correctly
|
|
296
|
+
*/
|
|
297
|
+
private void addReactChildView(final View child) {
|
|
298
|
+
// If the child has a parent, we take it away ¯\_(ツ)_/¯
|
|
299
|
+
if (child.getParent() instanceof ViewGroup) {
|
|
300
|
+
((ViewGroup) child.getParent()).removeView(child);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
final View view = ScanbotViewWrapper.wrap(child);
|
|
304
|
+
childrenContainerView.addView(view);
|
|
305
|
+
childrenContainerView.invalidate();
|
|
306
|
+
childrenContainerView.requestLayout();
|
|
307
|
+
|
|
308
|
+
view.invalidate();
|
|
309
|
+
view.requestLayout();
|
|
310
|
+
|
|
311
|
+
childrenContainerView.bringToFront();
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
private boolean isReactChildView(final View child) {
|
|
315
|
+
return child != cameraView && child != finderOverlayView && child != childrenContainerView;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/*---------------------------*
|
|
319
|
+
* Camera Related
|
|
320
|
+
---------------------------*/
|
|
321
|
+
/**
|
|
322
|
+
* WORKAROUND FOR ISSUE: camera frame size is not auto-calculated correctly
|
|
323
|
+
*/
|
|
324
|
+
private void remeasureCameraFrame() {
|
|
325
|
+
cameraView.setCameraFrameSize(new Size(this.getWidth(), this.getHeight()));
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
/*---------------------------*
|
|
329
|
+
* Utils and overrides
|
|
330
|
+
---------------------------*/
|
|
331
|
+
/**
|
|
332
|
+
* WORKAROUND for React Native ISSUE #17968
|
|
333
|
+
* Android native UI components are not re-layout on dynamically added views
|
|
334
|
+
* https://github.com/facebook/react-native/issues/17968
|
|
335
|
+
* @param cameraView - The view that CONTAINS a PreviewView
|
|
336
|
+
*/
|
|
337
|
+
private void applyWorkaroundForReactNativeIssue17968(final ViewGroup cameraView) {
|
|
338
|
+
ScanbotViewUtils.installHierarchyFitter(cameraView);
|
|
339
|
+
ScanbotViewUtils.installHierarchyFitter(cameraView.findViewById(R.id.camera_preview_view));
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
public static NativeEvents[] getNativeEvents() {
|
|
343
|
+
return NativeEvents.values();
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
private ReactContext getReactContext() {
|
|
347
|
+
final Context context = getContext();
|
|
348
|
+
if (context instanceof ReactContext) {
|
|
349
|
+
return (ReactContext) context;
|
|
350
|
+
}
|
|
351
|
+
throw new TypeCastException("Context is not of type ReactContext");
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
private LifecycleOwner getLifecycleOwner() {
|
|
355
|
+
final Activity activity = getReactContext().getCurrentActivity();
|
|
356
|
+
if (activity instanceof LifecycleOwner) {
|
|
357
|
+
return (LifecycleOwner) activity;
|
|
358
|
+
}
|
|
359
|
+
throw new TypeCastException("Activity is not of type LifecycleOwner");
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
private void checkPermissions() {
|
|
363
|
+
final Activity activity = this.getReactContext().getCurrentActivity();
|
|
364
|
+
if (activity == null) {
|
|
365
|
+
return;
|
|
366
|
+
}
|
|
367
|
+
final int cameraPermission = ContextCompat.checkSelfPermission(
|
|
368
|
+
activity,
|
|
369
|
+
Manifest.permission.CAMERA
|
|
370
|
+
);
|
|
371
|
+
|
|
372
|
+
if (cameraPermission != PackageManager.PERMISSION_GRANTED) {
|
|
373
|
+
ActivityCompat.requestPermissions(
|
|
374
|
+
activity,
|
|
375
|
+
new String[] { Manifest.permission.CAMERA },
|
|
376
|
+
REQUEST_PERMISSION_CODE
|
|
377
|
+
);
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
package io.scanbot.barcodesdk.plugin.reactnative.components.barcodecameraview;
|
|
2
2
|
|
|
3
|
-
;
|
|
4
|
-
|
|
5
3
|
import android.graphics.Color;
|
|
6
4
|
|
|
7
5
|
import androidx.annotation.NonNull;
|
|
@@ -11,19 +9,19 @@ import com.facebook.react.bridge.ReadableMap;
|
|
|
11
9
|
import java.util.ArrayList;
|
|
12
10
|
import java.util.List;
|
|
13
11
|
|
|
12
|
+
import io.scanbot.barcodesdk.plugin.reactnative.ObjectMapper;
|
|
13
|
+
import io.scanbot.barcodesdk.plugin.reactnative.components.base.models.ScanbotFinderInset;
|
|
14
|
+
import io.scanbot.barcodesdk.plugin.reactnative.utils.JSONUtils;
|
|
15
|
+
import io.scanbot.sdk.barcode.BarcodeFilter;
|
|
14
16
|
import io.scanbot.sdk.barcode.entity.BarcodeDensity;
|
|
15
17
|
import io.scanbot.sdk.barcode.entity.BarcodeDocumentFormat;
|
|
16
18
|
import io.scanbot.sdk.barcode.entity.BarcodeFormat;
|
|
17
19
|
import io.scanbot.sdk.barcode.entity.BarcodeScannerAdditionalConfig;
|
|
18
20
|
import io.scanbot.sdk.barcode.entity.EngineMode;
|
|
19
|
-
import io.scanbot.barcodesdk.plugin.reactnative.utils.JSONUtils;
|
|
20
|
-
import io.scanbot.barcodesdk.plugin.reactnative.ObjectMapper;
|
|
21
21
|
import io.scanbot.sdk.ui.camera.FinderAspectRatio;
|
|
22
|
-
import io.scanbot.sdk.barcode.BarcodeFilter;
|
|
23
|
-
import io.scanbot.sdk.ui.view.barcode.SelectionOverlayConfiguration;
|
|
24
22
|
|
|
25
23
|
@SuppressWarnings("unused")
|
|
26
|
-
public class
|
|
24
|
+
public class ScanbotBarcodeCameraViewConfiguration {
|
|
27
25
|
// Manually mapped properties (must NOT have a getter and setter)
|
|
28
26
|
public List<BarcodeFormat> barcodeFormats = new ArrayList<>();
|
|
29
27
|
public List<BarcodeDocumentFormat> acceptedDocumentFormats = new ArrayList<>();
|
|
@@ -31,13 +29,14 @@ public class RNScanbotBarcodeCameraConfiguration {
|
|
|
31
29
|
public BarcodeScannerAdditionalConfig additionalConfiguration;
|
|
32
30
|
public BarcodeFilter barcodeFilter;
|
|
33
31
|
public BarcodeDensity codeDensity;
|
|
34
|
-
public
|
|
32
|
+
public ScanbotFinderInset finderInset;
|
|
35
33
|
|
|
36
34
|
// Automatically mapped properties (must have a getter and a setter with the same name)
|
|
37
35
|
private boolean shouldUseFinderView = false;
|
|
38
36
|
private int finderLineWidth = 1;
|
|
39
37
|
private int finderLineColor = Color.WHITE;
|
|
40
38
|
private int finderBackgroundColor = Color.BLACK;
|
|
39
|
+
private int finderMinimumPadding = 64;
|
|
41
40
|
private float finderBackgroundOpacity = 0.66f;
|
|
42
41
|
private float cameraZoomFactor = -1;
|
|
43
42
|
private boolean flashEnabled = false;
|
|
@@ -55,6 +54,10 @@ public class RNScanbotBarcodeCameraConfiguration {
|
|
|
55
54
|
this.finderLineColor = viewFinderLineColor;
|
|
56
55
|
}
|
|
57
56
|
|
|
57
|
+
public void setFinderMinimumPadding(int finderMinimumPadding) {
|
|
58
|
+
this.finderMinimumPadding = finderMinimumPadding;
|
|
59
|
+
}
|
|
60
|
+
|
|
58
61
|
public void setFinderBackgroundColor(@androidx.annotation.ColorInt int viewFinderBackgroundColor) {
|
|
59
62
|
this.finderBackgroundColor = viewFinderBackgroundColor;
|
|
60
63
|
}
|
|
@@ -83,6 +86,8 @@ public class RNScanbotBarcodeCameraConfiguration {
|
|
|
83
86
|
return finderLineWidth;
|
|
84
87
|
}
|
|
85
88
|
|
|
89
|
+
public int getFinderMinimumPadding() { return finderMinimumPadding; }
|
|
90
|
+
|
|
86
91
|
public int getFinderLineColor() {
|
|
87
92
|
return finderLineColor;
|
|
88
93
|
}
|
|
@@ -113,9 +118,10 @@ public class RNScanbotBarcodeCameraConfiguration {
|
|
|
113
118
|
* @param jsonConfig ReadableMap
|
|
114
119
|
*/
|
|
115
120
|
private void populateFinderInset(ReadableMap jsonConfig) {
|
|
116
|
-
this.finderInset = new FinderInset();
|
|
117
121
|
if (jsonConfig.hasKey("finderInset")) {
|
|
122
|
+
this.finderInset = new ScanbotFinderInset();
|
|
118
123
|
jsonConfig = jsonConfig.getMap("finderInset");
|
|
124
|
+
assert jsonConfig != null;
|
|
119
125
|
|
|
120
126
|
if (jsonConfig.hasKey("left")) {
|
|
121
127
|
this.finderInset.left = jsonConfig.getInt("left");
|
|
@@ -136,8 +142,8 @@ public class RNScanbotBarcodeCameraConfiguration {
|
|
|
136
142
|
}
|
|
137
143
|
|
|
138
144
|
@NonNull
|
|
139
|
-
public static
|
|
140
|
-
final
|
|
145
|
+
public static ScanbotBarcodeCameraViewConfiguration fromJsonMap(ReadableMap jsonConfig) {
|
|
146
|
+
final ScanbotBarcodeCameraViewConfiguration nativeConfig = new ScanbotBarcodeCameraViewConfiguration();
|
|
141
147
|
|
|
142
148
|
// Automatic Mapping
|
|
143
149
|
try {
|
|
@@ -176,16 +182,7 @@ public class RNScanbotBarcodeCameraConfiguration {
|
|
|
176
182
|
|
|
177
183
|
// Finder inset
|
|
178
184
|
nativeConfig.populateFinderInset(jsonConfig);
|
|
185
|
+
|
|
179
186
|
return nativeConfig;
|
|
180
187
|
}
|
|
181
188
|
}
|
|
182
|
-
|
|
183
|
-
/**
|
|
184
|
-
* Finder Inset class to extract data from common React native side and carry it to the native classical component.
|
|
185
|
-
*/
|
|
186
|
-
class FinderInset {
|
|
187
|
-
public int left;
|
|
188
|
-
public int top;
|
|
189
|
-
public int right;
|
|
190
|
-
public int bottom;
|
|
191
|
-
}
|