react-native-rectangle-doc-scanner 3.131.0 → 3.132.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.
|
@@ -43,18 +43,11 @@ class DocumentScannerModule(reactContext: ReactApplicationContext) :
|
|
|
43
43
|
val view = uiManager.resolveView(tag)
|
|
44
44
|
|
|
45
45
|
if (view is DocumentScannerView) {
|
|
46
|
-
Log.d(TAG, "Found DocumentScannerView, triggering capture")
|
|
47
|
-
|
|
48
|
-
//
|
|
49
|
-
//
|
|
50
|
-
view.
|
|
51
|
-
|
|
52
|
-
// Note: In the current implementation, we use events (onPictureTaken)
|
|
53
|
-
// iOS also uses events for the main flow, but has a promise-based method too
|
|
54
|
-
// For consistency with the event-based approach, resolve immediately
|
|
55
|
-
promise.resolve(Arguments.createMap().apply {
|
|
56
|
-
putString("status", "capturing")
|
|
57
|
-
})
|
|
46
|
+
Log.d(TAG, "Found DocumentScannerView, triggering capture with promise")
|
|
47
|
+
|
|
48
|
+
// Pass promise to view so it can be resolved when capture completes
|
|
49
|
+
// This matches iOS behavior where promise is resolved with actual image data
|
|
50
|
+
view.captureWithPromise(promise)
|
|
58
51
|
} else {
|
|
59
52
|
Log.e(TAG, "View with tag $tag is not DocumentScannerView: ${view?.javaClass?.simpleName}")
|
|
60
53
|
promise.reject("INVALID_VIEW", "View is not a DocumentScannerView")
|
|
@@ -153,13 +153,22 @@ class DocumentScannerView(context: ThemedReactContext) : FrameLayout(context) {
|
|
|
153
153
|
}
|
|
154
154
|
|
|
155
155
|
fun capture() {
|
|
156
|
+
captureWithPromise(null)
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Capture image with promise support (matches iOS captureWithResolver:rejecter:)
|
|
161
|
+
* @param promise Optional promise to resolve with capture result
|
|
162
|
+
*/
|
|
163
|
+
fun captureWithPromise(promise: com.facebook.react.bridge.Promise?) {
|
|
156
164
|
if (isCapturing) {
|
|
157
165
|
Log.d(TAG, "Already capturing, ignoring request")
|
|
166
|
+
promise?.reject("CAPTURE_IN_PROGRESS", "Capture already in progress")
|
|
158
167
|
return
|
|
159
168
|
}
|
|
160
169
|
|
|
161
170
|
isCapturing = true
|
|
162
|
-
Log.d(TAG, "Capture initiated")
|
|
171
|
+
Log.d(TAG, "Capture initiated with promise: ${promise != null}")
|
|
163
172
|
|
|
164
173
|
val outputDir = if (saveInAppDocument) {
|
|
165
174
|
context.filesDir
|
|
@@ -171,18 +180,23 @@ class DocumentScannerView(context: ThemedReactContext) : FrameLayout(context) {
|
|
|
171
180
|
outputDirectory = outputDir,
|
|
172
181
|
onImageCaptured = { file ->
|
|
173
182
|
scope.launch {
|
|
174
|
-
processAndEmitImage(file)
|
|
183
|
+
processAndEmitImage(file, promise)
|
|
175
184
|
}
|
|
176
185
|
},
|
|
177
186
|
onError = { exception ->
|
|
178
187
|
Log.e(TAG, "Capture failed", exception)
|
|
179
188
|
isCapturing = false
|
|
189
|
+
|
|
190
|
+
// Reject promise if provided
|
|
191
|
+
promise?.reject("CAPTURE_FAILED", "Failed to capture image", exception)
|
|
192
|
+
|
|
193
|
+
// Also send event for backwards compatibility
|
|
180
194
|
sendErrorEvent("capture_failed")
|
|
181
195
|
}
|
|
182
196
|
)
|
|
183
197
|
}
|
|
184
198
|
|
|
185
|
-
private suspend fun processAndEmitImage(imageFile: File) = withContext(Dispatchers.IO) {
|
|
199
|
+
private suspend fun processAndEmitImage(imageFile: File, promise: com.facebook.react.bridge.Promise? = null) = withContext(Dispatchers.IO) {
|
|
186
200
|
try {
|
|
187
201
|
// Detect rectangle in captured image
|
|
188
202
|
val bitmap = BitmapFactory.decodeFile(imageFile.absolutePath)
|
|
@@ -229,7 +243,14 @@ class DocumentScannerView(context: ThemedReactContext) : FrameLayout(context) {
|
|
|
229
243
|
}
|
|
230
244
|
|
|
231
245
|
withContext(Dispatchers.Main) {
|
|
246
|
+
Log.d(TAG, "Processing completed, resolving promise: ${promise != null}")
|
|
247
|
+
|
|
248
|
+
// Resolve promise first (if provided) - matches iOS behavior
|
|
249
|
+
promise?.resolve(result)
|
|
250
|
+
|
|
251
|
+
// Then send event for backwards compatibility
|
|
232
252
|
sendPictureTakenEvent(result)
|
|
253
|
+
|
|
233
254
|
isCapturing = false
|
|
234
255
|
|
|
235
256
|
if (!captureMultiple) {
|
|
@@ -239,6 +260,10 @@ class DocumentScannerView(context: ThemedReactContext) : FrameLayout(context) {
|
|
|
239
260
|
} catch (e: Exception) {
|
|
240
261
|
Log.e(TAG, "Failed to process image", e)
|
|
241
262
|
withContext(Dispatchers.Main) {
|
|
263
|
+
// Reject promise if provided
|
|
264
|
+
promise?.reject("PROCESSING_FAILED", "Failed to process image: ${e.message}", e)
|
|
265
|
+
|
|
266
|
+
// Also send error event for backwards compatibility
|
|
242
267
|
sendErrorEvent("processing_failed")
|
|
243
268
|
isCapturing = false
|
|
244
269
|
}
|
package/package.json
CHANGED