react-native-rectangle-doc-scanner 3.179.0 → 3.181.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.
@@ -146,6 +146,12 @@ class CameraController(
146
146
  Log.d(TAG, "[BIND] PreviewView attached to window: ${previewView.isAttachedToWindow}")
147
147
  Log.d(TAG, "[BIND] PreviewView size: ${previewView.width}x${previewView.height}")
148
148
  Log.d(TAG, "[BIND] PreviewView implementationMode: ${previewView.implementationMode}")
149
+
150
+ // Set surface provider FIRST, before binding - this is critical
151
+ Log.d(TAG, "[BIND] Setting surface provider BEFORE binding...")
152
+ preview.setSurfaceProvider(previewView.surfaceProvider)
153
+ Log.d(TAG, "[BIND] Surface provider set successfully")
154
+
149
155
  // Unbind all use cases before rebinding
150
156
  Log.d(TAG, "[BIND] Unbinding all existing use cases...")
151
157
  cameraProvider.unbindAll()
@@ -165,20 +171,6 @@ class CameraController(
165
171
  )
166
172
  Log.d(TAG, "[BIND] Bound to lifecycle successfully, camera: $camera")
167
173
 
168
- // Set surface provider AFTER binding for all modes
169
- // This ensures the camera is ready to receive the surface
170
- Log.d(TAG, "[BIND] Binding completed, now setting surface provider...")
171
- Log.d(TAG, "[BIND] PreviewView: $previewView")
172
- Log.d(TAG, "[BIND] PreviewView.surfaceProvider: ${previewView.surfaceProvider}")
173
- Log.d(TAG, "[BIND] PreviewView.implementationMode: ${previewView.implementationMode}")
174
-
175
- // Use postDelayed to ensure surface is ready (especially for SurfaceView)
176
- previewView.post {
177
- Log.d(TAG, "[BIND] Setting surface provider on UI thread...")
178
- preview.setSurfaceProvider(previewView.surfaceProvider)
179
- Log.d(TAG, "[BIND] Surface provider set successfully")
180
- }
181
-
182
174
  // Restore torch state if it was enabled
183
175
  if (torchEnabled) {
184
176
  Log.d(TAG, "[BIND] Restoring torch state...")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-rectangle-doc-scanner",
3
- "version": "3.179.0",
3
+ "version": "3.181.0",
4
4
  "description": "Native-backed document scanner for React Native with customizable overlays.",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
@@ -109,6 +109,14 @@ static inline void dispatch_async_main_queue(dispatch_block_t block)
109
109
  - (void)_foregroundMode
110
110
  {
111
111
  self.forceStop = NO;
112
+
113
+ // If the session was stopped while the app was backgrounded, bring it back
114
+ if (self.captureSession && !self.captureSession.isRunning) {
115
+ NSLog(@"[IPDFCameraViewController] Foreground - restarting capture session");
116
+ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
117
+ [self.captureSession startRunning];
118
+ });
119
+ }
112
120
  }
113
121
 
114
122
  - (void)dealloc
@@ -204,6 +212,17 @@ static inline void dispatch_async_main_queue(dispatch_block_t block)
204
212
  AVCaptureConnection *connection = [dataOutput.connections firstObject];
205
213
  [connection setVideoOrientation:AVCaptureVideoOrientationPortrait];
206
214
 
215
+ // Restart capture session automatically after media services/interruption events
216
+ [[NSNotificationCenter defaultCenter] addObserver:self
217
+ selector:@selector(handleSessionRuntimeError:)
218
+ name:AVCaptureSessionRuntimeErrorNotification
219
+ object:session];
220
+
221
+ [[NSNotificationCenter defaultCenter] addObserver:self
222
+ selector:@selector(handleSessionInterruptionEnded:)
223
+ name:AVCaptureSessionInterruptionEndedNotification
224
+ object:session];
225
+
207
226
  if (device.isFlashAvailable)
208
227
  {
209
228
  [device lockForConfiguration:nil];
@@ -221,6 +240,34 @@ static inline void dispatch_async_main_queue(dispatch_block_t block)
221
240
  [session commitConfiguration];
222
241
  }
223
242
 
243
+ - (void)handleSessionRuntimeError:(NSNotification *)notification
244
+ {
245
+ NSError *error = notification.userInfo[AVCaptureSessionErrorKey];
246
+ NSLog(@"[IPDFCameraViewController] Session runtime error: %@", error);
247
+
248
+ // Common case: AVErrorMediaServicesWereReset requires restarting the session
249
+ if (error.code == AVErrorMediaServicesWereReset) {
250
+ [self restartCaptureSession:@"Media services were reset"];
251
+ }
252
+ }
253
+
254
+ - (void)handleSessionInterruptionEnded:(NSNotification *)notification
255
+ {
256
+ [self restartCaptureSession:@"Interruption ended"];
257
+ }
258
+
259
+ - (void)restartCaptureSession:(NSString *)reason
260
+ {
261
+ if (!self.captureSession || self.captureSession.isRunning) {
262
+ return;
263
+ }
264
+
265
+ NSLog(@"[IPDFCameraViewController] Restarting capture session (%@)", reason);
266
+ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
267
+ [self.captureSession startRunning];
268
+ });
269
+ }
270
+
224
271
  - (void)setCameraViewType:(IPDFCameraViewType)cameraViewType
225
272
  {
226
273
  UIBlurEffect * effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];