react-native-scanbot-barcode-scanner-sdk 3.2.1-beta6 → 3.2.1-beta9

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 (37) hide show
  1. package/android/.project +6 -0
  2. package/android/build.gradle +2 -2
  3. package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  4. package/android/gradle/wrapper/gradle-wrapper.properties +5 -0
  5. package/android/gradlew +185 -0
  6. package/android/gradlew.bat +89 -0
  7. package/android/src/main/java/com/reactlibrary/ScanbotBarcodeSdkPackage.java +17 -4
  8. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/ObjectMapper.java +6 -0
  9. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/ScanbotBarcodeSdkPackage.java +15 -5
  10. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/barcodecameraview/RNScanbotBarcodeCameraComponent.java +292 -0
  11. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/barcodecameraview/{ScanbotBarcodeCameraViewConfiguration.java → RNScanbotBarcodeCameraConfiguration.java} +54 -4
  12. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/barcodecameraview/RNScanbotBarcodeCameraUi.java +81 -0
  13. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/base/RNScanbotNativeComponent.java +90 -0
  14. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/base/RNScanbotNativeComponentManager.java +133 -0
  15. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/base/RNScanbotNativeComponentManagerFactory.java +40 -0
  16. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/base/RNScanbotNativeComponentUi.java +131 -0
  17. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/{EventEmitter.java → base/communication/RNScanbotEventEmitter.java} +27 -6
  18. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/base/communication/RNScanbotEventReceiver.java +108 -0
  19. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/{common/ScanbotComponentFrameLayout.java → base/views/RNScanbotNativeComponentFrameLayout.java} +4 -4
  20. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/{common/ScanbotComponentRootView.java → base/views/RNScanbotNativeComponentRootView.java} +43 -48
  21. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/utils/JSONUtils.java +25 -14
  22. package/android/src/main/res/layout/component_barcode_camera_view.xml +22 -5
  23. package/index.d.ts +7 -3
  24. package/ios/Components/BarcodeCameraView/RNScanbotBarcodeCameraView.h +7 -1
  25. package/ios/Components/BarcodeCameraView/RNScanbotBarcodeCameraView.m +18 -2
  26. package/ios/Components/BarcodeCameraView/RNScanbotBarcodeCameraViewManager.h +6 -0
  27. package/ios/Components/BarcodeCameraView/RNScanbotBarcodeCameraViewManager.m +41 -0
  28. package/ios/Utils/BarcodeMapping.h +3 -1
  29. package/package.json +1 -1
  30. package/src/components/barcode-camera-view/scanbot-barcode-camera-view-types.tsx +6 -0
  31. package/src/components/barcode-camera-view/scanbot-barcode-camera-view.tsx +42 -5
  32. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/BitmapHelper.java +0 -28
  33. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/JSONUtils.java +0 -272
  34. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/LogUtils.java +0 -40
  35. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/ResponseUtils.java +0 -41
  36. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/barcodecameraview/ScanbotBarcodeCameraViewFragment.java +0 -255
  37. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/barcodecameraview/ScanbotBarcodeCameraViewManager.java +0 -160
@@ -1,41 +0,0 @@
1
- /*
2
- Scanbot Barcode Scanner SDK React Native Plugin
3
- Copyright (c) 2020 doo GmbH. All rights reserved.
4
- https://scanbot.io/sdk
5
- */
6
- package io.scanbot.barcodesdk.plugin.reactnative;
7
-
8
- import android.view.View;
9
-
10
- import com.facebook.react.bridge.Arguments;
11
- import com.facebook.react.bridge.Promise;
12
- import com.facebook.react.bridge.ReactContext;
13
- import com.facebook.react.bridge.WritableMap;
14
- import com.facebook.react.uimanager.events.RCTEventEmitter;
15
-
16
- public class ResponseUtils {
17
-
18
- public static void successMessageJson(final String msg, final Promise promise) {
19
- final WritableMap response = Arguments.createMap();
20
- response.putString("status", "OK");
21
- response.putString("message", msg);
22
- promise.resolve(response);
23
- }
24
-
25
- public static void successCanceled(final Promise promise) {
26
- final WritableMap response = Arguments.createMap();
27
- response.putString("status", "CANCELED");
28
- promise.resolve(response);
29
- }
30
-
31
- public static void errorMessageJson(final String msg, final Promise promise) {
32
- final WritableMap response = Arguments.createMap();
33
- response.putString("error", msg);
34
- promise.reject(msg);
35
- }
36
-
37
- public static void sendReactEvent(String eventName, WritableMap event, View view) {
38
- final ReactContext reactContext = (ReactContext)view.getContext();
39
- reactContext.getJSModule(RCTEventEmitter.class).receiveEvent(view.getId(), eventName, event);
40
- }
41
- }
@@ -1,255 +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.os.Bundle;
8
- import android.view.View;
9
- import android.view.ViewGroup;
10
-
11
- import androidx.annotation.ColorInt;
12
- import androidx.annotation.NonNull;
13
- import androidx.annotation.Nullable;
14
- import androidx.core.app.ActivityCompat;
15
- import androidx.core.content.ContextCompat;
16
- import androidx.fragment.app.Fragment;
17
-
18
- import com.facebook.react.bridge.ReactContext;
19
- import com.facebook.react.bridge.WritableArray;
20
- import com.facebook.react.bridge.WritableMap;
21
- import com.facebook.react.bridge.WritableNativeArray;
22
-
23
- import org.jetbrains.annotations.NotNull;
24
-
25
- import java.util.Collections;
26
- import java.util.List;
27
-
28
- import io.scanbot.barcodesdk.plugin.reactnative.barcode.ScanbotBarcodeDetectorConfigBuilder;
29
- import io.scanbot.barcodesdk.plugin.reactnative.utils.JSONUtils;
30
- import io.scanbot.barcodesdk.plugin.reactnative.R;
31
- import io.scanbot.barcodesdk.plugin.reactnative.components.EventEmitter;
32
- import io.scanbot.barcodesdk.plugin.reactnative.components.common.ScanbotComponentFrameLayout;
33
- import io.scanbot.sdk.SdkLicenseError;
34
- import io.scanbot.sdk.barcode.BarcodeDetectorFrameHandler;
35
- import io.scanbot.sdk.barcode.DefaultScanbotBarcodeDetector;
36
- import io.scanbot.sdk.barcode.ScanbotBarcodeDetector;
37
- import io.scanbot.sdk.barcode.entity.BarcodeItem;
38
- import io.scanbot.sdk.barcode.entity.BarcodeScannerAdditionalConfig;
39
- import io.scanbot.sdk.barcode.entity.BarcodeScannerAdditionalConfigBuilder;
40
- import io.scanbot.sdk.barcode.entity.BarcodeScannerConfigBuilder;
41
- import io.scanbot.sdk.barcode.entity.BarcodeScanningResult;
42
- import io.scanbot.sdk.camera.CameraOpenCallback;
43
- import io.scanbot.sdk.camera.FrameHandlerResult;
44
- import io.scanbot.sdk.camera.ScanbotCameraView;
45
- import io.scanbot.sdk.ui.camera.FinderOverlayView;
46
- import kotlin.Unit;
47
- import kotlin.jvm.functions.Function1;
48
-
49
- public class ScanbotBarcodeCameraViewFragment extends Fragment implements BarcodeDetectorFrameHandler.ResultHandler {
50
-
51
- private static final int REQUEST_PERMISSION_CODE = 200;
52
-
53
- private ReactContext callerContext;
54
- private ViewGroup rootViewGroup;
55
- private ScanbotComponentFrameLayout cameraLayout;
56
- private ScanbotCameraView cameraView;
57
- private FinderOverlayView finderOverlayView;
58
- private ScanbotBarcodeDetector barcodeDetector;
59
- private BarcodeDetectorFrameHandler frameHandler;
60
- private ScanbotBarcodeCameraViewConfiguration configuration = new ScanbotBarcodeCameraViewConfiguration();
61
- private boolean isInitialized = false;
62
- private EventEmitter jsEventEmitter;
63
- private float userDefinedCameraZoomFactor = -1;
64
-
65
- public ScanbotBarcodeCameraViewFragment() {
66
- super(R.layout.fragment_barcode_scanner);
67
- }
68
-
69
- public void instantiate(final ReactContext reactContext, final ViewGroup rootViewGroup) {
70
- this.callerContext = reactContext;
71
- this.rootViewGroup = rootViewGroup;
72
- jsEventEmitter = new EventEmitter(reactContext, rootViewGroup);
73
- }
74
-
75
- @Override
76
- public void onViewCreated(@NonNull final View view, @Nullable Bundle savedInstanceState) {
77
- super.onViewCreated(view, savedInstanceState);
78
-
79
- final Activity activity = getActivity();
80
- final View rootView = getView();
81
- assert activity != null;
82
- assert rootView != null;
83
-
84
- cameraLayout = rootView.findViewById(R.id.barcode_camera_layout);
85
- cameraView = rootView.findViewById(R.id.barcode_camera);
86
- finderOverlayView = rootView.findViewById(R.id.barcode_finder_overlay);
87
-
88
- cameraView.post(new Runnable() {
89
- @Override
90
- public void run() {
91
- checkPermissions();
92
- }
93
- });
94
-
95
- cameraView.onResume();
96
-
97
- // Setup Frame Handler for Barcode Detection
98
- barcodeDetector = new DefaultScanbotBarcodeDetector();
99
-
100
- frameHandler = BarcodeDetectorFrameHandler.attach(cameraView, barcodeDetector);
101
- frameHandler.setDetectionInterval(0);
102
- frameHandler.addResultHandler(this);
103
-
104
- cameraView.addFrameHandler(frameHandler);
105
-
106
- cameraView.setCameraOpenCallback(new CameraOpenCallback() {
107
- @Override
108
- public void onCameraOpened() {
109
- cameraView.continuousFocus();
110
- }
111
- });
112
-
113
- applyConfiguration();
114
-
115
- isInitialized = true;
116
- }
117
-
118
- private void applyConfiguration() {
119
- finderOverlayView.setVisibility(configuration.shouldUseFinderView() ? View.VISIBLE : View.INVISIBLE);
120
- finderOverlayView.setStrokeWidth(configuration.getFinderLineWidth());
121
- finderOverlayView.setStrokeColor(configuration.getFinderLineColor());
122
- finderOverlayView.setOverlayColor(colorWithAlpha(
123
- configuration.getFinderBackgroundColor(),
124
- configuration.getFinderBackgroundOpacity()));
125
- finderOverlayView.setMinFinderPadding(configuration.getFinderMinimumPadding());
126
- finderOverlayView.setVerticalOffset(configuration.getFinderVerticalOffset());
127
- finderOverlayView.setRequiredAspectRatios(Collections.singletonList(configuration.getFinderAspectRatio()));
128
-
129
- cameraView.useFlash(configuration.isFlashEnabled());
130
-
131
- if (configuration.getCameraZoomFactor() != -1) {
132
- if (configuration.getCameraZoomFactor() != userDefinedCameraZoomFactor || userDefinedCameraZoomFactor == -1) {
133
- cameraView.setOpticalZoomLevel(configuration.getCameraZoomFactor());
134
- userDefinedCameraZoomFactor = configuration.getCameraZoomFactor();
135
- }
136
- }
137
- barcodeDetector.modifyConfig(b -> {
138
- if(!configuration.barcodeFormats.isEmpty()) {
139
- b.setBarcodeFormats(configuration.barcodeFormats);
140
- }
141
- if(!configuration.acceptedDocumentFormats.isEmpty()) {
142
- b.setAcceptedDocumentFormats(configuration.acceptedDocumentFormats);
143
- }
144
- b.setEngineMode(configuration.engineMode);
145
-
146
- if(configuration.additionalConfiguration != null) {
147
- b.modifyAdditionalConfig(ab -> {
148
- final BarcodeScannerAdditionalConfig config = configuration.additionalConfiguration;
149
- ab.setMinimumTextLength(config.getMinimumTextLength());
150
- ab.setMaximumTextLength(config.getMaximumTextLength());
151
- ab.setMsiPlesseyChecksumAlgorithms(config.getMsiPlesseyChecksumAlgorithms());
152
- ab.setStripCheckDigits(config.getStripCheckDigits());
153
- ab.setGs1DecodingEnabled(config.getGs1DecodingEnabled());
154
- ab.setMinimum1DQuietZoneSize(config.getMinimum1DQuietZoneSize());
155
- return Unit.INSTANCE;
156
- });
157
- }
158
- return Unit.INSTANCE;
159
- });
160
- }
161
-
162
- @Override
163
- public void onStart() {
164
- super.onStart();
165
- if(cameraView != null) {
166
- cameraView.onResume();
167
- }
168
- }
169
-
170
- @Override
171
- public void onResume() {
172
- super.onResume();
173
- if (cameraView != null) {
174
- cameraView.onResume();
175
- }
176
- }
177
-
178
- @Override
179
- public void onPause() {
180
- super.onPause();
181
- if (cameraView != null) {
182
- cameraView.onPause();
183
- }
184
- }
185
-
186
- public void updateWithConfiguration(ScanbotBarcodeCameraViewConfiguration configuration) {
187
- this.configuration = configuration;
188
-
189
- if (isInitialized) {
190
- applyConfiguration();
191
- }
192
- }
193
-
194
- @ColorInt
195
- public static int colorWithAlpha(@ColorInt int color, float factor) {
196
- int alpha = Math.round(Color.alpha(color) * factor);
197
- int red = Color.red(color);
198
- int green = Color.green(color);
199
- int blue = Color.blue(color);
200
- return Color.argb(alpha, red, green, blue);
201
- }
202
-
203
- private void sendResult(final List<BarcodeItem> barcodeItems) {
204
-
205
- if (barcodeItems == null || barcodeItems.size() == 0) {
206
- return;
207
- }
208
-
209
- final WritableArray barcodes = new WritableNativeArray();
210
-
211
- for (BarcodeItem item: barcodeItems) {
212
- final WritableMap barcode = new JSONUtils.WritableMapBuilder()
213
- .putString("text", item.getText())
214
- .putString("type", item.getBarcodeFormat().name())
215
- .build();
216
- barcodes.pushMap(barcode);
217
- }
218
-
219
- final WritableMap result = new JSONUtils.WritableMapBuilder()
220
- .putString("status", "OK")
221
- .putArray("barcodes", barcodes)
222
- .build();
223
-
224
- final WritableMap data = new JSONUtils.WritableMapBuilder()
225
- .putMap("result", result)
226
- .build();
227
-
228
- jsEventEmitter.emitEvent(EventEmitter.NativeEvent.BARCODE_SCANNER_RESULT, data);
229
- }
230
-
231
- @Override
232
- public boolean handle(@NotNull FrameHandlerResult<? extends BarcodeScanningResult, ? extends SdkLicenseError> frameHandlerResult) {
233
- if (frameHandlerResult instanceof FrameHandlerResult.Success) {
234
- handleSuccess((FrameHandlerResult.Success<BarcodeScanningResult>) frameHandlerResult);
235
- }
236
- return false;
237
- }
238
-
239
- private void handleSuccess(final FrameHandlerResult.Success<BarcodeScanningResult> result) {
240
- if (result == null || result.getValue() == null) {
241
- return;
242
- }
243
-
244
- sendResult(result.getValue().getBarcodeItems());
245
- }
246
-
247
- private void checkPermissions() {
248
- if (callerContext == null) { return; }
249
- Activity activity = callerContext.getCurrentActivity();
250
-
251
- if (activity != null && ContextCompat.checkSelfPermission(activity, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
252
- ActivityCompat.requestPermissions(activity, new String[] { Manifest.permission.CAMERA }, REQUEST_PERMISSION_CODE);
253
- }
254
- }
255
- }
@@ -1,160 +0,0 @@
1
- package io.scanbot.barcodesdk.plugin.reactnative.components.barcodecameraview;
2
-
3
- import android.app.Activity;
4
- import android.view.LayoutInflater;
5
- import android.view.View;
6
- import android.widget.FrameLayout;
7
-
8
- import androidx.annotation.NonNull;
9
- import androidx.annotation.Nullable;
10
- import androidx.appcompat.app.AppCompatActivity;
11
- import androidx.fragment.app.FragmentManager;
12
-
13
- import com.facebook.react.ReactRootView;
14
- import com.facebook.react.bridge.ReactApplicationContext;
15
- import com.facebook.react.bridge.ReadableMap;
16
- import com.facebook.react.bridge.WritableNativeMap;
17
- import com.facebook.react.uimanager.ThemedReactContext;
18
- import com.facebook.react.uimanager.ViewGroupManager;
19
- import com.facebook.react.uimanager.annotations.ReactProp;
20
-
21
- import java.util.Map;
22
-
23
- import io.scanbot.barcodesdk.plugin.reactnative.utils.JSONUtils;
24
- import io.scanbot.barcodesdk.plugin.reactnative.ObjectMapper;
25
- import io.scanbot.barcodesdk.plugin.reactnative.R;
26
- import io.scanbot.barcodesdk.plugin.reactnative.components.EventEmitter;
27
- import io.scanbot.barcodesdk.plugin.reactnative.components.common.ScanbotComponentFrameLayout;
28
- import io.scanbot.barcodesdk.plugin.reactnative.components.common.ScanbotComponentRootView;
29
-
30
- public class ScanbotBarcodeCameraViewManager extends ViewGroupManager<ReactRootView> {
31
-
32
- public static final String REACT_CLASS = "ScanbotBarcodeCameraView";
33
-
34
- private final ReactApplicationContext mCallerContext;
35
- private ScanbotComponentRootView viewGroup;
36
- private ScanbotBarcodeCameraViewFragment cameraViewFragment;
37
- private ScanbotBarcodeCameraViewConfiguration cameraViewConfiguration = new ScanbotBarcodeCameraViewConfiguration();
38
-
39
- public ScanbotBarcodeCameraViewManager(ReactApplicationContext context) {
40
- mCallerContext = context;
41
- }
42
-
43
- @NonNull
44
- @Override
45
- public String getName() {
46
- return REACT_CLASS;
47
- }
48
-
49
- @ReactProp(name = "configuration")
50
- public void setConfiguration(FrameLayout frameLayout, ReadableMap configuration) {
51
- cameraViewConfiguration = new ScanbotBarcodeCameraViewConfiguration();
52
-
53
- try {
54
- ObjectMapper.map(configuration, cameraViewConfiguration);
55
- } catch (Exception e) {
56
- e.printStackTrace();
57
- }
58
-
59
- if (configuration.hasKey("barcodeFormats")) {
60
- cameraViewConfiguration.barcodeFormats = JSONUtils.extractBarcodeFormats(configuration);
61
- }
62
-
63
- if (configuration.hasKey("acceptedDocumentFormats")) {
64
- cameraViewConfiguration.acceptedDocumentFormats = JSONUtils.extractBarcodeDocumentFormats(configuration);
65
- }
66
-
67
- if (configuration.hasKey("cameraZoomFactor")) {
68
- float value = (float) configuration.getDouble("cameraZoomFactor");
69
- if (value != -1) {
70
- cameraViewConfiguration.setCameraZoomFactor(value);
71
- }
72
- }
73
-
74
- if (configuration.hasKey("flashEnabled")) {
75
- cameraViewConfiguration.setFlashEnabled(configuration.getBoolean("flashEnabled"));
76
- }
77
-
78
- cameraViewConfiguration.additionalConfiguration = JSONUtils.extractBarcodeScannerAdditionalConfig(configuration);
79
- cameraViewConfiguration.engineMode = JSONUtils.extractEngineMode(configuration);
80
-
81
- if (cameraViewFragment != null) {
82
- cameraViewFragment.updateWithConfiguration(cameraViewConfiguration);
83
- }
84
- }
85
-
86
- @Nullable
87
- @Override
88
- public Map<String, Object> getExportedCustomDirectEventTypeConstants() {
89
- return EventEmitter.getMapForNativeEvents(new EventEmitter.NativeEvent[] {
90
- EventEmitter.NativeEvent.BARCODE_SCANNER_RESULT,
91
- EventEmitter.NativeEvent.REQUEST_COMPONENT_RELOAD
92
- });
93
- }
94
-
95
- @NonNull
96
- @Override
97
- protected ReactRootView createViewInstance(@NonNull final ThemedReactContext reactContext) {
98
-
99
- // Retrieve Current Activity
100
- final Activity activity = reactContext.getCurrentActivity();
101
- assert activity != null;
102
-
103
- // Inflate Layout
104
- viewGroup = (ScanbotComponentRootView) LayoutInflater
105
- .from(activity)
106
- .inflate(R.layout.component_barcode_camera_view, null, false);
107
-
108
- // Add Camera View Fragment
109
- cameraViewFragment = new ScanbotBarcodeCameraViewFragment();
110
- cameraViewFragment.instantiate(reactContext, viewGroup);
111
- final AppCompatActivity fragmentActivity = (AppCompatActivity) activity;
112
- final FragmentManager fragmentManager = fragmentActivity.getSupportFragmentManager();
113
-
114
- final ScanbotComponentFrameLayout fragmentLayout = viewGroup.findViewById(R.id.fragment_container_view);
115
- fragmentLayout.setZ(-1.0f);
116
- fragmentLayout.setLayoutParams(new FrameLayout.LayoutParams(
117
- FrameLayout.LayoutParams.MATCH_PARENT,
118
- FrameLayout.LayoutParams.MATCH_PARENT));
119
-
120
- // Configure Camera View fragment with configuration parameters
121
- cameraViewFragment.updateWithConfiguration(cameraViewConfiguration);
122
- viewGroup.addOnAttachStateChangeListener(new View.OnAttachStateChangeListener() {
123
- @Override
124
- public void onViewAttachedToWindow(View v) {
125
- if (cameraViewFragment.isAdded()) {
126
- return;
127
- }
128
- reactContext.runOnUiQueueThread(new Runnable() {
129
- @Override
130
- public void run() {
131
- fragmentManager
132
- .beginTransaction()
133
- .add(R.id.fragment_container_view, cameraViewFragment)
134
- .commit();
135
-
136
- viewGroup.post(viewGroup.measureAndLayout);
137
-
138
- viewGroup.addOneShotChildRemovedListener(new ScanbotComponentRootView.IOnChildRemovedListener() {
139
- @Override
140
- public void onChildRemoved(View child) {
141
- new EventEmitter(mCallerContext, viewGroup)
142
- .emitEvent(
143
- EventEmitter.NativeEvent.REQUEST_COMPONENT_RELOAD,
144
- new WritableNativeMap());
145
- }
146
- });
147
- }
148
- });
149
- }
150
-
151
- @Override
152
- public void onViewDetachedFromWindow(View v) {
153
-
154
- }
155
- });
156
-
157
- return viewGroup;
158
- }
159
-
160
- }