react-native-rectangle-doc-scanner 3.147.0 → 3.149.0

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.
@@ -99,9 +99,10 @@ class CameraView(context: Context) : FrameLayout(context), LifecycleOwner {
99
99
  * Bind camera use cases
100
100
  */
101
101
  private fun bindCamera() {
102
- val lifecycleOwner = when (context) {
103
- is LifecycleOwner -> context as LifecycleOwner
104
- is ThemedReactContext -> context.currentActivity as? LifecycleOwner ?: context as? LifecycleOwner
102
+ val ctx = context
103
+ val lifecycleOwner = when {
104
+ ctx is LifecycleOwner -> ctx
105
+ ctx is ThemedReactContext -> ctx.currentActivity as? LifecycleOwner ?: ctx as? LifecycleOwner
105
106
  else -> null
106
107
  }
107
108
  if (lifecycleOwner == null) {
@@ -207,13 +208,14 @@ class CameraView(context: Context) : FrameLayout(context), LifecycleOwner {
207
208
  onRectangleDetected?.invoke(transformedRectangle)
208
209
  }
209
210
  } catch (e: Exception) {
210
- Log.e(TAG, "Failed to analyze frame", e)
211
- post {
212
- overlayView.setDetectedRectangle(null)
213
- onRectangleDetected?.invoke(null)
211
+ Log.e(TAG, "Failed to analyze frame", e)
212
+ post {
213
+ overlayView.setDetectedRectangle(null)
214
+ onRectangleDetected?.invoke(null)
215
+ }
216
+ } finally {
217
+ imageProxy.close()
214
218
  }
215
- } finally {
216
- imageProxy.close()
217
219
  }
218
220
  }
219
221
 
@@ -225,7 +227,6 @@ class CameraView(context: Context) : FrameLayout(context), LifecycleOwner {
225
227
  cameraExecutor.shutdown()
226
228
  }
227
229
  }
228
- }
229
230
 
230
231
  /**
231
232
  * Overlay view for grid and rectangle
@@ -10,7 +10,7 @@ import com.facebook.react.uimanager.annotations.ReactProp
10
10
  class DocumentScannerViewManager : SimpleViewManager<DocumentScannerView>() {
11
11
 
12
12
  companion object {
13
- const val REACT_CLASS = "RNPdfScannerManager"
13
+ const val REACT_CLASS = "RNPdfScanner"
14
14
  }
15
15
 
16
16
  override fun getName() = REACT_CLASS
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-rectangle-doc-scanner",
3
- "version": "3.147.0",
3
+ "version": "3.149.0",
4
4
  "description": "Native-backed document scanner for React Native with customizable overlays.",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
@@ -79,21 +79,42 @@ class PdfScanner extends React.Component {
79
79
  return;
80
80
  }
81
81
  try {
82
- const granted = await PermissionsAndroid.requestMultiple([
82
+ const requestedPermissions = [
83
83
  PermissionsAndroid.PERMISSIONS.CAMERA,
84
- PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE,
85
- PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE,
86
- ]);
84
+ ];
85
+
86
+ const isTiramisuOrNewer = Platform.Version >= 33;
87
+
88
+ if (isTiramisuOrNewer) {
89
+ // Android 13+: storage permissions split by media type. Request images access.
90
+ if (PermissionsAndroid.PERMISSIONS.READ_MEDIA_IMAGES) {
91
+ requestedPermissions.push(PermissionsAndroid.PERMISSIONS.READ_MEDIA_IMAGES);
92
+ }
93
+ } else {
94
+ if (PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE) {
95
+ requestedPermissions.push(PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE);
96
+ }
97
+ if (PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE) {
98
+ requestedPermissions.push(PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE);
99
+ }
100
+ }
101
+
102
+ const granted = await PermissionsAndroid.requestMultiple(requestedPermissions);
87
103
 
88
104
  const cameraGranted =
89
105
  granted['android.permission.CAMERA'] ===
90
106
  PermissionsAndroid.RESULTS.GRANTED;
91
- const readGranted =
92
- granted['android.permission.READ_EXTERNAL_STORAGE'] ===
93
- PermissionsAndroid.RESULTS.GRANTED;
94
- const writeGranted =
95
- granted['android.permission.WRITE_EXTERNAL_STORAGE'] ===
96
- PermissionsAndroid.RESULTS.GRANTED;
107
+
108
+ const readGranted = isTiramisuOrNewer
109
+ ? granted['android.permission.READ_MEDIA_IMAGES'] === PermissionsAndroid.RESULTS.GRANTED ||
110
+ granted['android.permission.READ_MEDIA_IMAGES'] === undefined
111
+ : granted['android.permission.READ_EXTERNAL_STORAGE'] === PermissionsAndroid.RESULTS.GRANTED ||
112
+ granted['android.permission.READ_EXTERNAL_STORAGE'] === undefined;
113
+
114
+ const writeGranted = isTiramisuOrNewer
115
+ ? true // WRITE_EXTERNAL_STORAGE is deprecated on API 33+
116
+ : granted['android.permission.WRITE_EXTERNAL_STORAGE'] === PermissionsAndroid.RESULTS.GRANTED ||
117
+ granted['android.permission.WRITE_EXTERNAL_STORAGE'] === undefined;
97
118
 
98
119
  if (cameraGranted && readGranted && writeGranted) {
99
120
  this.setState({ permissionsAuthorized: true });