Fix camera position switch to work in real-time
- Pass camera position from settings to CameraContainerView - Add onChange handler to regenerate camera session when position changes - Remove hardcoded .front camera position - Camera now switches immediately when changed in settings
This commit is contained in:
parent
4ecdb8fbfe
commit
19e17b7051
@ -28,6 +28,7 @@ struct ContentView: View {
|
||||
EquatableView(content: CameraContainerView(
|
||||
settings: settings,
|
||||
sessionKey: cameraSessionKey,
|
||||
cameraPosition: settings.cameraPosition,
|
||||
onImageCaptured: { image in
|
||||
handlePhotoCaptured(image)
|
||||
}
|
||||
@ -79,6 +80,10 @@ struct ContentView: View {
|
||||
settings.flashMode = settings.isRingLightEnabled ? .on : .off
|
||||
}
|
||||
}
|
||||
.onChange(of: settings.cameraPosition) { _, _ in
|
||||
// Force camera session recreation when camera position changes
|
||||
cameraSessionKey = UUID()
|
||||
}
|
||||
.sheet(isPresented: $showSettings) {
|
||||
SettingsView(viewModel: settings, showPaywall: $showPaywall)
|
||||
}
|
||||
@ -162,6 +167,7 @@ struct ContentView: View {
|
||||
struct CameraContainerView: View, Equatable {
|
||||
let settings: SettingsViewModel
|
||||
let sessionKey: UUID
|
||||
let cameraPosition: CameraPosition
|
||||
let onImageCaptured: (UIImage) -> Void
|
||||
|
||||
// Only compare sessionKey for equality - ignore settings and callback changes
|
||||
@ -170,7 +176,7 @@ struct CameraContainerView: View, Equatable {
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
let _ = Design.debugLog("CameraContainerView body evaluated - sessionKey: \(sessionKey)")
|
||||
let _ = Design.debugLog("CameraContainerView body evaluated - sessionKey: \(sessionKey), position: \(cameraPosition)")
|
||||
MCamera()
|
||||
.setCameraScreen { cameraManager, namespace, closeAction in
|
||||
CustomCameraScreen(
|
||||
@ -182,9 +188,7 @@ struct CameraContainerView: View, Equatable {
|
||||
)
|
||||
}
|
||||
.setCapturedMediaScreen(nil)
|
||||
// Use front camera as default for selfie app - don't read from settings here
|
||||
// to avoid triggering @Observable tracking which breaks the camera
|
||||
.setCameraPosition(.front)
|
||||
.setCameraPosition(cameraPosition)
|
||||
.startSession()
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user