@capgo/camera-preview 8.2.0 → 8.2.2

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.
File without changes
@@ -0,0 +1,2 @@
1
+ #Tue Jan 27 22:56:21 WET 2026
2
+ gradle.version=8.14.4
File without changes
@@ -30,7 +30,7 @@ android {
30
30
  buildTypes {
31
31
  release {
32
32
  minifyEnabled false
33
- proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
33
+ proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
34
34
  }
35
35
  }
36
36
  lintOptions {
@@ -268,7 +268,11 @@ public class CameraXView implements LifecycleOwner, LifecycleObserver {
268
268
  this.lifecycleRegistry = new LifecycleRegistry(this);
269
269
  this.mainExecutor = ContextCompat.getMainExecutor(context);
270
270
 
271
- mainExecutor.execute(() -> lifecycleRegistry.setCurrentState(Lifecycle.State.CREATED));
271
+ mainExecutor.execute(() -> {
272
+ if (lifecycleRegistry.getCurrentState() != Lifecycle.State.DESTROYED) {
273
+ lifecycleRegistry.setCurrentState(Lifecycle.State.CREATED);
274
+ }
275
+ });
272
276
  }
273
277
 
274
278
  @NonNull
@@ -390,36 +394,91 @@ public class CameraXView implements LifecycleOwner, LifecycleObserver {
390
394
  }
391
395
 
392
396
  public void startSession(CameraSessionConfiguration config) {
393
- this.sessionConfig = config;
394
- cameraExecutor = Executors.newSingleThreadExecutor();
395
-
396
- // Reset cached orientation so we don't reuse stale values across sessions
397
- synchronized (accelerometerLock) {
398
- lastAccelerometerValues[0] = 0f;
399
- lastAccelerometerValues[1] = 0f;
400
- lastAccelerometerValues[2] = 0f;
401
- }
402
- lastCaptureRotation = -1;
403
-
404
- // Start accelerometer for orientation detection regardless of lock
405
- if (sensorManager == null) {
406
- sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
407
- accelerometer = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
408
- rotationVectorSensor = sensorManager.getDefaultSensor(Sensor.TYPE_ROTATION_VECTOR);
409
- }
410
- if (accelerometer != null) {
411
- sensorManager.registerListener(accelerometerListener, accelerometer, SensorManager.SENSOR_DELAY_UI);
412
- }
413
- if (rotationVectorSensor != null) {
414
- sensorManager.registerListener(rotationVectorListener, rotationVectorSensor, SensorManager.SENSOR_DELAY_NORMAL);
415
- }
416
- lastCompassHeading = -1f;
417
- synchronized (operationLock) {
418
- activeOperations = 0;
419
- stopPending = false;
420
- }
421
397
  mainExecutor.execute(() -> {
398
+ // Stop may run first (e.g. activity pause) and move the registry to DESTROYED while this
399
+ // runnable is still queued — never transition backward from DESTROYED.
400
+ if (lifecycleRegistry.getCurrentState() == Lifecycle.State.DESTROYED) {
401
+ if (listener != null) {
402
+ listener.onCameraStartError("Camera start aborted: lifecycle destroyed");
403
+ }
404
+ return;
405
+ }
406
+ if (stopRequested) {
407
+ if (listener != null) {
408
+ listener.onCameraStartError("Camera start aborted: stop requested");
409
+ }
410
+ return;
411
+ }
412
+ Lifecycle.State state = lifecycleRegistry.getCurrentState();
413
+ if (state == Lifecycle.State.INITIALIZED) {
414
+ lifecycleRegistry.setCurrentState(Lifecycle.State.CREATED);
415
+ if (lifecycleRegistry.getCurrentState() == Lifecycle.State.DESTROYED) {
416
+ if (listener != null) {
417
+ listener.onCameraStartError("Camera start aborted: lifecycle destroyed");
418
+ }
419
+ return;
420
+ }
421
+ if (stopRequested) {
422
+ if (listener != null) {
423
+ listener.onCameraStartError("Camera start aborted: stop requested");
424
+ }
425
+ return;
426
+ }
427
+ }
428
+ if (lifecycleRegistry.getCurrentState() == Lifecycle.State.DESTROYED) {
429
+ if (listener != null) {
430
+ listener.onCameraStartError("Camera start aborted: lifecycle destroyed");
431
+ }
432
+ return;
433
+ }
434
+ if (stopRequested) {
435
+ if (listener != null) {
436
+ listener.onCameraStartError("Camera start aborted: stop requested");
437
+ }
438
+ return;
439
+ }
422
440
  lifecycleRegistry.setCurrentState(Lifecycle.State.STARTED);
441
+ if (lifecycleRegistry.getCurrentState() == Lifecycle.State.DESTROYED) {
442
+ if (listener != null) {
443
+ listener.onCameraStartError("Camera start aborted: lifecycle destroyed");
444
+ }
445
+ return;
446
+ }
447
+ if (stopRequested) {
448
+ if (listener != null) {
449
+ listener.onCameraStartError("Camera start aborted: stop requested");
450
+ }
451
+ return;
452
+ }
453
+
454
+ this.sessionConfig = config;
455
+ cameraExecutor = Executors.newSingleThreadExecutor();
456
+
457
+ // Reset cached orientation so we don't reuse stale values across sessions
458
+ synchronized (accelerometerLock) {
459
+ lastAccelerometerValues[0] = 0f;
460
+ lastAccelerometerValues[1] = 0f;
461
+ lastAccelerometerValues[2] = 0f;
462
+ }
463
+ lastCaptureRotation = -1;
464
+
465
+ // Start accelerometer for orientation detection regardless of lock
466
+ if (sensorManager == null) {
467
+ sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
468
+ accelerometer = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
469
+ rotationVectorSensor = sensorManager.getDefaultSensor(Sensor.TYPE_ROTATION_VECTOR);
470
+ }
471
+ if (accelerometer != null) {
472
+ sensorManager.registerListener(accelerometerListener, accelerometer, SensorManager.SENSOR_DELAY_UI);
473
+ }
474
+ if (rotationVectorSensor != null) {
475
+ sensorManager.registerListener(rotationVectorListener, rotationVectorSensor, SensorManager.SENSOR_DELAY_NORMAL);
476
+ }
477
+ lastCompassHeading = -1f;
478
+ synchronized (operationLock) {
479
+ activeOperations = 0;
480
+ stopPending = false;
481
+ }
423
482
  setupCamera();
424
483
  });
425
484
  }
@@ -483,7 +542,6 @@ public class CameraXView implements LifecycleOwner, LifecycleObserver {
483
542
  if (cameraProvider != null) {
484
543
  cameraProvider.unbindAll();
485
544
  }
486
- lifecycleRegistry.setCurrentState(Lifecycle.State.DESTROYED);
487
545
  if (cameraExecutor != null) {
488
546
  cameraExecutor.shutdown();
489
547
  }
@@ -527,7 +585,31 @@ public class CameraXView implements LifecycleOwner, LifecycleObserver {
527
585
  cameraProviderFuture.addListener(
528
586
  () -> {
529
587
  try {
588
+ if (lifecycleRegistry.getCurrentState() == Lifecycle.State.DESTROYED) {
589
+ if (listener != null) {
590
+ listener.onCameraStartError("Camera binding cancelled: lifecycle destroyed (before provider)");
591
+ }
592
+ return;
593
+ }
594
+ if (stopRequested) {
595
+ if (listener != null) {
596
+ listener.onCameraStartError("Camera binding cancelled: stop requested (before provider)");
597
+ }
598
+ return;
599
+ }
530
600
  cameraProvider = cameraProviderFuture.get();
601
+ if (lifecycleRegistry.getCurrentState() == Lifecycle.State.DESTROYED) {
602
+ if (listener != null) {
603
+ listener.onCameraStartError("Camera binding cancelled: lifecycle destroyed (after provider)");
604
+ }
605
+ return;
606
+ }
607
+ if (stopRequested) {
608
+ if (listener != null) {
609
+ listener.onCameraStartError("Camera binding cancelled: stop requested (after provider)");
610
+ }
611
+ return;
612
+ }
531
613
  setupPreviewView();
532
614
  bindCameraUseCases();
533
615
  } catch (Exception e) {
@@ -34,7 +34,7 @@ extension UIWindow {
34
34
  */
35
35
  @objc(CameraPreview)
36
36
  public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelegate {
37
- private let pluginVersion: String = "8.2.0"
37
+ private let pluginVersion: String = "8.2.2"
38
38
  public let identifier = "CameraPreviewPlugin"
39
39
  public let jsName = "CameraPreview"
40
40
  public let pluginMethods: [CAPPluginMethod] = [
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@capgo/camera-preview",
3
- "version": "8.2.0",
3
+ "version": "8.2.2",
4
4
  "description": "Camera preview",
5
5
  "license": "MPL-2.0",
6
6
  "repository": {
7
7
  "type": "git",
8
- "url": "https://github.com/Cap-go/capacitor-camera-preview"
8
+ "url": "git+https://github.com/Cap-go/capacitor-camera-preview.git"
9
9
  },
10
10
  "bugs": {
11
11
  "url": "https://github.com/Cap-go/capacitor-camera-preview/issues"