capacitor-camera-view 3.0.2 → 3.0.3

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.
@@ -73,6 +73,21 @@ internal let SUPPORTED_CAMERA_DEVICE_TYPES: [AVCaptureDevice.DeviceType] = [
73
73
  /// session-queue callers that drive session setup/teardown.
74
74
  internal var webView: UIView?
75
75
 
76
+ /// The presentation properties `revealPreview` overwrites to make the host
77
+ /// WebView see-through.
78
+ private struct WebViewPresentationState {
79
+ let isOpaque: Bool
80
+ let backgroundColor: UIColor?
81
+ let scrollViewBackgroundColor: UIColor?
82
+ }
83
+
84
+ /// The host WebView's presentation state as it was before `revealPreview`
85
+ /// made it transparent, restored on teardown so the app is not left with a
86
+ /// see-through WebView (and the window showing through) for the rest of its
87
+ /// lifetime. `nil` while no session has revealed the preview. Confined to
88
+ /// the main queue like `webView` itself.
89
+ private var webViewPresentationState: WebViewPresentationState?
90
+
76
91
  /// Whether the session was explicitly stopped via `stopSession`, as opposed
77
92
  /// to being paused by backgrounding or an interruption. Confined to
78
93
  /// `sessionQueue` (set at the top of `startSession`'s and `stopSession`'s
@@ -342,8 +357,7 @@ internal let SUPPORTED_CAMERA_DEVICE_TYPES: [AVCaptureDevice.DeviceType] = [
342
357
  return
343
358
  }
344
359
  self.videoPreviewLayer.removeFromSuperlayer()
345
- self.webView?.isOpaque = true
346
- self.webView?.backgroundColor = nil
360
+ self.restoreWebViewPresentationState()
347
361
  self.webView = nil
348
362
 
349
363
  // Release rotation state so a stopped session doesn't keep the
@@ -890,9 +904,21 @@ internal let SUPPORTED_CAMERA_DEVICE_TYPES: [AVCaptureDevice.DeviceType] = [
890
904
  /// Makes the WebView transparent so the attached preview layer becomes
891
905
  /// visible. Called once the session is running, so the app's own UI stays
892
906
  /// visible while the camera powers up.
907
+ ///
908
+ /// The overwritten presentation properties are snapshotted first — only
909
+ /// once, so a reveal on an already-transparent WebView cannot capture the
910
+ /// transparent state as the one to restore.
893
911
  private func revealPreview() {
894
912
  DispatchQueue.main.async { [weak self] in
895
- guard let view = self?.webView else { return }
913
+ guard let self = self, let view = self.webView else { return }
914
+
915
+ if self.webViewPresentationState == nil {
916
+ self.webViewPresentationState = WebViewPresentationState(
917
+ isOpaque: view.isOpaque,
918
+ backgroundColor: view.backgroundColor,
919
+ scrollViewBackgroundColor: (view as? WKWebView)?.scrollView.backgroundColor
920
+ )
921
+ }
896
922
 
897
923
  view.isOpaque = false
898
924
  view.backgroundColor = UIColor.clear
@@ -900,4 +926,19 @@ internal let SUPPORTED_CAMERA_DEVICE_TYPES: [AVCaptureDevice.DeviceType] = [
900
926
  }
901
927
  }
902
928
 
929
+ /// Restores the presentation state `revealPreview` snapshotted, undoing the
930
+ /// transparency on teardown. Capacitor's own background color is whatever
931
+ /// the snapshot holds, so it is restored rather than guessed. A no-op
932
+ /// without a snapshot, so tearing down a session that never revealed the
933
+ /// preview leaves the WebView alone. Must be called on the main queue.
934
+ private func restoreWebViewPresentationState() {
935
+ guard let state = webViewPresentationState else { return }
936
+
937
+ webView?.isOpaque = state.isOpaque
938
+ webView?.backgroundColor = state.backgroundColor
939
+ (webView as? WKWebView)?.scrollView.backgroundColor = state.scrollViewBackgroundColor
940
+
941
+ webViewPresentationState = nil
942
+ }
943
+
903
944
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "capacitor-camera-view",
3
- "version": "3.0.2",
3
+ "version": "3.0.3",
4
4
  "description": "A Capacitor plugin for embedding a live camera feed directly into your app.",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",