capacitor-camera-module 0.0.55 → 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,22 +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
|
|
|
197
|
-
|
|
198
|
-
container.bringSubviewToFront(webView)
|
|
199
|
-
}
|
|
209
|
+
|
|
200
210
|
|
|
201
211
|
self.previewView = previewView
|
|
202
212
|
self.videoPreviewLayer = previewLayer
|
|
203
213
|
self.captureSession = session
|
|
204
214
|
|
|
205
|
-
|
|
215
|
+
DispatchQueue.global(qos: .userInitiated).async {
|
|
216
|
+
session.startRunning()
|
|
217
|
+
}
|
|
206
218
|
call.resolve()
|
|
207
219
|
}
|
|
208
220
|
}
|
|
@@ -220,6 +232,11 @@ public class CameraModulePlugin: CAPPlugin,CAPBridgedPlugin,AVCaptureVideoDataOu
|
|
|
220
232
|
}
|
|
221
233
|
}
|
|
222
234
|
|
|
235
|
+
|
|
236
|
+
public override func viewDidLayoutSubviews() {
|
|
237
|
+
super.viewDidLayoutSubviews()
|
|
238
|
+
videoPreviewLayer?.frame = previewView?.bounds ?? .zero
|
|
239
|
+
}
|
|
223
240
|
// MARK: - Flash
|
|
224
241
|
|
|
225
242
|
@objc func toggleFlash(_ call: CAPPluginCall) {
|
|
@@ -448,4 +465,6 @@ extension UIImage {
|
|
|
448
465
|
UIGraphicsEndImageContext()
|
|
449
466
|
return img
|
|
450
467
|
}
|
|
468
|
+
|
|
469
|
+
|
|
451
470
|
}
|