@capgo/camera-preview 7.25.0 → 7.26.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.
|
@@ -3,5 +3,5 @@
|
|
|
3
3
|
<uses-permission android:name="android.permission.CAMERA" />
|
|
4
4
|
<uses-permission android:name="android.permission.RECORD_AUDIO" />
|
|
5
5
|
<uses-feature android:name="android.hardware.camera" />
|
|
6
|
-
<uses-feature android:name="android.hardware.camera.autofocus" />
|
|
6
|
+
<uses-feature android:required="false" android:name="android.hardware.camera.autofocus" />
|
|
7
7
|
</manifest>
|
|
@@ -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 = "7.
|
|
37
|
+
private let pluginVersion: String = "7.26.0"
|
|
38
38
|
public let identifier = "CameraPreviewPlugin"
|
|
39
39
|
public let jsName = "CameraPreview"
|
|
40
40
|
public let pluginMethods: [CAPPluginMethod] = [
|
|
@@ -106,6 +106,10 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
|
|
|
106
106
|
private var waitingForLocation: Bool = false
|
|
107
107
|
private var isPresentingPermissionAlert: Bool = false
|
|
108
108
|
|
|
109
|
+
// Store original webview colors to restore them when stopping
|
|
110
|
+
private var originalWebViewBackgroundColor: UIColor?
|
|
111
|
+
private var originalWebViewSubviewColors: [UIView: UIColor] = [:]
|
|
112
|
+
|
|
109
113
|
// MARK: - Helper Methods for Aspect Ratio
|
|
110
114
|
|
|
111
115
|
/// Parses aspect ratio string and returns the appropriate ratio for the current orientation
|
|
@@ -141,6 +145,30 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
|
|
|
141
145
|
private func makeWebViewTransparent() {
|
|
142
146
|
guard let webView = self.webView else { return }
|
|
143
147
|
|
|
148
|
+
// IMPORTANT: Save colors synchronously FIRST to prevent race condition
|
|
149
|
+
// If we don't have saved colors yet, save them now (before going async)
|
|
150
|
+
if self.originalWebViewBackgroundColor == nil {
|
|
151
|
+
self.originalWebViewBackgroundColor = webView.backgroundColor
|
|
152
|
+
self.originalWebViewSubviewColors.removeAll()
|
|
153
|
+
|
|
154
|
+
// Define a recursive function to traverse and save colors
|
|
155
|
+
func saveSubviewColors(_ view: UIView) {
|
|
156
|
+
// Save the original background color before changing it
|
|
157
|
+
if let bgColor = view.backgroundColor, bgColor != .clear {
|
|
158
|
+
self.originalWebViewSubviewColors[view] = bgColor
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// Recurse for all subviews
|
|
162
|
+
for subview in view.subviews {
|
|
163
|
+
saveSubviewColors(subview)
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// Save all subview colors synchronously
|
|
168
|
+
saveSubviewColors(webView)
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// Now make the changes asynchronously on main thread
|
|
144
172
|
DispatchQueue.main.async {
|
|
145
173
|
_ = CFAbsoluteTimeGetCurrent()
|
|
146
174
|
|
|
@@ -170,6 +198,51 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
|
|
|
170
198
|
}
|
|
171
199
|
}
|
|
172
200
|
|
|
201
|
+
private func restoreWebViewBackground(_ webView: UIView) {
|
|
202
|
+
// Restore the saved background colors
|
|
203
|
+
func restoreSubviewsBackground(_ view: UIView) {
|
|
204
|
+
// Restore the saved background color for this view
|
|
205
|
+
if let savedColor = self.originalWebViewSubviewColors[view] {
|
|
206
|
+
view.backgroundColor = savedColor
|
|
207
|
+
} else {
|
|
208
|
+
// Fallback: If no saved color, intelligently restore based on view type
|
|
209
|
+
let className = String(describing: type(of: view))
|
|
210
|
+
if className.contains("WKScrollView") || className.contains("WKContentView") {
|
|
211
|
+
// Only restore if it's currently clear (meaning we likely made it transparent)
|
|
212
|
+
if view.backgroundColor == .clear || view.backgroundColor == nil {
|
|
213
|
+
view.backgroundColor = .white
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// Recurse for all subviews
|
|
219
|
+
for subview in view.subviews {
|
|
220
|
+
restoreSubviewsBackground(subview)
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// Restore the main webview background color
|
|
225
|
+
if let originalColor = self.originalWebViewBackgroundColor {
|
|
226
|
+
webView.backgroundColor = originalColor
|
|
227
|
+
} else {
|
|
228
|
+
// Fallback: If no saved color and webview is clear, restore to white
|
|
229
|
+
if webView.backgroundColor == .clear || webView.backgroundColor == nil {
|
|
230
|
+
webView.backgroundColor = .white
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// Restore all subviews
|
|
235
|
+
restoreSubviewsBackground(webView)
|
|
236
|
+
|
|
237
|
+
// Clear the saved colors dictionary
|
|
238
|
+
self.originalWebViewSubviewColors.removeAll()
|
|
239
|
+
self.originalWebViewBackgroundColor = nil
|
|
240
|
+
|
|
241
|
+
// Force a layout pass to apply changes
|
|
242
|
+
webView.setNeedsLayout()
|
|
243
|
+
webView.layoutIfNeeded()
|
|
244
|
+
}
|
|
245
|
+
|
|
173
246
|
private func presentCameraPermissionAlert(title: String,
|
|
174
247
|
message: String,
|
|
175
248
|
openSettingsText: String,
|
|
@@ -594,7 +667,13 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
|
|
|
594
667
|
previewView.removeFromSuperview()
|
|
595
668
|
self.previewView = nil
|
|
596
669
|
}
|
|
597
|
-
|
|
670
|
+
|
|
671
|
+
// Restore webView to opaque state with original background
|
|
672
|
+
if let webView = self.webView {
|
|
673
|
+
webView.isOpaque = true
|
|
674
|
+
// Restore the original background colors that were saved
|
|
675
|
+
self.restoreWebViewBackground(webView)
|
|
676
|
+
}
|
|
598
677
|
|
|
599
678
|
// Force stop the camera controller regardless of state
|
|
600
679
|
self.cameraController.stopRequestedAfterCapture = false
|
|
@@ -878,7 +957,13 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
|
|
|
878
957
|
self.previewView = nil
|
|
879
958
|
}
|
|
880
959
|
|
|
881
|
-
|
|
960
|
+
// Restore webView to opaque state with original background
|
|
961
|
+
if let webView = self.webView {
|
|
962
|
+
webView.isOpaque = true
|
|
963
|
+
// Restore the original background colors that were saved
|
|
964
|
+
self.restoreWebViewBackground(webView)
|
|
965
|
+
}
|
|
966
|
+
|
|
882
967
|
self.isInitialized = false
|
|
883
968
|
self.isInitializing = false
|
|
884
969
|
|