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.
- package/Libraries.txt +31 -31
- package/RNScanbotBarcodeSDK.podspec +1 -4
- package/android/build.gradle +6 -5
- package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/ScanbotBarcodeSdkPackage.kt +9 -7
- package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/barcode_scanner_view/ScanbotBarcodeScannerView.kt +114 -0
- package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/barcode_scanner_view/ScanbotBarcodeScannerViewEvents.kt +56 -0
- package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/barcode_scanner_view/ScanbotBarcodeScannerViewManager.kt +256 -0
- package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/extensions/JSONObject.kt +18 -2
- package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/extensions/ReadableMap.kt +3 -4
- package/android/src/newarch/ScanbotBarcodeScannerViewManagerSpec.kt +19 -0
- package/android/src/oldarch/ScanbotBarcodeScannerViewManagerSpec.kt +29 -0
- package/dist/components/barcode-camera-view/ScanbotBarcodeCameraView.d.ts +3 -0
- package/dist/components/barcode-camera-view/ScanbotBarcodeCameraView.js +122 -0
- package/dist/components/barcode-camera-view/ScanbotBarcodeCameraViewProperties.d.ts +89 -0
- package/dist/components/barcode-camera-view/ScanbotBarcodeCameraViewProperties.js +2 -0
- package/dist/components/spec/ScanbotBarcodeScannerViewNativeComponent.d.ts +54 -0
- package/dist/components/spec/ScanbotBarcodeScannerViewNativeComponent.js +12 -0
- package/dist/configurations.d.ts +241 -0
- package/dist/configurations.js +2 -0
- package/dist/customConfigurations.d.ts +94 -0
- package/dist/customConfigurations.js +2 -0
- package/dist/customResults.d.ts +5 -0
- package/dist/customResults.js +2 -0
- package/dist/customTypes.d.ts +7 -0
- package/dist/customTypes.js +2 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.js +34 -0
- package/dist/results.d.ts +29 -0
- package/dist/results.js +2 -0
- package/dist/types.d.ts +1194 -0
- package/dist/types.js +2 -0
- package/ios/Components/BarcodeScannerView/RNScanbotBarcodeScannerLegacyView.h +25 -0
- package/ios/Components/BarcodeScannerView/RNScanbotBarcodeScannerLegacyView.m +194 -0
- package/ios/Components/BarcodeScannerView/RNScanbotBarcodeScannerView.h +20 -0
- package/ios/Components/BarcodeScannerView/RNScanbotBarcodeScannerView.mm +259 -0
- package/ios/Components/BarcodeScannerView/RNScanbotBarcodeScannerViewControllerWrapper.h +99 -0
- package/ios/Components/BarcodeScannerView/RNScanbotBarcodeScannerViewControllerWrapper.m +196 -0
- package/ios/Components/BarcodeScannerView/RNScanbotBarcodeScannerViewManager.mm +73 -0
- package/package.json +16 -21
- package/src/components/barcode-camera-view/ScanbotBarcodeCameraView.tsx +112 -0
- package/src/components/barcode-camera-view/ScanbotBarcodeCameraViewProperties.ts +106 -0
- package/src/components/spec/ScanbotBarcodeScannerViewNativeComponent.ts +59 -0
- package/src/index.ts +58 -0
- package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/barcodecameraview/ScanbotBarcodeCameraView.java +0 -401
- package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/base/communication/ScanbotEventEmitter.java +0 -78
- package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/base/communication/ScanbotEventReceiver.java +0 -119
- package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/base/ui/ScanbotViewWrapper.java +0 -26
- package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/utils/JSONUtils.kt +0 -24
- package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/utils/ScanbotViewUtils.java +0 -43
- package/android/src/new-architecture/io/scanbot/barcodesdk/plugin/reactnative/components/barcodecameraview/ScanbotBarcodeCameraViewManager.java +0 -125
- package/android/src/old-architecture/io/scanbot/barcodesdk/plugin/reactnative/components/barcodecameraview/ScanbotBarcodeCameraViewManager.java +0 -114
- package/index.d.ts +0 -42
- package/index.js +0 -20
- package/ios/Components/BarcodeCameraView/NewArchitecture/RTNScanbotBarcodeCameraView.h +0 -44
- package/ios/Components/BarcodeCameraView/NewArchitecture/RTNScanbotBarcodeCameraView.mm +0 -338
- package/ios/Components/BarcodeCameraView/NewArchitecture/RTNScanbotBarcodeCameraViewManager.mm +0 -71
- package/ios/Components/BarcodeCameraView/OldArchitecture/RNScanbotBarcodeCameraView.h +0 -36
- package/ios/Components/BarcodeCameraView/OldArchitecture/RNScanbotBarcodeCameraView.mm +0 -181
- package/ios/Components/BarcodeCameraView/OldArchitecture/RNScanbotBarcodeCameraViewManager.h +0 -28
- package/ios/Components/BarcodeCameraView/OldArchitecture/RNScanbotBarcodeCameraViewManager.mm +0 -89
- package/js/RTNScanbotBarcodeCameraViewNativeComponent.ts +0 -186
- package/src/components/barcode-camera-view/scanbot-barcode-camera-view-types.ts +0 -175
- package/src/components/barcode-camera-view/scanbot-barcode-camera-view.tsx +0 -270
- package/src/components/barcode-camera-view/scanbot-native-barcode-camera-view.ts +0 -7
|
@@ -1,401 +0,0 @@
|
|
|
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.bridge.WritableNativeMap;
|
|
25
|
-
import com.facebook.react.views.view.ReactViewGroup;
|
|
26
|
-
|
|
27
|
-
import org.json.JSONObject;
|
|
28
|
-
|
|
29
|
-
import java.util.Collections;
|
|
30
|
-
|
|
31
|
-
import io.scanbot.barcodesdk.plugin.reactnative.components.base.communication.ScanbotEventEmitter;
|
|
32
|
-
import io.scanbot.barcodesdk.plugin.reactnative.components.base.ui.ScanbotViewWrapper;
|
|
33
|
-
import io.scanbot.barcodesdk.plugin.reactnative.utils.JSONUtils;
|
|
34
|
-
import io.scanbot.barcodesdk.plugin.reactnative.utils.ScanbotViewUtils;
|
|
35
|
-
import io.scanbot.sdk.SdkLicenseError;
|
|
36
|
-
import io.scanbot.sdk.barcode.BarcodeDetectorFrameHandler;
|
|
37
|
-
import io.scanbot.sdk.barcode.BarcodeEanUpcNoExtensionsFilter;
|
|
38
|
-
import io.scanbot.sdk.barcode.BarcodeExtensionsFilter;
|
|
39
|
-
import io.scanbot.sdk.barcode.DefaultScanbotBarcodeDetector;
|
|
40
|
-
import io.scanbot.sdk.barcode.ScanbotBarcodeDetector;
|
|
41
|
-
import io.scanbot.sdk.barcode.entity.BarcodeScanningResult;
|
|
42
|
-
import io.scanbot.sdk.camera.FrameHandlerResult;
|
|
43
|
-
import io.scanbot.sdk.ui.camera.FinderOverlayView;
|
|
44
|
-
import io.scanbot.sdk.ui.camera.ScanbotCameraXView;
|
|
45
|
-
import io.scanbot.sdk_wrapper.SBWrapper;
|
|
46
|
-
import io.scanbot.sdk_wrapper.barcode.configurations.SBWrapperBarcodeCameraViewConfiguration;
|
|
47
|
-
import io.scanbot.sdk_wrapper.barcode.results.SBWrapperBarcodeScannerResult;
|
|
48
|
-
import kotlin.TypeCastException;
|
|
49
|
-
import kotlin.Unit;
|
|
50
|
-
|
|
51
|
-
public class ScanbotBarcodeCameraView extends FrameLayout implements BarcodeDetectorFrameHandler.ResultHandler {
|
|
52
|
-
// From Java to JavaScript
|
|
53
|
-
public enum NativeEvents implements ScanbotEventEmitter.NativeEvent {
|
|
54
|
-
BARCODE_SCANNER_RESULT("onNativeBarcodeScannerResult");
|
|
55
|
-
|
|
56
|
-
private final String name;
|
|
57
|
-
|
|
58
|
-
NativeEvents(final String name) {
|
|
59
|
-
this.name = name;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
public String getName() {
|
|
63
|
-
return name;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// Constants
|
|
68
|
-
private static final int REQUEST_PERMISSION_CODE = 200;
|
|
69
|
-
|
|
70
|
-
// Views
|
|
71
|
-
private ScanbotCameraXView cameraView;
|
|
72
|
-
private FinderOverlayView finderOverlayView;
|
|
73
|
-
private ViewGroup childrenContainerView;
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* @noinspection FieldCanBeLocal
|
|
77
|
-
*/ // Barcode Detection
|
|
78
|
-
private BarcodeDetectorFrameHandler frameHandler;
|
|
79
|
-
private ScanbotBarcodeDetector barcodeDetector;
|
|
80
|
-
|
|
81
|
-
// Communication
|
|
82
|
-
private ScanbotEventEmitter eventEmitter;
|
|
83
|
-
|
|
84
|
-
// Configuration
|
|
85
|
-
private SBWrapperBarcodeCameraViewConfiguration configuration = new SBWrapperBarcodeCameraViewConfiguration();
|
|
86
|
-
private float userDefinedCameraZoomFactor = -1;
|
|
87
|
-
|
|
88
|
-
public ScanbotBarcodeCameraView(@NonNull Context context) {
|
|
89
|
-
super(context);
|
|
90
|
-
initCommunication();
|
|
91
|
-
createViews();
|
|
92
|
-
createFrameHandler();
|
|
93
|
-
refreshConfiguration();
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/*---------------------------*
|
|
97
|
-
* Barcode Detection
|
|
98
|
-
---------------------------*/
|
|
99
|
-
private void createFrameHandler() {
|
|
100
|
-
this.barcodeDetector = new DefaultScanbotBarcodeDetector();
|
|
101
|
-
this.frameHandler = BarcodeDetectorFrameHandler.attach(cameraView, barcodeDetector);
|
|
102
|
-
this.frameHandler.setDetectionInterval(0);
|
|
103
|
-
this.frameHandler.addResultHandler(this);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// Barcode Detector Frame Handler - Result Handler
|
|
107
|
-
@Override
|
|
108
|
-
public boolean handle(@NonNull FrameHandlerResult<? extends BarcodeScanningResult, ? extends SdkLicenseError> result) {
|
|
109
|
-
if (result instanceof FrameHandlerResult.Success) {
|
|
110
|
-
//noinspection unchecked
|
|
111
|
-
handleBarcodeScanningResult((FrameHandlerResult.Success<BarcodeScanningResult>) result);
|
|
112
|
-
}
|
|
113
|
-
return false;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
private void handleBarcodeScanningResult(final FrameHandlerResult.Success<BarcodeScanningResult> result) {
|
|
117
|
-
if (result.getValue() == null) {
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
sendResultToJS(result.getValue());
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
/*---------------------------*
|
|
125
|
-
* Communication
|
|
126
|
-
---------------------------*/
|
|
127
|
-
private void initCommunication() {
|
|
128
|
-
this.eventEmitter = new ScanbotEventEmitter(getReactContext(), this);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
private void sendResultToJS(final BarcodeScanningResult result) {
|
|
132
|
-
if (result == null || result.getBarcodeItems().size() == 0) {
|
|
133
|
-
return;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
try {
|
|
137
|
-
String resultAsJson = SBWrapper.getGson().toJson(SBWrapperBarcodeScannerResult.fromNativeBarcodeResult(result));
|
|
138
|
-
|
|
139
|
-
WritableMap data = new WritableNativeMap();
|
|
140
|
-
data.putMap("result", JSONUtils.jsonToWritableMap(new JSONObject(resultAsJson)));
|
|
141
|
-
|
|
142
|
-
eventEmitter.emitEvent(NativeEvents.BARCODE_SCANNER_RESULT, data);
|
|
143
|
-
} catch (Exception ignored) {
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
/*---------------------------*
|
|
148
|
-
* Configuration
|
|
149
|
-
---------------------------*/
|
|
150
|
-
public void applyConfiguration(@NonNull final ReadableMap jsonConfig) {
|
|
151
|
-
this.configuration = SBWrapper.getGson().fromJson(JSONUtils.readableMapToJson(jsonConfig).toString(), SBWrapperBarcodeCameraViewConfiguration.class);
|
|
152
|
-
refreshConfiguration();
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
public void refreshConfiguration() {
|
|
156
|
-
getReactContext().runOnUiQueueThread(() -> {
|
|
157
|
-
|
|
158
|
-
// Finder Overlay View
|
|
159
|
-
finderOverlayView.setOverlayColor(colorWithAlpha(
|
|
160
|
-
configuration.getFinderBackgroundColorAsInt(),
|
|
161
|
-
configuration.getFinderBackgroundOpacity()
|
|
162
|
-
));
|
|
163
|
-
|
|
164
|
-
finderOverlayView.setVisibility(configuration.getShouldUseFinderView() ? View.VISIBLE : View.INVISIBLE);
|
|
165
|
-
if (configuration.getFinderLineWidth() != -1) {
|
|
166
|
-
finderOverlayView.setStrokeWidth(configuration.getFinderLineWidth());
|
|
167
|
-
}
|
|
168
|
-
finderOverlayView.setStrokeColor(configuration.getFinderLineColorAsInt());
|
|
169
|
-
|
|
170
|
-
if (configuration.getFinderInset() != null && !configuration.getFinderInset().isEmpty()) {
|
|
171
|
-
finderOverlayView.setFinderInset(
|
|
172
|
-
ScanbotViewUtils.convertDpToPx(getResources(), configuration.getFinderInset().left),
|
|
173
|
-
ScanbotViewUtils.convertDpToPx(getResources(), configuration.getFinderInset().top),
|
|
174
|
-
ScanbotViewUtils.convertDpToPx(getResources(), configuration.getFinderInset().right),
|
|
175
|
-
ScanbotViewUtils.convertDpToPx(getResources(), configuration.getFinderInset().bottom));
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
finderOverlayView.setRequiredAspectRatios(Collections.singletonList(configuration.getFinderAspectRatio()));
|
|
179
|
-
finderOverlayView.requestLayout();
|
|
180
|
-
|
|
181
|
-
cameraView.setCameraOpenCallback(() -> cameraView.useFlash(configuration.getFlashEnabled()));
|
|
182
|
-
// Camera View
|
|
183
|
-
cameraView.useFlash(configuration.getFlashEnabled());
|
|
184
|
-
|
|
185
|
-
if (shouldSetCameraZoomFactor(configuration)) {
|
|
186
|
-
cameraView.setPhysicalZoom(configuration.getCameraZoomFactor());
|
|
187
|
-
userDefinedCameraZoomFactor = configuration.getCameraZoomFactor();
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
barcodeDetector.modifyConfig(b -> {
|
|
191
|
-
if (!configuration.getBarcodeFormats().isEmpty()) {
|
|
192
|
-
b.setBarcodeFormats(configuration.getBarcodeFormats());
|
|
193
|
-
}
|
|
194
|
-
if (!configuration.getAcceptedDocumentFormats().isEmpty()) {
|
|
195
|
-
b.setAcceptedDocumentFormats(configuration.getAcceptedDocumentFormats());
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
b.setEngineMode(configuration.getEngineMode());
|
|
199
|
-
b.modifyAdditionalConfig(ab -> {
|
|
200
|
-
if (configuration.getMinimumTextLength() != -1) {
|
|
201
|
-
ab.setMinimumTextLength(configuration.getMinimumTextLength());
|
|
202
|
-
}
|
|
203
|
-
if (configuration.getMaximumTextLength() != -1) {
|
|
204
|
-
ab.setMaximumTextLength(configuration.getMaximumTextLength());
|
|
205
|
-
}
|
|
206
|
-
ab.setMsiPlesseyChecksumAlgorithms(configuration.getMsiPlesseyChecksumAlgorithms());
|
|
207
|
-
ab.setStripCheckDigits(configuration.getStripCheckDigits());
|
|
208
|
-
ab.setGs1HandlingMode(configuration.getGs1HandlingMode());
|
|
209
|
-
if (configuration.getMinimum1DBarcodesQuietZone() != -1) {
|
|
210
|
-
ab.setMinimum1DQuietZoneSize(configuration.getMinimum1DBarcodesQuietZone());
|
|
211
|
-
}
|
|
212
|
-
ab.setLowPowerMode(configuration.getLowPowerMode());
|
|
213
|
-
ab.setCodeDensity(configuration.getCodeDensity());
|
|
214
|
-
|
|
215
|
-
return Unit.INSTANCE;
|
|
216
|
-
});
|
|
217
|
-
return Unit.INSTANCE;
|
|
218
|
-
});
|
|
219
|
-
|
|
220
|
-
if (frameHandler != null) {
|
|
221
|
-
frameHandler.setEnabled(configuration.getScanningEnabled());
|
|
222
|
-
|
|
223
|
-
switch (configuration.getBarcodesExtensionFilter()) {
|
|
224
|
-
case ONLY_WITH_EXTENSIONS:
|
|
225
|
-
frameHandler.setBarcodeFilter(new BarcodeExtensionsFilter());
|
|
226
|
-
break;
|
|
227
|
-
case ONLY_WITHOUT_EXTENSIONS:
|
|
228
|
-
frameHandler.setBarcodeFilter(new BarcodeEanUpcNoExtensionsFilter());
|
|
229
|
-
break;
|
|
230
|
-
default:
|
|
231
|
-
frameHandler.setBarcodeFilter(null);
|
|
232
|
-
break;
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
});
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
private boolean shouldSetCameraZoomFactor(final SBWrapperBarcodeCameraViewConfiguration config) {
|
|
239
|
-
return config.getCameraZoomFactor() != -1 && config.getCameraZoomFactor() != userDefinedCameraZoomFactor;
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
/*---------------------------*
|
|
243
|
-
* Views Creation
|
|
244
|
-
---------------------------*/
|
|
245
|
-
private void createViews() {
|
|
246
|
-
final Context context = getReactContext().getCurrentActivity();
|
|
247
|
-
|
|
248
|
-
cameraView = createScanbotCameraView(context);
|
|
249
|
-
finderOverlayView = createFinderOverlayView(context);
|
|
250
|
-
childrenContainerView = createChildrenContainerView(context);
|
|
251
|
-
|
|
252
|
-
addView(cameraView);
|
|
253
|
-
addView(finderOverlayView);
|
|
254
|
-
addView(childrenContainerView);
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
private ViewGroup createChildrenContainerView(final Context context) {
|
|
258
|
-
final ReactViewGroup containerView = new ReactViewGroup(context);
|
|
259
|
-
|
|
260
|
-
containerView.setLayoutParams(new LayoutParams(MATCH_PARENT, MATCH_PARENT));
|
|
261
|
-
containerView.setZ(2.0f);
|
|
262
|
-
|
|
263
|
-
return containerView;
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
private FinderOverlayView createFinderOverlayView(final Context context) {
|
|
267
|
-
final FinderOverlayView finderView = new FinderOverlayView(context, null);
|
|
268
|
-
|
|
269
|
-
finderView.setLayoutParams(new LayoutParams(MATCH_PARENT, MATCH_PARENT));
|
|
270
|
-
finderView.setId(io.scanbot.sdk.barcode.R.id.finder_overlay);
|
|
271
|
-
|
|
272
|
-
ScanbotViewUtils.installHierarchyFitter(finderView);
|
|
273
|
-
|
|
274
|
-
return finderView;
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
private ScanbotCameraXView createScanbotCameraView(final Context context) {
|
|
278
|
-
final ScanbotCameraXView cameraView = new ScanbotCameraXView(context);
|
|
279
|
-
|
|
280
|
-
cameraView.setLifecycleOwner(getLifecycleOwner());
|
|
281
|
-
cameraView.setLayoutParams(new LayoutParams(MATCH_PARENT, MATCH_PARENT));
|
|
282
|
-
cameraView.setBackgroundColor(Color.BLACK);
|
|
283
|
-
cameraView.setCameraOpenCallback(cameraView::continuousFocus);
|
|
284
|
-
cameraView.post(this::checkPermissions);
|
|
285
|
-
|
|
286
|
-
applyWorkaroundForReactNativeIssue17968(cameraView);
|
|
287
|
-
|
|
288
|
-
return cameraView;
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
/*---------------------------*
|
|
292
|
-
* View Lifecycle Handling
|
|
293
|
-
---------------------------*/
|
|
294
|
-
@Override
|
|
295
|
-
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
|
|
296
|
-
super.onLayout(changed, left, top, right, bottom);
|
|
297
|
-
remeasureCameraFrame();
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
/*---------------------------*
|
|
301
|
-
* React Views Handling
|
|
302
|
-
---------------------------*/
|
|
303
|
-
@Override
|
|
304
|
-
public void addView(View child, int index, ViewGroup.LayoutParams params) {
|
|
305
|
-
if (isReactChildView(child)) {
|
|
306
|
-
addReactChildView(child);
|
|
307
|
-
} else {
|
|
308
|
-
super.addView(child, index, params);
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
/**
|
|
313
|
-
* WORKAROUND FOR ISSUE: react child views are not measured / positioned correctly
|
|
314
|
-
*/
|
|
315
|
-
private void addReactChildView(final View child) {
|
|
316
|
-
// If the child has a parent, we take it away ¯\_(ツ)_/¯
|
|
317
|
-
if (child.getParent() instanceof ViewGroup) {
|
|
318
|
-
((ViewGroup) child.getParent()).removeView(child);
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
final View view = ScanbotViewWrapper.wrap(child);
|
|
322
|
-
childrenContainerView.addView(view);
|
|
323
|
-
childrenContainerView.invalidate();
|
|
324
|
-
childrenContainerView.requestLayout();
|
|
325
|
-
|
|
326
|
-
view.invalidate();
|
|
327
|
-
view.requestLayout();
|
|
328
|
-
|
|
329
|
-
childrenContainerView.bringToFront();
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
private boolean isReactChildView(final View child) {
|
|
333
|
-
return child != cameraView && child != finderOverlayView && child != childrenContainerView;
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
/*---------------------------*
|
|
337
|
-
* Camera Related
|
|
338
|
-
---------------------------*/
|
|
339
|
-
|
|
340
|
-
/**
|
|
341
|
-
* WORKAROUND FOR ISSUE: camera frame size is not auto-calculated correctly
|
|
342
|
-
*/
|
|
343
|
-
private void remeasureCameraFrame() {
|
|
344
|
-
cameraView.setCameraFrameSize(new Size(this.getWidth(), this.getHeight()));
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
/*---------------------------*
|
|
348
|
-
* Utils and overrides
|
|
349
|
-
---------------------------*/
|
|
350
|
-
|
|
351
|
-
/**
|
|
352
|
-
* WORKAROUND for React Native
|
|
353
|
-
* <a href="https://github.com/facebook/react-native/issues/17968">ISSUE #17968</a>
|
|
354
|
-
* Android native UI components are not re-layout on dynamically added views
|
|
355
|
-
*
|
|
356
|
-
* @param cameraView - The view that CONTAINS a PreviewView
|
|
357
|
-
*/
|
|
358
|
-
private void applyWorkaroundForReactNativeIssue17968(final ViewGroup cameraView) {
|
|
359
|
-
ScanbotViewUtils.installHierarchyFitter(cameraView);
|
|
360
|
-
ScanbotViewUtils.installHierarchyFitter(cameraView.findViewById(io.scanbot.sdk.barcode.R.id.camera_preview_view));
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
public static NativeEvents[] getNativeEvents() {
|
|
364
|
-
return NativeEvents.values();
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
private ReactContext getReactContext() {
|
|
368
|
-
final Context context = getContext();
|
|
369
|
-
if (context instanceof ReactContext) {
|
|
370
|
-
return (ReactContext) context;
|
|
371
|
-
}
|
|
372
|
-
throw new TypeCastException("Context is not of type ReactContext");
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
private LifecycleOwner getLifecycleOwner() {
|
|
376
|
-
final Activity activity = getReactContext().getCurrentActivity();
|
|
377
|
-
if (activity instanceof LifecycleOwner) {
|
|
378
|
-
return (LifecycleOwner) activity;
|
|
379
|
-
}
|
|
380
|
-
throw new TypeCastException("Activity is not of type LifecycleOwner");
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
private void checkPermissions() {
|
|
384
|
-
final Activity activity = this.getReactContext().getCurrentActivity();
|
|
385
|
-
if (activity == null) {
|
|
386
|
-
return;
|
|
387
|
-
}
|
|
388
|
-
final int cameraPermission = ContextCompat.checkSelfPermission(
|
|
389
|
-
activity,
|
|
390
|
-
Manifest.permission.CAMERA
|
|
391
|
-
);
|
|
392
|
-
|
|
393
|
-
if (cameraPermission != PackageManager.PERMISSION_GRANTED) {
|
|
394
|
-
ActivityCompat.requestPermissions(
|
|
395
|
-
activity,
|
|
396
|
-
new String[]{Manifest.permission.CAMERA},
|
|
397
|
-
REQUEST_PERMISSION_CODE
|
|
398
|
-
);
|
|
399
|
-
}
|
|
400
|
-
}
|
|
401
|
-
}
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
package io.scanbot.barcodesdk.plugin.reactnative.components.base.communication;
|
|
2
|
-
|
|
3
|
-
import android.view.ViewGroup;
|
|
4
|
-
|
|
5
|
-
import com.facebook.react.bridge.ReactContext;
|
|
6
|
-
import com.facebook.react.bridge.WritableMap;
|
|
7
|
-
import com.facebook.react.common.MapBuilder;
|
|
8
|
-
import com.facebook.react.uimanager.events.RCTEventEmitter;
|
|
9
|
-
|
|
10
|
-
import java.util.Map;
|
|
11
|
-
|
|
12
|
-
public class ScanbotEventEmitter {
|
|
13
|
-
|
|
14
|
-
public interface NativeEvent {
|
|
15
|
-
String getName();
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
public enum CommonEvents implements NativeEvent {
|
|
19
|
-
// TODO: requestComponentReload is not currently implemented
|
|
20
|
-
REQUEST_COMPONENT_RELOAD("requestComponentReload");
|
|
21
|
-
|
|
22
|
-
private final String name;
|
|
23
|
-
CommonEvents(final String name) {
|
|
24
|
-
this.name = name;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
public String getName() {
|
|
28
|
-
return name;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
private final RCTEventEmitter jsEventEmitter;
|
|
33
|
-
private final ReactContext reactContext;
|
|
34
|
-
private final ViewGroup rootViewGroup;
|
|
35
|
-
|
|
36
|
-
public ScanbotEventEmitter(final ReactContext reactContext, final ViewGroup rootViewGroup) {
|
|
37
|
-
this.reactContext = reactContext;
|
|
38
|
-
this.jsEventEmitter = reactContext.getJSModule(RCTEventEmitter.class);
|
|
39
|
-
this.rootViewGroup = rootViewGroup;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
public void emitEvent(final NativeEvent event, final WritableMap data) {
|
|
43
|
-
assert reactContext != null;
|
|
44
|
-
jsEventEmitter.receiveEvent(
|
|
45
|
-
rootViewGroup.getId(),
|
|
46
|
-
event.getName(),
|
|
47
|
-
data
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
public static Map<String, Object> getMapForNativeEvents(NativeEvent[] events) {
|
|
52
|
-
MapBuilder.Builder<String, Object> builder = MapBuilder.builder();
|
|
53
|
-
|
|
54
|
-
for (NativeEvent event: events) {
|
|
55
|
-
builder.put(event.getName(), MapBuilder.of("registrationName", event.getName()));
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
return builder.build();
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
public static NativeEvent[] concatEvents(
|
|
62
|
-
NativeEvent[] arr1,
|
|
63
|
-
NativeEvent[] arr2
|
|
64
|
-
) {
|
|
65
|
-
final int len1 = arr1.length;
|
|
66
|
-
final int len2 = arr2.length;
|
|
67
|
-
final int min = Math.min(len1, len2);
|
|
68
|
-
final int max = Math.max(len1, len2);
|
|
69
|
-
final NativeEvent[] out = new NativeEvent[len1 + len2];
|
|
70
|
-
|
|
71
|
-
for (int i = 0; i<max; ++i) {
|
|
72
|
-
out[i] = len2 > len1 ? arr2[i] : arr1[i];
|
|
73
|
-
if (i < min) { out[i+max] = len2 > len1 ? arr1[i] : arr2[i]; }
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
return out;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
package io.scanbot.barcodesdk.plugin.reactnative.components.base.communication;
|
|
2
|
-
|
|
3
|
-
import androidx.annotation.NonNull;
|
|
4
|
-
import androidx.annotation.Nullable;
|
|
5
|
-
|
|
6
|
-
import com.facebook.react.bridge.ReadableArray;
|
|
7
|
-
|
|
8
|
-
import java.util.HashMap;
|
|
9
|
-
import java.util.Map;
|
|
10
|
-
|
|
11
|
-
public class ScanbotEventReceiver {
|
|
12
|
-
|
|
13
|
-
public interface JavaScriptEvent {
|
|
14
|
-
String getName();
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
public enum CommonEvents implements JavaScriptEvent {
|
|
18
|
-
COMPONENT_DID_UPDATE("componentDidUpdate"),
|
|
19
|
-
COMPONENT_DID_MOUNT("componentDidMount"),
|
|
20
|
-
COMPONENT_WILL_UNMOUNT("componentWillUnmount"),
|
|
21
|
-
ORIENTATION_CHANGED("orientationChanged");
|
|
22
|
-
|
|
23
|
-
private final String name;
|
|
24
|
-
CommonEvents(final String name) {
|
|
25
|
-
this.name = name;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
@Override
|
|
29
|
-
public String getName() {
|
|
30
|
-
return name;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
public interface IEventHandler {
|
|
35
|
-
void eventHandler_eventReceived(final JavaScriptEvent event, @Nullable final ReadableArray args);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
private final IEventHandler handler;
|
|
39
|
-
private final JavaScriptEvent[] events;
|
|
40
|
-
private final HashMap<Integer, String> eventsMap = new HashMap<>();
|
|
41
|
-
|
|
42
|
-
public ScanbotEventReceiver(@NonNull final IEventHandler handler, @NonNull final JavaScriptEvent[] events) {
|
|
43
|
-
this.handler = handler;
|
|
44
|
-
this.events = concatEvents(CommonEvents.values(), events);
|
|
45
|
-
prepare();
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
public void receiveCommand(@NonNull final String commandId, @Nullable final ReadableArray args) {
|
|
49
|
-
try {
|
|
50
|
-
// Legacy implementation uses integers for command identifiers
|
|
51
|
-
int commandIdInt = Integer.parseInt(commandId);
|
|
52
|
-
if (!eventsMap.containsKey(commandIdInt)) {
|
|
53
|
-
return; // Command not handled
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
final String eventName = eventsMap.get(commandIdInt);
|
|
57
|
-
handleReceivedCommandFromEventName(eventName, args);
|
|
58
|
-
} catch(NumberFormatException ignored) {
|
|
59
|
-
// New Architecture implementation uses strings for command identifiers
|
|
60
|
-
handleReceivedCommandFromEventName(commandId, args);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
private void handleReceivedCommandFromEventName(final String eventName, @Nullable final ReadableArray args) {
|
|
65
|
-
assert eventName != null;
|
|
66
|
-
final JavaScriptEvent event = getEventFromName(eventName);
|
|
67
|
-
handler.eventHandler_eventReceived(event, args);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
public Map<String, Integer> getCommandsMap() {
|
|
71
|
-
final HashMap<String, Integer> out = new HashMap<>();
|
|
72
|
-
for (final Integer key: eventsMap.keySet()) {
|
|
73
|
-
out.put(eventsMap.get(key), key);
|
|
74
|
-
}
|
|
75
|
-
return out;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
private void prepare() {
|
|
79
|
-
int commandId = 1;
|
|
80
|
-
for(final JavaScriptEvent event: this.events) {
|
|
81
|
-
this.eventsMap.put(commandId++, event.getName());
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
public JavaScriptEvent getEventFromName(@NonNull final String name) {
|
|
86
|
-
for (JavaScriptEvent event: events) {
|
|
87
|
-
if (event.getName().equals(name)) {
|
|
88
|
-
return event;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
return null;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
public CommonEvents getCommonEventFromName(@NonNull final String name) {
|
|
95
|
-
final JavaScriptEvent event = getEventFromName(name);
|
|
96
|
-
if (!(event instanceof CommonEvents)) {
|
|
97
|
-
return null;
|
|
98
|
-
}
|
|
99
|
-
return (CommonEvents) event;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
public static JavaScriptEvent[] concatEvents(
|
|
103
|
-
JavaScriptEvent[] arr1,
|
|
104
|
-
JavaScriptEvent[] arr2
|
|
105
|
-
) {
|
|
106
|
-
final int len1 = arr1.length;
|
|
107
|
-
final int len2 = arr2.length;
|
|
108
|
-
final int min = Math.min(len1, len2);
|
|
109
|
-
final int max = Math.max(len1, len2);
|
|
110
|
-
final JavaScriptEvent[] out = new JavaScriptEvent[len1 + len2];
|
|
111
|
-
|
|
112
|
-
for (int i = 0; i<max; ++i) {
|
|
113
|
-
out[i] = len2 > len1 ? arr2[i] : arr1[i];
|
|
114
|
-
if (i < min) { out[i+max] = len2 > len1 ? arr1[i] : arr2[i]; }
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
return out;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,24 +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
|
-
package io.scanbot.barcodesdk.plugin.reactnative.utils
|
|
7
|
-
|
|
8
|
-
import com.facebook.react.bridge.ReadableMap
|
|
9
|
-
import io.scanbot.barcodesdk.plugin.reactnative.extensions.toJSON
|
|
10
|
-
import io.scanbot.barcodesdk.plugin.reactnative.extensions.toWritableMap
|
|
11
|
-
import org.json.JSONObject
|
|
12
|
-
|
|
13
|
-
object JSONUtils {
|
|
14
|
-
|
|
15
|
-
@JvmStatic
|
|
16
|
-
fun jsonToWritableMap(jsonObject: JSONObject): ReadableMap {
|
|
17
|
-
return jsonObject.toWritableMap()
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
@JvmStatic
|
|
21
|
-
fun readableMapToJson(readableMap: ReadableMap): JSONObject {
|
|
22
|
-
return readableMap.toJSON()
|
|
23
|
-
}
|
|
24
|
-
}
|
package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/utils/ScanbotViewUtils.java
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
package io.scanbot.barcodesdk.plugin.reactnative.utils;
|
|
2
|
-
|
|
3
|
-
import android.content.res.Resources;
|
|
4
|
-
import android.graphics.Color;
|
|
5
|
-
import android.view.View;
|
|
6
|
-
import android.view.ViewGroup;
|
|
7
|
-
|
|
8
|
-
import androidx.annotation.ColorInt;
|
|
9
|
-
|
|
10
|
-
public class ScanbotViewUtils {
|
|
11
|
-
public static void installHierarchyFitter(final ViewGroup viewGroup) {
|
|
12
|
-
viewGroup.setOnHierarchyChangeListener(new ViewGroup.OnHierarchyChangeListener() {
|
|
13
|
-
@Override
|
|
14
|
-
public void onChildViewAdded(View parent, View child) {
|
|
15
|
-
if (parent == null) { return; }
|
|
16
|
-
parent.measure(
|
|
17
|
-
View.MeasureSpec.makeMeasureSpec(viewGroup.getMeasuredWidth(), View.MeasureSpec.EXACTLY),
|
|
18
|
-
View.MeasureSpec.makeMeasureSpec(viewGroup.getMeasuredHeight(), View.MeasureSpec.EXACTLY)
|
|
19
|
-
);
|
|
20
|
-
parent.layout(0, 0, parent.getMeasuredWidth(), parent.getMeasuredHeight());
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
@Override
|
|
24
|
-
public void onChildViewRemoved(View parent, View child) {}
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
@ColorInt
|
|
28
|
-
public static int colorWithAlpha(@ColorInt int color, float factor) {
|
|
29
|
-
int alpha = Math.round(Color.alpha(color) * factor);
|
|
30
|
-
int red = Color.red(color);
|
|
31
|
-
int green = Color.green(color);
|
|
32
|
-
int blue = Color.blue(color);
|
|
33
|
-
return Color.argb(alpha, red, green, blue);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
public static int convertDpToPx(Resources resources, int dp) {
|
|
37
|
-
return (int) Math.floor(dp * resources.getDisplayMetrics().density);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
public static int convertDpToPx(Resources resources, float dp) {
|
|
41
|
-
return (int) Math.floor(dp * resources.getDisplayMetrics().density);
|
|
42
|
-
}
|
|
43
|
-
}
|