Fix camera position switch - detect change on settings sheet dismiss
- Track lastCameraPosition to detect changes - Use sheet onDismiss callback to check if position changed - Force camera recreation only when position actually changes - Works around @Observable tracking issues with nested cloudSync data
This commit is contained in:
parent
19e17b7051
commit
55c4d7e05a
@ -21,6 +21,9 @@ struct ContentView: View {
|
||||
/// Incrementing this value creates a new camera session with fresh AVCapturePhotoOutput
|
||||
@State private var cameraSessionKey = UUID()
|
||||
|
||||
/// Track camera position to detect changes when settings sheet closes
|
||||
@State private var lastCameraPosition: CameraPosition = .front
|
||||
|
||||
var body: some View {
|
||||
ZStack {
|
||||
// Camera view - wrapped in EquatableView to prevent re-evaluation on settings changes
|
||||
@ -70,6 +73,10 @@ struct ContentView: View {
|
||||
.padding(.top, Design.Spacing.small)
|
||||
}
|
||||
.animation(.easeInOut(duration: Design.Animation.quick), value: showPhotoReview)
|
||||
.onAppear {
|
||||
// Initialize tracking of camera position
|
||||
lastCameraPosition = settings.cameraPosition
|
||||
}
|
||||
.onChange(of: settings.isRingLightEnabled) { _, newValue in
|
||||
if settings.isFlashSyncedWithRingLight {
|
||||
settings.flashMode = newValue ? .on : .off
|
||||
@ -80,11 +87,14 @@ struct ContentView: View {
|
||||
settings.flashMode = settings.isRingLightEnabled ? .on : .off
|
||||
}
|
||||
}
|
||||
.onChange(of: settings.cameraPosition) { _, _ in
|
||||
// Force camera session recreation when camera position changes
|
||||
.sheet(isPresented: $showSettings, onDismiss: {
|
||||
// Check if camera position changed while settings was open
|
||||
if settings.cameraPosition != lastCameraPosition {
|
||||
lastCameraPosition = settings.cameraPosition
|
||||
// Force camera session recreation with new position
|
||||
cameraSessionKey = UUID()
|
||||
}
|
||||
.sheet(isPresented: $showSettings) {
|
||||
}) {
|
||||
SettingsView(viewModel: settings, showPaywall: $showPaywall)
|
||||
}
|
||||
.sheet(isPresented: $showPaywall) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user