@capgo/camera-preview 7.13.10 → 7.14.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.
@@ -7,6 +7,8 @@ import android.Manifest;
7
7
  import android.content.pm.ActivityInfo;
8
8
  import android.content.res.Configuration;
9
9
  import android.graphics.Color;
10
+ import android.graphics.drawable.ColorDrawable;
11
+ import android.graphics.drawable.Drawable;
10
12
  import android.location.Location;
11
13
  import android.util.DisplayMetrics;
12
14
  import android.util.Log;
@@ -116,6 +118,7 @@ public class CameraPreview
116
118
  private OrientationEventListener orientationListener;
117
119
  private int lastOrientation = Configuration.ORIENTATION_UNDEFINED;
118
120
  private boolean lastDisableAudio = true;
121
+ private Drawable originalWindowBackground;
119
122
 
120
123
  @PluginMethod
121
124
  public void getExposureModes(PluginCall call) {
@@ -379,6 +382,16 @@ public class CameraPreview
379
382
  cameraXView.stopSession();
380
383
  cameraXView = null;
381
384
  }
385
+ // Restore original window background if modified earlier
386
+ if (originalWindowBackground != null) {
387
+ try {
388
+ getBridge()
389
+ .getActivity()
390
+ .getWindow()
391
+ .setBackgroundDrawable(originalWindowBackground);
392
+ } catch (Exception ignored) {}
393
+ originalWindowBackground = null;
394
+ }
382
395
  call.resolve();
383
396
  });
384
397
  }
@@ -788,6 +801,22 @@ public class CameraPreview
788
801
  getBridge()
789
802
  .getActivity()
790
803
  .runOnUiThread(() -> {
804
+ // Ensure transparent background when preview is behind the WebView (Android 10 fix)
805
+ if (toBack) {
806
+ try {
807
+ if (originalWindowBackground == null) {
808
+ originalWindowBackground = getBridge()
809
+ .getActivity()
810
+ .getWindow()
811
+ .getDecorView()
812
+ .getBackground();
813
+ }
814
+ getBridge()
815
+ .getActivity()
816
+ .getWindow()
817
+ .setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
818
+ } catch (Exception ignored) {}
819
+ }
791
820
  DisplayMetrics metrics = getBridge()
792
821
  .getActivity()
793
822
  .getResources()
@@ -51,6 +51,7 @@ import androidx.camera.core.MeteringPoint;
51
51
  import androidx.camera.core.MeteringPointFactory;
52
52
  import androidx.camera.core.Preview;
53
53
  import androidx.camera.core.ResolutionInfo;
54
+ import androidx.camera.core.TorchState;
54
55
  import androidx.camera.core.UseCase;
55
56
  import androidx.camera.core.ZoomState;
56
57
  import androidx.camera.core.resolutionselector.AspectRatioStrategy;
@@ -2321,7 +2322,8 @@ public class CameraXView implements LifecycleOwner, LifecycleObserver {
2321
2322
  try {
2322
2323
  boolean hasFlash = camera.getCameraInfo().hasFlashUnit();
2323
2324
  if (hasFlash) {
2324
- return Arrays.asList("off", "on", "auto");
2325
+ // Include torch for devices with a flash unit
2326
+ return Arrays.asList("off", "on", "auto", "torch");
2325
2327
  } else {
2326
2328
  return Collections.singletonList("off");
2327
2329
  }
@@ -2332,6 +2334,16 @@ public class CameraXView implements LifecycleOwner, LifecycleObserver {
2332
2334
  }
2333
2335
 
2334
2336
  public String getFlashMode() {
2337
+ // If torch is enabled, report torch regardless of ImageCapture flash mode
2338
+ try {
2339
+ if (camera != null) {
2340
+ Integer torch = camera.getCameraInfo().getTorchState().getValue();
2341
+ if (torch != null && torch == TorchState.ON) {
2342
+ return "torch";
2343
+ }
2344
+ }
2345
+ } catch (Exception ignore) {}
2346
+
2335
2347
  switch (currentFlashMode) {
2336
2348
  case ImageCapture.FLASH_MODE_ON:
2337
2349
  return "on";
@@ -2343,6 +2355,35 @@ public class CameraXView implements LifecycleOwner, LifecycleObserver {
2343
2355
  }
2344
2356
 
2345
2357
  public void setFlashMode(String mode) {
2358
+ // Handle torch separately via CameraControl
2359
+ if ("torch".equals(mode)) {
2360
+ try {
2361
+ if (camera != null) {
2362
+ camera.getCameraControl().enableTorch(true);
2363
+ }
2364
+ } catch (Exception e) {
2365
+ Log.e(TAG, "setFlashMode: Failed to enable torch", e);
2366
+ }
2367
+ // Keep ImageCapture flash mode OFF to avoid conflicts with torch
2368
+ currentFlashMode = ImageCapture.FLASH_MODE_OFF;
2369
+ if (imageCapture != null) {
2370
+ imageCapture.setFlashMode(ImageCapture.FLASH_MODE_OFF);
2371
+ }
2372
+ if (sampleImageCapture != null) {
2373
+ sampleImageCapture.setFlashMode(ImageCapture.FLASH_MODE_OFF);
2374
+ }
2375
+ return;
2376
+ }
2377
+
2378
+ // For non-torch modes, ensure torch is disabled
2379
+ try {
2380
+ if (camera != null) {
2381
+ camera.getCameraControl().enableTorch(false);
2382
+ }
2383
+ } catch (Exception e) {
2384
+ Log.w(TAG, "setFlashMode: Failed to disable torch", e);
2385
+ }
2386
+
2346
2387
  int flashMode;
2347
2388
  switch (mode) {
2348
2389
  case "on":
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/camera-preview",
3
- "version": "7.13.10",
3
+ "version": "7.14.0",
4
4
  "description": "Camera preview",
5
5
  "license": "MIT",
6
6
  "repository": {