@sodyo/react-native-sodyo-sdk 3.9.0 → 3.9.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.
@@ -10,8 +10,6 @@ package com.sodyo.RNSodyoSDK;
10
10
  import com.facebook.react.bridge.ReadableArray;
11
11
  import com.facebook.react.bridge.ReadableMap;
12
12
  import com.facebook.react.bridge.ReadableType;
13
- import com.facebook.react.bridge.WritableArray;
14
- import com.facebook.react.bridge.Arguments;
15
13
 
16
14
  import java.util.ArrayList;
17
15
  import java.util.HashMap;
@@ -13,7 +13,7 @@ import android.app.FragmentManager;
13
13
  import android.app.FragmentTransaction;
14
14
  import javax.annotation.Nullable;
15
15
 
16
- import com.sodyo.sdk.SodyoOpenCvScannerFragment;
16
+ import com.sodyo.sdk.SodyoScannerFragment;
17
17
 
18
18
  public class RNSodyoSdkView extends SimpleViewManager<FrameLayout> {
19
19
  static final String TAG = "RNSodyoSdkView";
@@ -24,6 +24,10 @@ public class RNSodyoSdkView extends SimpleViewManager<FrameLayout> {
24
24
 
25
25
  private final @Nullable ReactApplicationContext mCallerContext;
26
26
 
27
+ private @Nullable SodyoScannerFragment sodyoFragment;
28
+
29
+ private boolean isCameraEnabled = true;
30
+
27
31
  @Override
28
32
  public String getName() {
29
33
  return REACT_CLASS;
@@ -35,22 +39,19 @@ public class RNSodyoSdkView extends SimpleViewManager<FrameLayout> {
35
39
 
36
40
  @Override
37
41
  public FrameLayout createViewInstance(ThemedReactContext context) {
38
- Log.i(TAG, "createViewInstance");
42
+ Log.i(TAG,"createViewInstance");
39
43
 
40
44
  final FrameLayout view = new FrameLayout(context);
41
- SodyoOpenCvScannerFragment sodyoFragment = new SodyoOpenCvScannerFragment();
45
+
46
+ if (sodyoFragment == null) {
47
+ Log.i(TAG,"init SodyoScannerFragment");
48
+ sodyoFragment = new SodyoScannerFragment();
49
+ }
42
50
 
43
51
  FragmentManager fragmentManager = mCallerContext.getCurrentActivity().getFragmentManager();
44
- Fragment fragment = fragmentManager.findFragmentByTag(TAG_FRAGMENT);
45
52
  FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
46
53
 
47
-
48
- if (fragment != null) {
49
- fragmentTransaction.remove(fragment);
50
- }
51
-
52
- fragmentTransaction.add(sodyoFragment, TAG_FRAGMENT);
53
- fragmentTransaction.commit();
54
+ fragmentTransaction.add(sodyoFragment, TAG_FRAGMENT).commit();
54
55
 
55
56
  fragmentManager.executePendingTransactions();
56
57
 
@@ -62,7 +63,10 @@ public class RNSodyoSdkView extends SimpleViewManager<FrameLayout> {
62
63
  public void onDropViewInstance(FrameLayout view) {
63
64
  super.onDropViewInstance(view);
64
65
 
65
- Log.i(TAG, "onDropViewInstance");
66
+ Log.i(TAG,"onDropViewInstance");
67
+
68
+ sodyoFragment = null;
69
+ isCameraEnabled = true;
66
70
 
67
71
  try {
68
72
  FragmentManager fragmentManager = mCallerContext.getCurrentActivity().getFragmentManager();
@@ -71,9 +75,27 @@ public class RNSodyoSdkView extends SimpleViewManager<FrameLayout> {
71
75
  if (fragment != null) {
72
76
  fragmentManager.beginTransaction().remove(fragment).commit();
73
77
  }
74
-
75
78
  } catch (Exception e) {
76
- e.printStackTrace();
79
+ e.printStackTrace();
77
80
  }
78
81
  }
82
+
83
+ @ReactProp(name = "isEnabled", defaultBoolean=true)
84
+ public void setIsEnabled(FrameLayout view, boolean isEnabled) {
85
+ if (sodyoFragment == null) {
86
+ return;
87
+ }
88
+
89
+ if (isEnabled && !isCameraEnabled) {
90
+ Log.i(TAG,"start camera");
91
+ isCameraEnabled = true;
92
+ sodyoFragment.startCamera();
93
+ }
94
+
95
+ if (!isEnabled && isCameraEnabled) {
96
+ Log.i(TAG,"stop camera");
97
+ isCameraEnabled = false;
98
+ sodyoFragment.stopCamera();
99
+ }
100
+ }
79
101
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sodyo/react-native-sodyo-sdk",
3
- "version": "3.9.0",
3
+ "version": "3.9.1",
4
4
  "description": "RNSodyoSdk",
5
5
  "main": "sodyosdk.js",
6
6
  "typings": "./sodyosdk.d.ts",
package/sodyosdk.js CHANGED
@@ -183,11 +183,25 @@ export default {
183
183
  };
184
184
 
185
185
  export class Scanner extends Component {
186
+ static defaultProps = {
187
+ isEnabled: true,
188
+ isTroubleShootingEnabled: false,
189
+ };
190
+
191
+ componentDidUpdate(prevProps: Readonly<P>, prevState: Readonly<S>, snapshot: SS) {
192
+ if (this.props.isTroubleShootingEnabled) {
193
+ if (Platform.OS !== 'ios') {
194
+ return RNSodyoSdk.startTroubleshoot()
195
+ }
196
+ }
197
+ }
198
+
186
199
  render () {
187
- const { children, isTroubleShootingEnabled } = this.props;
200
+ const { isEnabled, isTroubleShootingEnabled, children } = this.props;
188
201
  return (
189
202
  <Fragment>
190
203
  <RNSodyoSdkView
204
+ isEnabled={isEnabled}
191
205
  isTroubleShootingEnabled={isTroubleShootingEnabled}
192
206
  style={{ height: '100%', width: '100%' }}
193
207
  />