dynamsoft-capture-vision-react-native 1.1.3 → 1.1.4-beta09052010

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.
@@ -1,5 +1,8 @@
1
1
  package com.dynamsoft.reactlibrary;
2
2
 
3
+ import androidx.annotation.NonNull;
4
+ import androidx.annotation.Nullable;
5
+
3
6
  import com.dynamsoft.dce.CameraEnhancer;
4
7
  import com.dynamsoft.dce.CameraEnhancerException;
5
8
  import com.dynamsoft.dce.DCECameraView;
@@ -10,12 +13,18 @@ import com.facebook.react.uimanager.ThemedReactContext;
10
13
  public class RNDCECameraView extends DCECameraView implements LifecycleEventListener {
11
14
 
12
15
  CameraEnhancer mCamera;
16
+ ReactApplicationContext mAppContext;
17
+ RNDynamsoftBarcodeReaderModule mDbrModule;
13
18
 
14
- public RNDCECameraView(ThemedReactContext context, ReactApplicationContext appContext, CameraEnhancer cameraEnhancer) {
19
+ public RNDCECameraView(ThemedReactContext context, ReactApplicationContext appContext, @Nullable CameraEnhancer cameraEnhancer, @NonNull RNDynamsoftBarcodeReaderModule dbrModule) {
15
20
  super(context);
16
21
  context.addLifecycleEventListener(this);
22
+ mAppContext = appContext;
23
+ mDbrModule = dbrModule;
17
24
  mCamera = cameraEnhancer;
18
- mCamera.setCameraView(this);
25
+ if(mCamera != null) {
26
+ mCamera.setCameraView(this);
27
+ }
19
28
  }
20
29
 
21
30
  @Override
@@ -40,6 +49,14 @@ public class RNDCECameraView extends DCECameraView implements LifecycleEventList
40
49
 
41
50
  @Override
42
51
  public void onHostResume() {
52
+ if(mCamera == null) {
53
+ if(mAppContext.getCurrentActivity() != null) {
54
+ mCamera = new CameraEnhancer(mAppContext.getCurrentActivity());
55
+ mCamera.setCameraView(this);
56
+ mDbrModule.mIsCameraAttached = false;
57
+ mDbrModule.mReader.setCameraEnhancer(mCamera);
58
+ }
59
+ }
43
60
  if(mCamera!=null){
44
61
  try {
45
62
  mCamera.open();
@@ -7,6 +7,8 @@ import android.graphics.drawable.BitmapDrawable;
7
7
  import android.graphics.drawable.Drawable;
8
8
  import android.util.Base64;
9
9
 
10
+ import androidx.annotation.NonNull;
11
+
10
12
  import com.dynamsoft.dce.CameraEnhancer;
11
13
  import com.dynamsoft.dce.CameraEnhancerException;
12
14
  import com.dynamsoft.dce.RegionDefinition;
@@ -33,12 +35,16 @@ public class RNDCECameraViewManager extends ViewGroupManager<RNDCECameraView> {
33
35
  CameraEnhancer mCamera;
34
36
  RNDynamsoftBarcodeReaderModule mDbrModule;
35
37
 
36
- public RNDCECameraViewManager(ReactApplicationContext reactContext, RNDynamsoftBarcodeReaderModule dbrModule) {
38
+ public RNDCECameraViewManager(ReactApplicationContext reactContext, @NonNull RNDynamsoftBarcodeReaderModule dbrModule) {
37
39
  mReactApplicationContext = reactContext;
38
40
  mDbrModule = dbrModule;
39
- if (dbrModule.getActivity() != null) {
40
- mCamera = new CameraEnhancer(dbrModule.getActivity());
41
+ if (reactContext.getCurrentActivity() != null) {
42
+ mCamera = new CameraEnhancer(reactContext.getCurrentActivity());
41
43
  dbrModule.mCamera = mCamera;
44
+ if(dbrModule.mReader != null && !dbrModule.mIsCameraAttached) {
45
+ dbrModule.mIsCameraAttached = true;
46
+ dbrModule.mReader.setCameraEnhancer(mCamera);
47
+ }
42
48
  }
43
49
  }
44
50
 
@@ -52,10 +58,16 @@ public class RNDCECameraViewManager extends ViewGroupManager<RNDCECameraView> {
52
58
  @Override
53
59
  protected RNDCECameraView createViewInstance(ThemedReactContext reactContext) {
54
60
  if (mCamera == null) {
55
- mCamera = new CameraEnhancer(mDbrModule.getActivity());
56
- mDbrModule.mCamera = mCamera;
61
+ if (reactContext.getCurrentActivity() != null) {
62
+ mCamera = new CameraEnhancer(reactContext.getCurrentActivity());
63
+ mDbrModule.mCamera = mCamera;
64
+ if(mDbrModule.mReader != null && !mDbrModule.mIsCameraAttached) {
65
+ mDbrModule.mIsCameraAttached = true;
66
+ mDbrModule.mReader.setCameraEnhancer(mCamera);
67
+ }
68
+ }
57
69
  }
58
- return new RNDCECameraView(reactContext, mReactApplicationContext, mCamera);
70
+ return new RNDCECameraView(reactContext, mReactApplicationContext, mCamera, mDbrModule);
59
71
  }
60
72
 
61
73
  @ReactProp(name = "overlayVisible")
@@ -26,19 +26,21 @@ import com.facebook.react.bridge.ReadableMap;
26
26
  import com.facebook.react.bridge.WritableArray;
27
27
  import com.facebook.react.bridge.WritableMap;
28
28
  import com.facebook.react.modules.core.DeviceEventManagerModule;
29
+
29
30
  import java.util.Collections;
30
31
  import java.util.HashMap;
31
32
  import java.util.Map;
33
+
32
34
  import javax.annotation.Nullable;
33
35
 
34
36
 
35
37
  public class RNDynamsoftBarcodeReaderModule extends ReactContextBaseJavaModule {
36
38
 
37
39
  private final ReactApplicationContext mReactContext;
38
- private BarcodeReader mReader;
39
40
 
40
- private boolean mIsCameraAttached;
41
- CameraEnhancer mCamera;
41
+ public BarcodeReader mReader;
42
+ public boolean mIsCameraAttached;
43
+ public CameraEnhancer mCamera;
42
44
 
43
45
  public RNDynamsoftBarcodeReaderModule(ReactApplicationContext reactContext) {
44
46
  super(reactContext);
@@ -46,11 +48,6 @@ public class RNDynamsoftBarcodeReaderModule extends ReactContextBaseJavaModule {
46
48
  mIsCameraAttached = false;
47
49
  }
48
50
 
49
-
50
- protected Activity getActivity() {
51
- return super.getCurrentActivity();
52
- }
53
-
54
51
  @Override
55
52
  public String getName() {
56
53
  return "RNDynamsoftBarcodeReader";
@@ -64,7 +61,7 @@ public class RNDynamsoftBarcodeReaderModule extends ReactContextBaseJavaModule {
64
61
  put("TorchState", getFlashModeConstants());
65
62
  }
66
63
 
67
- private Map<String, Object> getFlashModeConstants(){
64
+ private Map<String, Object> getFlashModeConstants() {
68
65
  return Collections.unmodifiableMap(new HashMap<String, Object>() {
69
66
  {
70
67
  put("off", Constants.TORCH_OFF);
@@ -93,12 +90,17 @@ public class RNDynamsoftBarcodeReaderModule extends ReactContextBaseJavaModule {
93
90
 
94
91
  @ReactMethod
95
92
  public void createInstance() {
96
- try {
97
- mReader = new BarcodeReader();
98
- } catch (BarcodeReaderException e) {
99
- e.printStackTrace();
93
+ if(mReader == null) {
94
+ try {
95
+ mReader = new BarcodeReader();
96
+ } catch (BarcodeReaderException e) {
97
+ e.printStackTrace();
98
+ }
99
+ }
100
+ if (mCamera != null && !mIsCameraAttached) {
101
+ mIsCameraAttached = true;
102
+ mReader.setCameraEnhancer(mCamera);
100
103
  }
101
- mReader.setCameraEnhancer(mCamera);
102
104
  }
103
105
 
104
106
  @ReactMethod
@@ -131,7 +133,7 @@ public class RNDynamsoftBarcodeReaderModule extends ReactContextBaseJavaModule {
131
133
 
132
134
  @ReactMethod
133
135
  public void startBarcodeScanning() {
134
- if (!mIsCameraAttached) {
136
+ if (mCamera != null && !mIsCameraAttached) {
135
137
  mReader.setCameraEnhancer(mCamera);
136
138
  mIsCameraAttached = true;
137
139
  }
@@ -20,9 +20,6 @@ public class RNDynamsoftCaptrueVisionPackage implements ReactPackage {
20
20
  @Override
21
21
  public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
22
22
  mDbrModule = new RNDynamsoftBarcodeReaderModule(reactContext);
23
- if(mDCEViewManager !=null && mDCEViewManager.mCamera != null) {
24
- mDbrModule.mCamera = mDCEViewManager.mCamera;
25
- }
26
23
  return Arrays.<NativeModule>asList(mDbrModule);
27
24
  }
28
25
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dynamsoft-capture-vision-react-native",
3
- "version": "1.1.3",
3
+ "version": "1.1.4-beta09052010",
4
4
  "description": "Dynamsoft Capture Vision React Native SDK",
5
5
  "homepage": "https://www.dynamsoft.com/capture-vision/docs/introduction",
6
6
  "main": "./js/index.js",