Fix camera position switch using runtime CameraManager.setCameraPosition()
- Add onChange handler in CustomCameraScreen to watch cameraPositionRaw - Call cameraManager.setCameraPosition() at runtime when setting changes - Camera now switches without needing to recreate the entire MCamera view - Keep onDismiss fallback in ContentView as safety net
This commit is contained in:
parent
9c88590926
commit
1c07009e06
@ -39,6 +39,9 @@ struct CustomCameraScreen: MCameraScreen {
|
|||||||
@GestureState private var magnification: CGFloat = 1.0
|
@GestureState private var magnification: CGFloat = 1.0
|
||||||
@State private var lastMagnification: CGFloat = 1.0
|
@State private var lastMagnification: CGFloat = 1.0
|
||||||
|
|
||||||
|
// Track camera position for runtime switching
|
||||||
|
@State private var currentCameraPosition: CameraPosition?
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
ZStack {
|
ZStack {
|
||||||
// Camera preview with pinch gesture - Metal layer doesn't respect SwiftUI clipping
|
// Camera preview with pinch gesture - Metal layer doesn't respect SwiftUI clipping
|
||||||
@ -159,6 +162,24 @@ struct CustomCameraScreen: MCameraScreen {
|
|||||||
updateFlashSyncState()
|
updateFlashSyncState()
|
||||||
// Initialize zoom gesture state
|
// Initialize zoom gesture state
|
||||||
lastMagnification = zoomFactor
|
lastMagnification = zoomFactor
|
||||||
|
// Track initial camera position
|
||||||
|
currentCameraPosition = cameraSettings.cameraPosition
|
||||||
|
}
|
||||||
|
.onChange(of: cameraSettings.cameraPositionRaw) { _, newRaw in
|
||||||
|
// Switch camera when position changes in settings
|
||||||
|
let newPosition: CameraPosition = newRaw == "front" ? .front : .back
|
||||||
|
if currentCameraPosition != newPosition {
|
||||||
|
Design.debugLog("Camera position changed to \(newPosition) - switching camera...")
|
||||||
|
currentCameraPosition = newPosition
|
||||||
|
Task {
|
||||||
|
do {
|
||||||
|
try await cameraManager.setCameraPosition(newPosition)
|
||||||
|
Design.debugLog("Camera switched successfully to \(newPosition)")
|
||||||
|
} catch {
|
||||||
|
Design.debugLog("Failed to switch camera: \(error)")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
.onChange(of: cameraSettings.isFlashSyncedWithRingLight) { _, _ in
|
.onChange(of: cameraSettings.isFlashSyncedWithRingLight) { _, _ in
|
||||||
// Only update when sync setting changes, not on every color change
|
// Only update when sync setting changes, not on every color change
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user