capacitor-camera-module 0.0.54 → 0.0.56
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.
|
@@ -176,9 +176,18 @@ public class CameraModulePlugin: CAPPlugin,CAPBridgedPlugin,AVCaptureVideoDataOu
|
|
|
176
176
|
|
|
177
177
|
// Preview view
|
|
178
178
|
let previewView = UIView()
|
|
179
|
+
|
|
180
|
+
// 🔑 MUY IMPORTANTE
|
|
181
|
+
previewView.isUserInteractionEnabled = false
|
|
179
182
|
previewView.translatesAutoresizingMaskIntoConstraints = false
|
|
180
183
|
previewView.backgroundColor = .black
|
|
181
|
-
|
|
184
|
+
|
|
185
|
+
guard let webView = self.bridge?.webView else {
|
|
186
|
+
call.reject("No webView")
|
|
187
|
+
return
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
container.insertSubview(previewView, belowSubview: webView)
|
|
182
191
|
|
|
183
192
|
NSLayoutConstraint.activate([
|
|
184
193
|
previewView.topAnchor.constraint(equalTo: container.topAnchor),
|
|
@@ -187,18 +196,25 @@ public class CameraModulePlugin: CAPPlugin,CAPBridgedPlugin,AVCaptureVideoDataOu
|
|
|
187
196
|
previewView.trailingAnchor.constraint(equalTo: container.trailingAnchor)
|
|
188
197
|
])
|
|
189
198
|
|
|
199
|
+
|
|
190
200
|
// Preview layer
|
|
191
201
|
let previewLayer = AVCaptureVideoPreviewLayer(session: session)
|
|
192
202
|
previewLayer.videoGravity = .resizeAspectFill
|
|
193
|
-
|
|
203
|
+
|
|
204
|
+
previewView.layoutIfNeeded()
|
|
205
|
+
previewLayer.frame = previewView.bounds
|
|
194
206
|
|
|
195
207
|
previewView.layer.insertSublayer(previewLayer, at: 0)
|
|
196
208
|
|
|
209
|
+
|
|
210
|
+
|
|
197
211
|
self.previewView = previewView
|
|
198
212
|
self.videoPreviewLayer = previewLayer
|
|
199
213
|
self.captureSession = session
|
|
200
214
|
|
|
201
|
-
|
|
215
|
+
DispatchQueue.global(qos: .userInitiated).async {
|
|
216
|
+
session.startRunning()
|
|
217
|
+
}
|
|
202
218
|
call.resolve()
|
|
203
219
|
}
|
|
204
220
|
}
|
|
@@ -216,6 +232,11 @@ public class CameraModulePlugin: CAPPlugin,CAPBridgedPlugin,AVCaptureVideoDataOu
|
|
|
216
232
|
}
|
|
217
233
|
}
|
|
218
234
|
|
|
235
|
+
|
|
236
|
+
public override func viewDidLayoutSubviews() {
|
|
237
|
+
super.viewDidLayoutSubviews()
|
|
238
|
+
videoPreviewLayer?.frame = previewView?.bounds ?? .zero
|
|
239
|
+
}
|
|
219
240
|
// MARK: - Flash
|
|
220
241
|
|
|
221
242
|
@objc func toggleFlash(_ call: CAPPluginCall) {
|
|
@@ -444,4 +465,6 @@ extension UIImage {
|
|
|
444
465
|
UIGraphicsEndImageContext()
|
|
445
466
|
return img
|
|
446
467
|
}
|
|
468
|
+
|
|
469
|
+
|
|
447
470
|
}
|