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.
- package/android/.project +6 -0
- package/android/build.gradle +2 -2
- package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/android/gradle/wrapper/gradle-wrapper.properties +5 -0
- package/android/gradlew +185 -0
- package/android/gradlew.bat +89 -0
- package/android/src/main/java/com/reactlibrary/ScanbotBarcodeSdkPackage.java +17 -4
- package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/ObjectMapper.java +6 -0
- package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/ScanbotBarcodeSdkPackage.java +15 -5
- package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/barcodecameraview/RNScanbotBarcodeCameraComponent.java +292 -0
- package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/barcodecameraview/{ScanbotBarcodeCameraViewConfiguration.java → RNScanbotBarcodeCameraConfiguration.java} +54 -4
- package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/barcodecameraview/RNScanbotBarcodeCameraUi.java +81 -0
- package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/base/RNScanbotNativeComponent.java +90 -0
- package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/base/RNScanbotNativeComponentManager.java +133 -0
- package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/base/RNScanbotNativeComponentManagerFactory.java +40 -0
- package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/base/RNScanbotNativeComponentUi.java +131 -0
- package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/{EventEmitter.java → base/communication/RNScanbotEventEmitter.java} +27 -6
- package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/base/communication/RNScanbotEventReceiver.java +108 -0
- package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/{common/ScanbotComponentFrameLayout.java → base/views/RNScanbotNativeComponentFrameLayout.java} +4 -4
- package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/{common/ScanbotComponentRootView.java → base/views/RNScanbotNativeComponentRootView.java} +43 -48
- package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/utils/JSONUtils.java +25 -14
- package/android/src/main/res/layout/component_barcode_camera_view.xml +22 -5
- package/index.d.ts +7 -3
- package/ios/Components/BarcodeCameraView/RNScanbotBarcodeCameraView.h +7 -1
- package/ios/Components/BarcodeCameraView/RNScanbotBarcodeCameraView.m +18 -2
- package/ios/Components/BarcodeCameraView/RNScanbotBarcodeCameraViewManager.h +6 -0
- package/ios/Components/BarcodeCameraView/RNScanbotBarcodeCameraViewManager.m +41 -0
- package/ios/Utils/BarcodeMapping.h +3 -1
- package/package.json +1 -1
- package/src/components/barcode-camera-view/scanbot-barcode-camera-view-types.tsx +6 -0
- package/src/components/barcode-camera-view/scanbot-barcode-camera-view.tsx +42 -5
- package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/BitmapHelper.java +0 -28
- package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/JSONUtils.java +0 -272
- package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/LogUtils.java +0 -40
- package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/ResponseUtils.java +0 -41
- package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/barcodecameraview/ScanbotBarcodeCameraViewFragment.java +0 -255
- package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/barcodecameraview/ScanbotBarcodeCameraViewManager.java +0 -160
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
package io.scanbot.barcodesdk.plugin.reactnative.components.base;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
|
|
5
|
+
import com.facebook.react.bridge.ReactContext;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* This class is used to create ViewManagers for native components
|
|
9
|
+
*/
|
|
10
|
+
public class RNScanbotNativeComponentManagerFactory {
|
|
11
|
+
|
|
12
|
+
private final ReactContext reactContext;
|
|
13
|
+
|
|
14
|
+
public RNScanbotNativeComponentManagerFactory(@NonNull final ReactContext reactContext) {
|
|
15
|
+
this.reactContext = reactContext;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
private static class RNScanbotNativeComponentManagerCreator<T extends RNScanbotNativeComponent> {
|
|
19
|
+
public RNScanbotNativeComponentManager<T> create(
|
|
20
|
+
@NonNull final ReactContext reactContext,
|
|
21
|
+
@NonNull final T nativeComponent,
|
|
22
|
+
@NonNull final String name
|
|
23
|
+
) {
|
|
24
|
+
return new RNScanbotNativeComponentManager<T>(reactContext, nativeComponent) {
|
|
25
|
+
@NonNull @Override public String getName() {
|
|
26
|
+
return name;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
@SuppressWarnings({"unchecked", "rawtypes"})
|
|
33
|
+
public RNScanbotNativeComponentManager createManager(
|
|
34
|
+
@NonNull final RNScanbotNativeComponent nativeComponent,
|
|
35
|
+
@NonNull final String name
|
|
36
|
+
) {
|
|
37
|
+
return new RNScanbotNativeComponentManagerCreator().create(reactContext, nativeComponent, name);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
package io.scanbot.barcodesdk.plugin.reactnative.components.base;
|
|
2
|
+
|
|
3
|
+
import android.view.View;
|
|
4
|
+
|
|
5
|
+
import androidx.annotation.NonNull;
|
|
6
|
+
|
|
7
|
+
import com.facebook.react.bridge.ReactContext;
|
|
8
|
+
import com.facebook.react.bridge.WritableNativeMap;
|
|
9
|
+
|
|
10
|
+
import io.scanbot.barcodesdk.plugin.reactnative.components.base.communication.RNScanbotEventEmitter;
|
|
11
|
+
import io.scanbot.barcodesdk.plugin.reactnative.components.base.views.RNScanbotNativeComponentRootView;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* This is the UI component of your custom React Native components.
|
|
15
|
+
* It expects you to return a ScanbotComponentRootView in createRootView.
|
|
16
|
+
* It takes care of attaching listeners and handling layout changes re-measurements.
|
|
17
|
+
*/
|
|
18
|
+
public abstract class RNScanbotNativeComponentUi {
|
|
19
|
+
// The rootView created through createRootView()
|
|
20
|
+
protected RNScanbotNativeComponentRootView rootView;
|
|
21
|
+
|
|
22
|
+
// The React Context
|
|
23
|
+
protected ReactContext reactContext;
|
|
24
|
+
|
|
25
|
+
// Listener to handle the re-layout when children change... they grow up so fast
|
|
26
|
+
private RNScanbotNativeComponentRootView.IOnChildRemovedListener childRemovedListener;
|
|
27
|
+
private View.OnAttachStateChangeListener onAttachStateChangeListener;
|
|
28
|
+
private Runnable onViewRecreated;
|
|
29
|
+
|
|
30
|
+
public RNScanbotNativeComponentUi(@NonNull final ReactContext reactContext) { this.reactContext = reactContext; }
|
|
31
|
+
|
|
32
|
+
/*
|
|
33
|
+
* Disposes the component
|
|
34
|
+
*/
|
|
35
|
+
public void dispose() {
|
|
36
|
+
if (childRemovedListener != null) {
|
|
37
|
+
rootView.removeOneShotChildRemovedListener(childRemovedListener);
|
|
38
|
+
}
|
|
39
|
+
if (onAttachStateChangeListener != null) {
|
|
40
|
+
rootView.removeOnAttachStateChangeListener(onAttachStateChangeListener);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
childRemovedListener = null;
|
|
44
|
+
onAttachStateChangeListener = null;
|
|
45
|
+
|
|
46
|
+
this.rootView = null;
|
|
47
|
+
this.reactContext = null;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/*
|
|
51
|
+
* Returns the rootView created by createRootView, after performing some UI post operations
|
|
52
|
+
*/
|
|
53
|
+
public RNScanbotNativeComponentRootView getRootView() {
|
|
54
|
+
if (this.rootView == null) {
|
|
55
|
+
this.rootView = createAndSetupRootView();
|
|
56
|
+
this.notifyViewRecreated();
|
|
57
|
+
}
|
|
58
|
+
return this.rootView;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
public void _setOnViewRecreatedListener(final Runnable runnable) {
|
|
62
|
+
this.onViewRecreated = runnable;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
public void removeOnViewRecreatedListener() {
|
|
66
|
+
this.onViewRecreated = null;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
private void notifyViewRecreated() {
|
|
70
|
+
if (this.onViewRecreated == null) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
this.onViewRecreated.run();
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/*
|
|
77
|
+
* You must construct your view inside this method, and then return it.
|
|
78
|
+
*/
|
|
79
|
+
protected abstract RNScanbotNativeComponentRootView createRootView(@NonNull final ReactContext reactContext);
|
|
80
|
+
|
|
81
|
+
/*
|
|
82
|
+
* Calls the inheriting class's Root View custom creator, and performs some additional setup to
|
|
83
|
+
* it, before returning it.
|
|
84
|
+
*/
|
|
85
|
+
private RNScanbotNativeComponentRootView createAndSetupRootView() {
|
|
86
|
+
final RNScanbotNativeComponentRootView rootView = createRootView(this.reactContext);
|
|
87
|
+
onAttachStateChangeListener = new View.OnAttachStateChangeListener() {
|
|
88
|
+
@Override
|
|
89
|
+
public void onViewAttachedToWindow(View v) {
|
|
90
|
+
remeasureViews(rootView, reactContext);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
@Override
|
|
94
|
+
public void onViewDetachedFromWindow(View v) {}
|
|
95
|
+
};
|
|
96
|
+
rootView.addOnAttachStateChangeListener(onAttachStateChangeListener);
|
|
97
|
+
return rootView;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/*
|
|
101
|
+
* UI Thread: Remeasures and layouts the views
|
|
102
|
+
*/
|
|
103
|
+
public void remeasureViews(
|
|
104
|
+
@NonNull final RNScanbotNativeComponentRootView rootView,
|
|
105
|
+
@NonNull final ReactContext reactContext
|
|
106
|
+
) {
|
|
107
|
+
reactContext.runOnUiQueueThread(() -> {
|
|
108
|
+
// The view is remeasured as soon as it is attached to the window
|
|
109
|
+
rootView.post(rootView.measureAndLayout);
|
|
110
|
+
|
|
111
|
+
// Runs custom logic that has to be performed after the remeasuring of the views
|
|
112
|
+
rootView.post(this::onViewsRemeasured);
|
|
113
|
+
|
|
114
|
+
// Take care of your children
|
|
115
|
+
if (childRemovedListener != null) {
|
|
116
|
+
rootView.removeOneShotChildRemovedListener(childRemovedListener);
|
|
117
|
+
}
|
|
118
|
+
childRemovedListener = child -> new RNScanbotEventEmitter(reactContext, rootView)
|
|
119
|
+
.emitEvent(
|
|
120
|
+
RNScanbotEventEmitter.CommonEvents.REQUEST_COMPONENT_RELOAD,
|
|
121
|
+
new WritableNativeMap());
|
|
122
|
+
rootView.addOneShotChildRemovedListener(childRemovedListener);
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Called after the remeasuring of the views has been completed. Override this if you want
|
|
128
|
+
* to apply some custom UI logic in that point of the lifecycle.
|
|
129
|
+
*/
|
|
130
|
+
protected void onViewsRemeasured() {}
|
|
131
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
package io.scanbot.barcodesdk.plugin.reactnative.components;
|
|
1
|
+
package io.scanbot.barcodesdk.plugin.reactnative.components.base.communication;
|
|
2
2
|
|
|
3
3
|
import android.view.ViewGroup;
|
|
4
4
|
|
|
@@ -9,14 +9,17 @@ import com.facebook.react.uimanager.events.RCTEventEmitter;
|
|
|
9
9
|
|
|
10
10
|
import java.util.Map;
|
|
11
11
|
|
|
12
|
-
public class
|
|
12
|
+
public class RNScanbotEventEmitter {
|
|
13
13
|
|
|
14
|
-
public
|
|
15
|
-
|
|
14
|
+
public interface NativeEvent {
|
|
15
|
+
String getName();
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
public enum CommonEvents implements RNScanbotEventEmitter.NativeEvent {
|
|
16
19
|
REQUEST_COMPONENT_RELOAD("requestComponentReload");
|
|
17
20
|
|
|
18
21
|
private final String name;
|
|
19
|
-
|
|
22
|
+
CommonEvents(final String name) {
|
|
20
23
|
this.name = name;
|
|
21
24
|
}
|
|
22
25
|
|
|
@@ -29,7 +32,7 @@ public class EventEmitter {
|
|
|
29
32
|
private final ReactContext reactContext;
|
|
30
33
|
private final ViewGroup rootViewGroup;
|
|
31
34
|
|
|
32
|
-
public
|
|
35
|
+
public RNScanbotEventEmitter(final ReactContext reactContext, final ViewGroup rootViewGroup) {
|
|
33
36
|
this.reactContext = reactContext;
|
|
34
37
|
this.jsEventEmitter = reactContext.getJSModule(RCTEventEmitter.class);
|
|
35
38
|
this.rootViewGroup = rootViewGroup;
|
|
@@ -52,4 +55,22 @@ public class EventEmitter {
|
|
|
52
55
|
|
|
53
56
|
return builder.build();
|
|
54
57
|
}
|
|
58
|
+
|
|
59
|
+
public static RNScanbotEventEmitter.NativeEvent[] concatEvents(
|
|
60
|
+
RNScanbotEventEmitter.NativeEvent[] arr1,
|
|
61
|
+
RNScanbotEventEmitter.NativeEvent[] arr2
|
|
62
|
+
) {
|
|
63
|
+
final int len1 = arr1.length;
|
|
64
|
+
final int len2 = arr2.length;
|
|
65
|
+
final int min = Math.min(len1, len2);
|
|
66
|
+
final int max = Math.max(len1, len2);
|
|
67
|
+
final RNScanbotEventEmitter.NativeEvent[] out = new RNScanbotEventEmitter.NativeEvent[len1 + len2];
|
|
68
|
+
|
|
69
|
+
for (int i = 0; i<max; ++i) {
|
|
70
|
+
out[i] = len2 > len1 ? arr2[i] : arr1[i];
|
|
71
|
+
if (i < min) { out[i+max] = len2 > len1 ? arr1[i] : arr2[i]; }
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return out;
|
|
75
|
+
}
|
|
55
76
|
}
|
|
@@ -0,0 +1,108 @@
|
|
|
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 RNScanbotEventReceiver {
|
|
12
|
+
|
|
13
|
+
public interface JavaScriptEvent {
|
|
14
|
+
String getName();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
public enum CommonEvents implements RNScanbotEventReceiver.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
|
+
public String getName() {
|
|
29
|
+
return name;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
public interface IEventHandler {
|
|
34
|
+
void eventHandler_eventReceived(final JavaScriptEvent event, @Nullable final ReadableArray args);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
private final IEventHandler handler;
|
|
38
|
+
private final JavaScriptEvent[] events;
|
|
39
|
+
private final HashMap<Integer, String> eventsMap = new HashMap<>();
|
|
40
|
+
|
|
41
|
+
public RNScanbotEventReceiver(@NonNull final IEventHandler handler, @NonNull final JavaScriptEvent[] events) {
|
|
42
|
+
this.handler = handler;
|
|
43
|
+
this.events = concatEvents(CommonEvents.values(), events);
|
|
44
|
+
prepare();
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
public void receiveCommand(@NonNull final String commandId, @Nullable final ReadableArray args) {
|
|
48
|
+
int commandIdInt = Integer.parseInt(commandId);
|
|
49
|
+
if (!eventsMap.containsKey(commandIdInt)) {
|
|
50
|
+
return; // Command not handled
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
final String eventName = eventsMap.get(commandIdInt);
|
|
54
|
+
assert eventName != null;
|
|
55
|
+
final JavaScriptEvent event = getEventFromName(eventName);
|
|
56
|
+
handler.eventHandler_eventReceived(event, args);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
public Map<String, Integer> getCommandsMap() {
|
|
60
|
+
final HashMap<String, Integer> out = new HashMap<>();
|
|
61
|
+
for (final Integer key: eventsMap.keySet()) {
|
|
62
|
+
out.put(eventsMap.get(key), key);
|
|
63
|
+
}
|
|
64
|
+
return out;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
private void prepare() {
|
|
68
|
+
int commandId = 1;
|
|
69
|
+
for(final JavaScriptEvent event: this.events) {
|
|
70
|
+
this.eventsMap.put(commandId++, event.getName());
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
public JavaScriptEvent getEventFromName(@NonNull final String name) {
|
|
75
|
+
for (JavaScriptEvent event: events) {
|
|
76
|
+
if (event.getName().equals(name)) {
|
|
77
|
+
return event;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
public CommonEvents getCommonEventFromName(@NonNull final String name) {
|
|
84
|
+
final JavaScriptEvent event = getEventFromName(name);
|
|
85
|
+
if (!(event instanceof CommonEvents)) {
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
return (CommonEvents) event;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
public static RNScanbotEventReceiver.JavaScriptEvent[] concatEvents(
|
|
92
|
+
RNScanbotEventReceiver.JavaScriptEvent[] arr1,
|
|
93
|
+
RNScanbotEventReceiver.JavaScriptEvent[] arr2
|
|
94
|
+
) {
|
|
95
|
+
final int len1 = arr1.length;
|
|
96
|
+
final int len2 = arr2.length;
|
|
97
|
+
final int min = Math.min(len1, len2);
|
|
98
|
+
final int max = Math.max(len1, len2);
|
|
99
|
+
final RNScanbotEventReceiver.JavaScriptEvent[] out = new RNScanbotEventReceiver.JavaScriptEvent[len1 + len2];
|
|
100
|
+
|
|
101
|
+
for (int i = 0; i<max; ++i) {
|
|
102
|
+
out[i] = len2 > len1 ? arr2[i] : arr1[i];
|
|
103
|
+
if (i < min) { out[i+max] = len2 > len1 ? arr1[i] : arr2[i]; }
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return out;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
package io.scanbot.barcodesdk.plugin.reactnative.components.
|
|
1
|
+
package io.scanbot.barcodesdk.plugin.reactnative.components.base.views;
|
|
2
2
|
|
|
3
3
|
import android.content.Context;
|
|
4
4
|
import android.util.AttributeSet;
|
|
@@ -7,17 +7,17 @@ import android.widget.FrameLayout;
|
|
|
7
7
|
import java.util.ArrayList;
|
|
8
8
|
import java.util.List;
|
|
9
9
|
|
|
10
|
-
public class
|
|
10
|
+
public class RNScanbotNativeComponentFrameLayout extends FrameLayout {
|
|
11
11
|
|
|
12
12
|
interface ILayoutChangeListener {
|
|
13
13
|
void onFrameLayoutChanged(int width, int height, int left, int top, int right, int bottom);
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
public
|
|
16
|
+
public RNScanbotNativeComponentFrameLayout(Context context, AttributeSet attrs) {
|
|
17
17
|
super(context, attrs);
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
public
|
|
20
|
+
public RNScanbotNativeComponentFrameLayout(Context context, AttributeSet attrs, int defStyle) {
|
|
21
21
|
super(context, attrs, defStyle);
|
|
22
22
|
}
|
|
23
23
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
package io.scanbot.barcodesdk.plugin.reactnative.components.
|
|
1
|
+
package io.scanbot.barcodesdk.plugin.reactnative.components.base.views;
|
|
2
2
|
|
|
3
3
|
import android.content.Context;
|
|
4
4
|
import android.util.AttributeSet;
|
|
@@ -13,7 +13,7 @@ import java.lang.reflect.Type;
|
|
|
13
13
|
import java.util.ArrayList;
|
|
14
14
|
import java.util.List;
|
|
15
15
|
|
|
16
|
-
public class
|
|
16
|
+
public class RNScanbotNativeComponentRootView extends ReactRootView {
|
|
17
17
|
|
|
18
18
|
public interface ILayoutChangeListener {
|
|
19
19
|
void onFrameLayoutChanged(int width, int height, int left, int top, int right, int bottom);
|
|
@@ -23,64 +23,53 @@ public class ScanbotComponentRootView extends ReactRootView {
|
|
|
23
23
|
void onChildRemoved(final View child);
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
public final Runnable measureAndLayout =
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
layout(getLeft(), getTop(), getRight(), getBottom());
|
|
34
|
-
notifyLayoutChangeListeners(getWidth(), getHeight(), getLeft(), getTop(), getRight(), getBottom());
|
|
35
|
-
}
|
|
36
|
-
};
|
|
26
|
+
public final Runnable measureAndLayout = () -> {
|
|
27
|
+
measure(
|
|
28
|
+
MeasureSpec.makeMeasureSpec(getWidth(), MeasureSpec.EXACTLY),
|
|
29
|
+
MeasureSpec.makeMeasureSpec(getHeight(), MeasureSpec.EXACTLY));
|
|
30
|
+
layout(getLeft(), getTop(), getRight(), getBottom());
|
|
31
|
+
notifyLayoutChangeListeners(getWidth(), getHeight(), getLeft(), getTop(), getRight(), getBottom());
|
|
32
|
+
};
|
|
37
33
|
|
|
38
34
|
private final List<ILayoutChangeListener> layoutChangeListeners = new ArrayList<>();
|
|
39
35
|
private final List<IOnChildRemovedListener> childRemovedListeners = new ArrayList<>();
|
|
40
|
-
private final List<View> lastNotifiedChildViews = new ArrayList<>();
|
|
41
|
-
private final List<Type> reservedComponents = new ArrayList<>();
|
|
42
36
|
private boolean shouldNotifyWhenChildIsRemoved = false;
|
|
43
37
|
|
|
44
|
-
|
|
45
|
-
reservedComponents.add(ScanbotComponentRootView.class);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
public ScanbotComponentRootView(Context context) {
|
|
38
|
+
public RNScanbotNativeComponentRootView(Context context) {
|
|
49
39
|
super(context);
|
|
50
40
|
instantiate();
|
|
51
41
|
}
|
|
52
42
|
|
|
53
|
-
public
|
|
43
|
+
public RNScanbotNativeComponentRootView(Context context, AttributeSet attrs) {
|
|
54
44
|
super(context, attrs);
|
|
55
45
|
instantiate();
|
|
56
46
|
}
|
|
57
47
|
|
|
58
|
-
public
|
|
48
|
+
public RNScanbotNativeComponentRootView(Context context, AttributeSet attrs, int defStyle) {
|
|
59
49
|
super(context, attrs, defStyle);
|
|
60
50
|
instantiate();
|
|
61
51
|
}
|
|
62
52
|
|
|
53
|
+
private void instantiate() {}
|
|
54
|
+
|
|
63
55
|
@Override
|
|
64
56
|
protected void onAttachedToWindow() {
|
|
65
57
|
super.onAttachedToWindow();
|
|
66
58
|
applyChildrenMeasureWorkaround();
|
|
67
59
|
}
|
|
68
60
|
|
|
69
|
-
|
|
70
|
-
Choreographer.getInstance().postFrameCallback(
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
MeasureSpec.makeMeasureSpec(getMeasuredHeight(), MeasureSpec.EXACTLY));
|
|
78
|
-
child.layout(0, 0, child.getMeasuredWidth(), child.getMeasuredHeight());
|
|
79
|
-
}
|
|
61
|
+
public void applyChildrenMeasureWorkaround() {
|
|
62
|
+
Choreographer.getInstance().postFrameCallback(frameTimeNanos -> {
|
|
63
|
+
for (int i = 0; i < getChildCount(); i++) {
|
|
64
|
+
View child = getChildAt(i);
|
|
65
|
+
if (child instanceof FrameLayout) {
|
|
66
|
+
child.measure(MeasureSpec.makeMeasureSpec(getMeasuredWidth(), MeasureSpec.EXACTLY),
|
|
67
|
+
MeasureSpec.makeMeasureSpec(getMeasuredHeight(), MeasureSpec.EXACTLY));
|
|
68
|
+
child.layout(0, 0, child.getMeasuredWidth(), child.getMeasuredHeight());
|
|
80
69
|
}
|
|
81
|
-
getViewTreeObserver().dispatchOnGlobalLayout();
|
|
82
|
-
shouldNotifyWhenChildIsRemoved = true;
|
|
83
70
|
}
|
|
71
|
+
getViewTreeObserver().dispatchOnGlobalLayout();
|
|
72
|
+
shouldNotifyWhenChildIsRemoved = true;
|
|
84
73
|
});
|
|
85
74
|
}
|
|
86
75
|
|
|
@@ -105,6 +94,10 @@ public class ScanbotComponentRootView extends ReactRootView {
|
|
|
105
94
|
}
|
|
106
95
|
}
|
|
107
96
|
|
|
97
|
+
public void removeOneShotChildRemovedListener(IOnChildRemovedListener listener) {
|
|
98
|
+
childRemovedListeners.remove(listener);
|
|
99
|
+
}
|
|
100
|
+
|
|
108
101
|
private void notifyLayoutChangeListeners(int width, int height, int left, int top, int right, int bottom) {
|
|
109
102
|
for(ILayoutChangeListener listener : layoutChangeListeners) {
|
|
110
103
|
listener.onFrameLayoutChanged(width, height, left, top, right, bottom);
|
|
@@ -112,16 +105,20 @@ public class ScanbotComponentRootView extends ReactRootView {
|
|
|
112
105
|
}
|
|
113
106
|
|
|
114
107
|
private void notifyChildRemovedListeners(final View childView) {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
108
|
+
// if (!shouldNotifyWhenChildIsRemoved) {
|
|
109
|
+
// return;
|
|
110
|
+
// }
|
|
111
|
+
// -> Might be useful one day
|
|
112
|
+
// for (IOnChildRemovedListener listener : childRemovedListeners) {
|
|
113
|
+
// if (!lastNotifiedChildViews.contains(childView)) {
|
|
114
|
+
// listener.onChildRemoved(childView);
|
|
115
|
+
// lastNotifiedChildViews.add(childView);
|
|
116
|
+
// } else {
|
|
117
|
+
// lastNotifiedChildViews.clear();
|
|
118
|
+
// }
|
|
119
|
+
// }
|
|
120
|
+
//
|
|
121
|
+
// childRemovedListeners.clear();
|
|
125
122
|
}
|
|
126
123
|
|
|
127
124
|
@Override
|
|
@@ -140,9 +137,7 @@ public class ScanbotComponentRootView extends ReactRootView {
|
|
|
140
137
|
@Override
|
|
141
138
|
public void onViewRemoved(View child) {
|
|
142
139
|
super.onViewRemoved(child);
|
|
143
|
-
|
|
144
|
-
//notifyChildRemovedListeners(child);
|
|
145
|
-
}
|
|
140
|
+
notifyChildRemovedListeners(child);
|
|
146
141
|
}
|
|
147
142
|
|
|
148
143
|
@Override
|
|
@@ -39,7 +39,8 @@ import io.scanbot.sdk.ui.view.base.configuration.CameraOrientationMode;
|
|
|
39
39
|
|
|
40
40
|
public final class JSONUtils {
|
|
41
41
|
|
|
42
|
-
private JSONUtils() {
|
|
42
|
+
private JSONUtils() {
|
|
43
|
+
}
|
|
43
44
|
|
|
44
45
|
public static class WritableMapBuilder {
|
|
45
46
|
|
|
@@ -88,7 +89,7 @@ public final class JSONUtils {
|
|
|
88
89
|
public static WritableArray sdkPolygonToWritableArray(final List<PointF> polygon) {
|
|
89
90
|
WritableArray points = Arguments.createArray();
|
|
90
91
|
if (polygon != null) {
|
|
91
|
-
for (final PointF p: polygon) {
|
|
92
|
+
for (final PointF p : polygon) {
|
|
92
93
|
WritableMap pointRecord = Arguments.createMap();
|
|
93
94
|
pointRecord.putDouble("x", p.x);
|
|
94
95
|
pointRecord.putDouble("y", p.y);
|
|
@@ -122,7 +123,8 @@ public final class JSONUtils {
|
|
|
122
123
|
return nativeBarcodeDocumentFormats;
|
|
123
124
|
}
|
|
124
125
|
|
|
125
|
-
public static @Nullable
|
|
126
|
+
public static @Nullable
|
|
127
|
+
CameraOrientationMode extractCameraOrientationMode(final ReadableMap configuration) {
|
|
126
128
|
if (configuration.hasKey("allowedInterfaceOrientations")) {
|
|
127
129
|
String orientation = configuration.getString("allowedInterfaceOrientations");
|
|
128
130
|
if (orientation == null) {
|
|
@@ -146,7 +148,8 @@ public final class JSONUtils {
|
|
|
146
148
|
return null;
|
|
147
149
|
}
|
|
148
150
|
|
|
149
|
-
public static @Nullable
|
|
151
|
+
public static @Nullable
|
|
152
|
+
BarcodeScannerAdditionalConfig extractBarcodeScannerAdditionalConfig(final ReadableMap configuration) {
|
|
150
153
|
boolean changed = false;
|
|
151
154
|
|
|
152
155
|
int minimumTextLength = BarcodeScannerAdditionalConfig.DEFAULT_MIN_TEXT_LENGTH;
|
|
@@ -163,7 +166,7 @@ public final class JSONUtils {
|
|
|
163
166
|
|
|
164
167
|
int minimum1DQuietZoneSize = BarcodeScannerAdditionalConfig.DEFAULT_MIN_1D_QUIET_ZONE_SIZE;
|
|
165
168
|
if (configuration.hasKey("minimum1DBarcodesQuietZone")) {
|
|
166
|
-
minimum1DQuietZoneSize
|
|
169
|
+
minimum1DQuietZoneSize = configuration.getInt("minimum1DBarcodesQuietZone");
|
|
167
170
|
changed = true;
|
|
168
171
|
}
|
|
169
172
|
|
|
@@ -205,7 +208,8 @@ public final class JSONUtils {
|
|
|
205
208
|
) : null;
|
|
206
209
|
}
|
|
207
210
|
|
|
208
|
-
public static @Nullable
|
|
211
|
+
public static @Nullable
|
|
212
|
+
BarcodeScannerAdditionalConfiguration extractBarcodeScannerAdditionalConfiguration(final ReadableMap configuration) {
|
|
209
213
|
final BarcodeScannerAdditionalConfig config = extractBarcodeScannerAdditionalConfig(configuration);
|
|
210
214
|
return config != null ? new BarcodeScannerAdditionalConfiguration(
|
|
211
215
|
config.getMinimumTextLength(),
|
|
@@ -227,8 +231,7 @@ public final class JSONUtils {
|
|
|
227
231
|
final ReactBarcodeExtensionsFilter.Type type =
|
|
228
232
|
ReactBarcodeExtensionsFilter.Type.valueOf(filterType);
|
|
229
233
|
return new ReactBarcodeExtensionsFilter(type);
|
|
230
|
-
}
|
|
231
|
-
catch (IllegalArgumentException exception) {
|
|
234
|
+
} catch (IllegalArgumentException exception) {
|
|
232
235
|
final String errMsg = String.format("The value passed in 'barcodeFilter' (%s) does not exist", filterType);
|
|
233
236
|
Log.e("SCANBOT_SDK", errMsg);
|
|
234
237
|
}
|
|
@@ -237,13 +240,19 @@ public final class JSONUtils {
|
|
|
237
240
|
}
|
|
238
241
|
|
|
239
242
|
public static List<BarcodeItem> getBarcodeItemsFromResultWithFilter(BarcodeScanningResult result, BarcodeFilter filter) {
|
|
240
|
-
|
|
243
|
+
return getBarcodeItemsFromItemListWithFilter(result.getBarcodeItems(), filter);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
public static List<BarcodeItem> getBarcodeItemsFromItemListWithFilter(List<BarcodeItem> results, BarcodeFilter filter) {
|
|
247
|
+
if (results == null) {
|
|
241
248
|
return new ArrayList<>();
|
|
242
249
|
}
|
|
243
250
|
|
|
244
251
|
final List<BarcodeItem> filteredBarcodeItems = new ArrayList<>();
|
|
245
|
-
for (BarcodeItem barcodeItem :
|
|
246
|
-
if (!filter.acceptsBarcode(barcodeItem)) {
|
|
252
|
+
for (BarcodeItem barcodeItem : results) {
|
|
253
|
+
if (!filter.acceptsBarcode(barcodeItem)) {
|
|
254
|
+
continue;
|
|
255
|
+
}
|
|
247
256
|
filteredBarcodeItems.add(barcodeItem);
|
|
248
257
|
}
|
|
249
258
|
return filteredBarcodeItems;
|
|
@@ -251,15 +260,17 @@ public final class JSONUtils {
|
|
|
251
260
|
|
|
252
261
|
public static ArrayList<String> getStringArrayListFromMap(final ReadableMap configuration, final String key) {
|
|
253
262
|
ArrayList<String> out = new ArrayList<>();
|
|
254
|
-
if(!configuration.hasKey(key)) {
|
|
263
|
+
if (!configuration.hasKey(key)) {
|
|
255
264
|
return out;
|
|
256
265
|
}
|
|
257
266
|
ReadableArray nullable = configuration.getArray(key);
|
|
258
267
|
if (nullable != null) {
|
|
259
268
|
ArrayList<Object> objects = nullable.toArrayList();
|
|
260
269
|
for (Object obj : objects) {
|
|
261
|
-
try {
|
|
262
|
-
|
|
270
|
+
try {
|
|
271
|
+
out.add(Objects.toString(obj));
|
|
272
|
+
} catch (ClassCastException ignored) {
|
|
273
|
+
}
|
|
263
274
|
}
|
|
264
275
|
}
|
|
265
276
|
return out;
|
|
@@ -1,11 +1,28 @@
|
|
|
1
1
|
<?xml version="1.0" encoding="utf-8"?>
|
|
2
|
-
<io.scanbot.barcodesdk.plugin.reactnative.components.
|
|
2
|
+
<io.scanbot.barcodesdk.plugin.reactnative.components.base.views.RNScanbotNativeComponentRootView
|
|
3
3
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
|
4
4
|
android:descendantFocusability="afterDescendants"
|
|
5
5
|
android:layout_width="match_parent"
|
|
6
6
|
android:layout_height="match_parent">
|
|
7
|
-
<io.scanbot.barcodesdk.plugin.reactnative.components.
|
|
8
|
-
android:id="@+id/
|
|
7
|
+
<io.scanbot.barcodesdk.plugin.reactnative.components.base.views.RNScanbotNativeComponentFrameLayout
|
|
8
|
+
android:id="@+id/barcode_camera_layout"
|
|
9
|
+
xmlns:app="http://schemas.android.com/apk/res-auto"
|
|
9
10
|
android:layout_width="match_parent"
|
|
10
|
-
android:layout_height="match_parent"
|
|
11
|
-
|
|
11
|
+
android:layout_height="match_parent">
|
|
12
|
+
|
|
13
|
+
<io.scanbot.sdk.ui.camera.ScanbotCameraXView
|
|
14
|
+
android:id="@+id/barcode_camera"
|
|
15
|
+
android:orientation="vertical"
|
|
16
|
+
android:layout_width="match_parent"
|
|
17
|
+
android:layout_height="match_parent"
|
|
18
|
+
android:background="@android:color/black"
|
|
19
|
+
app:finder_view_id="@id/barcode_finder_overlay"/>
|
|
20
|
+
|
|
21
|
+
<io.scanbot.sdk.ui.camera.FinderOverlayView
|
|
22
|
+
android:id="@+id/barcode_finder_overlay"
|
|
23
|
+
app:min_padding="64dp"
|
|
24
|
+
android:layout_width="match_parent"
|
|
25
|
+
android:layout_height="match_parent" />
|
|
26
|
+
|
|
27
|
+
</io.scanbot.barcodesdk.plugin.reactnative.components.base.views.RNScanbotNativeComponentFrameLayout>
|
|
28
|
+
</io.scanbot.barcodesdk.plugin.reactnative.components.base.views.RNScanbotNativeComponentRootView>
|