rn-document-scanner-vision 1.0.8 → 1.0.10

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.
@@ -4,7 +4,7 @@ buildscript {
4
4
  mavenCentral()
5
5
  }
6
6
  dependencies {
7
- classpath 'com.android.tools.build:gradle:8.4.2'
7
+ classpath 'com.android.tools.build:gradle:7.2.2'
8
8
  }
9
9
  }
10
10
 
@@ -15,13 +15,9 @@ def safeExtGet(prop, fallback) {
15
15
  }
16
16
 
17
17
  def resolveReactNativeDirectory() {
18
- // Try multiple possible locations for react-native
19
18
  def locations = [
20
- // When used as a dependency in another project
21
19
  "${rootProject.projectDir}/../node_modules/react-native/android",
22
- // Fallback for monorepos
23
20
  "${rootProject.projectDir}/../../node_modules/react-native/android",
24
- // Direct parent node_modules
25
21
  new File(projectDir, "../../../node_modules/react-native/android").canonicalPath
26
22
  ]
27
23
 
@@ -38,14 +34,10 @@ repositories {
38
34
  google()
39
35
  mavenCentral()
40
36
 
41
- // React Native's maven repository
42
37
  def reactNativeDir = resolveReactNativeDirectory()
43
38
  if (reactNativeDir != null) {
44
39
  maven { url reactNativeDir }
45
40
  }
46
-
47
- // Maven Central hosts react-android for newer RN versions
48
- maven { url "https://repo1.maven.org/maven2/" }
49
41
  }
50
42
 
51
43
  android {
@@ -68,10 +60,8 @@ android {
68
60
  }
69
61
 
70
62
  compileOptions {
71
- // Use Java version from host project, fallback to 11 for compatibility
72
- def javaVersion = safeExtGet('javaVersion', JavaVersion.VERSION_11)
73
- sourceCompatibility javaVersion
74
- targetCompatibility javaVersion
63
+ sourceCompatibility JavaVersion.VERSION_11
64
+ targetCompatibility JavaVersion.VERSION_11
75
65
  }
76
66
 
77
67
  lint {
@@ -80,10 +70,11 @@ android {
80
70
  }
81
71
 
82
72
  dependencies {
83
- // Use compileOnly for react-android to avoid bundling React Native
84
- // The host app will provide the React Native runtime at build time
85
- compileOnly "com.facebook.react:react-android:+"
73
+ // For React Native < 0.71, use react-native from local maven
74
+ // For React Native >= 0.71, use react-android
75
+ // compileOnly ensures the host app provides React Native at runtime
76
+ compileOnly "com.facebook.react:react-native:+"
86
77
 
87
- implementation "androidx.appcompat:appcompat:1.7.0"
78
+ implementation "androidx.appcompat:appcompat:1.6.1"
88
79
  implementation "com.websitebeaver:documentscanner:1.3.4"
89
80
  }
@@ -2,7 +2,6 @@ package com.rndocumentscanner;
2
2
 
3
3
  import android.app.Activity;
4
4
  import android.content.Intent;
5
- import androidx.activity.result.ActivityResult;
6
5
 
7
6
  import com.facebook.react.bridge.ActivityEventListener;
8
7
  import com.facebook.react.bridge.Arguments;
@@ -15,7 +14,6 @@ import com.facebook.react.bridge.ReadableMap;
15
14
  import com.facebook.react.bridge.WritableArray;
16
15
  import com.facebook.react.bridge.WritableMap;
17
16
 
18
- import com.websitebeaver.documentscanner.DocumentScanner;
19
17
  import com.websitebeaver.documentscanner.constants.DocumentScannerExtra;
20
18
 
21
19
  import java.util.ArrayList;
@@ -24,17 +22,57 @@ public class RNDocumentScannerModule extends ReactContextBaseJavaModule {
24
22
 
25
23
  private static final int DOCUMENT_SCAN_REQUEST = 1;
26
24
  private Promise scanPromise;
27
- private DocumentScanner documentScanner;
25
+ private String responseType = "imageFilePath";
28
26
 
29
27
  private final ActivityEventListener activityEventListener = new BaseActivityEventListener() {
30
28
  @Override
31
29
  public void onActivityResult(Activity activity, int requestCode, int resultCode, Intent data) {
32
30
  if (requestCode == DOCUMENT_SCAN_REQUEST) {
33
- if (documentScanner != null) {
34
- // Use a wrapper ActivityResult object
35
- ActivityResult result = new ActivityResult(resultCode, data);
36
- documentScanner.handleDocumentScanIntentResult(result);
31
+ if (scanPromise == null) {
32
+ return;
37
33
  }
34
+
35
+ if (resultCode == Activity.RESULT_OK && data != null) {
36
+ // Get the scanned document results
37
+ ArrayList<String> croppedImageResults = data.getStringArrayListExtra(
38
+ DocumentScannerExtra.EXTRA_CROPPED_IMAGE_RESULTS
39
+ );
40
+
41
+ if (croppedImageResults != null && !croppedImageResults.isEmpty()) {
42
+ WritableMap response = Arguments.createMap();
43
+ WritableArray scannedImages = Arguments.createArray();
44
+
45
+ for (String imagePath : croppedImageResults) {
46
+ scannedImages.pushString(imagePath);
47
+ }
48
+
49
+ response.putArray("scannedImages", scannedImages);
50
+ response.putString("status", "success");
51
+ scanPromise.resolve(response);
52
+ } else {
53
+ // No images returned
54
+ WritableMap response = Arguments.createMap();
55
+ WritableArray emptyArray = Arguments.createArray();
56
+ response.putArray("scannedImages", emptyArray);
57
+ response.putString("status", "cancel");
58
+ scanPromise.resolve(response);
59
+ }
60
+ } else if (resultCode == Activity.RESULT_CANCELED) {
61
+ // User cancelled
62
+ WritableMap response = Arguments.createMap();
63
+ WritableArray emptyArray = Arguments.createArray();
64
+ response.putArray("scannedImages", emptyArray);
65
+ response.putString("status", "cancel");
66
+ scanPromise.resolve(response);
67
+ } else {
68
+ // Check for error
69
+ String errorMessage = data != null ?
70
+ data.getStringExtra(DocumentScannerExtra.EXTRA_ERROR_MESSAGE) :
71
+ "Unknown error";
72
+ scanPromise.reject("SCAN_ERROR", errorMessage != null ? errorMessage : "Document scan failed");
73
+ }
74
+
75
+ scanPromise = null;
38
76
  }
39
77
  }
40
78
  };
@@ -52,7 +90,7 @@ public class RNDocumentScannerModule extends ReactContextBaseJavaModule {
52
90
  @ReactMethod
53
91
  public void scanDocument(ReadableMap options, Promise promise) {
54
92
  Activity activity = getCurrentActivity();
55
-
93
+
56
94
  if (activity == null) {
57
95
  promise.reject("NO_ACTIVITY", "Activity doesn't exist");
58
96
  return;
@@ -61,66 +99,27 @@ public class RNDocumentScannerModule extends ReactContextBaseJavaModule {
61
99
  scanPromise = promise;
62
100
 
63
101
  // Get options with defaults
64
- String responseType = options.hasKey("responseType") ? options.getString("responseType") : "imageFilePath";
102
+ responseType = options.hasKey("responseType") ? options.getString("responseType") : "imageFilePath";
65
103
  Boolean letUserAdjustCrop = options.hasKey("letUserAdjustCrop") ? options.getBoolean("letUserAdjustCrop") : true;
66
104
  Integer maxNumDocuments = options.hasKey("maxNumDocuments") ? options.getInt("maxNumDocuments") : 1;
67
105
  Integer croppedImageQuality = options.hasKey("croppedImageQuality") ? options.getInt("croppedImageQuality") : 100;
68
106
 
69
107
  try {
70
- // Create document scanner with callbacks
71
- documentScanner = new DocumentScanner(
72
- activity,
73
- (ArrayList<String> documentScanResults) -> {
74
- // Success callback
75
- WritableMap response = Arguments.createMap();
76
- WritableArray scannedImages = Arguments.createArray();
77
-
78
- for (String imagePath : documentScanResults) {
79
- scannedImages.pushString(imagePath);
80
- }
81
-
82
- response.putArray("scannedImages", scannedImages);
83
- response.putString("status", "success");
84
-
85
- if (scanPromise != null) {
86
- scanPromise.resolve(response);
87
- scanPromise = null;
88
- }
89
- return null;
90
- },
91
- (String errorMessage) -> {
92
- // Error callback
93
- if (scanPromise != null) {
94
- scanPromise.reject("SCAN_ERROR", errorMessage);
95
- scanPromise = null;
96
- }
97
- return null;
98
- },
99
- () -> {
100
- // Cancel callback
101
- WritableMap response = Arguments.createMap();
102
- WritableArray emptyArray = Arguments.createArray();
103
- response.putArray("scannedImages", emptyArray);
104
- response.putString("status", "cancel");
105
-
106
- if (scanPromise != null) {
107
- scanPromise.resolve(response);
108
- scanPromise = null;
109
- }
110
- return null;
111
- },
112
- responseType,
113
- letUserAdjustCrop,
114
- maxNumDocuments,
115
- croppedImageQuality
116
- );
117
-
118
- // Launch the document scanner
119
- Intent scanIntent = documentScanner.createDocumentScanIntent();
108
+ // Create intent directly for DocumentScannerActivity
109
+ Intent scanIntent = new Intent(activity, com.websitebeaver.documentscanner.DocumentScannerActivity.class);
110
+
111
+ // Set extras
112
+ scanIntent.putExtra(DocumentScannerExtra.EXTRA_LET_USER_ADJUST_CROP, letUserAdjustCrop);
113
+ scanIntent.putExtra(DocumentScannerExtra.EXTRA_MAX_NUM_DOCUMENTS, maxNumDocuments);
114
+ scanIntent.putExtra(DocumentScannerExtra.EXTRA_CROPPED_IMAGE_QUALITY, croppedImageQuality);
115
+ scanIntent.putExtra(DocumentScannerExtra.EXTRA_RESPONSE_TYPE, responseType);
116
+
117
+ // Launch the document scanner activity
120
118
  activity.startActivityForResult(scanIntent, DOCUMENT_SCAN_REQUEST);
121
119
 
122
120
  } catch (Exception e) {
123
121
  promise.reject("INITIALIZATION_ERROR", "Failed to initialize document scanner: " + e.getMessage());
122
+ scanPromise = null;
124
123
  }
125
124
  }
126
125
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rn-document-scanner-vision",
3
- "version": "1.0.8",
3
+ "version": "1.0.10",
4
4
  "description": "A React Native library for scanning documents on iOS and Android",
5
5
  "main": "lib/commonjs/index.js",
6
6
  "module": "lib/module/index.js",