Skip to content

Commit b4a5a2a

Browse files
illixionclaude
andcommitted
Stabilize swipe gesture modifiers so 3D window survives UI auto-hide
The swipe modifiers branched on `enabled` with an if/else inside their ViewModifier body. SwiftUI compiles that into a _ConditionalContent whose branch flip reroots the wrapped view. Once `isSwipeEnabled` started depending on `isUIHidden`, the auto-hide tick toggled the branch — and on the RealityKit 3D path that tore down the ImagePresentationComponent, so the immersive 3D window disappeared the moment the ornament hid. Keep view identity constant by always attaching the gesture and gating the work inside its onEnded closure instead. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent cf67a28 commit b4a5a2a

1 file changed

Lines changed: 20 additions & 21 deletions

File tree

SpatialStash/SpatialStash/Views/Pictures/PhotoDisplayView.swift

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -718,17 +718,19 @@ private struct SwipeGestureModifier: ViewModifier {
718718
let enabled: Bool
719719
let onEnded: (CGFloat, CGFloat) -> Void
720720

721+
// Keep view identity stable across `enabled` flips: an if/else here
722+
// produces a _ConditionalContent whose branch swap reroots the wrapped
723+
// view. On the RealityKit 3D path that tears down the
724+
// ImagePresentationComponent and the immersive window vanishes when the
725+
// ornament auto-hides.
721726
func body(content: Content) -> some View {
722-
if enabled {
723-
content.gesture(
724-
DragGesture(minimumDistance: 20)
725-
.onEnded { value in
726-
onEnded(value.translation.width, value.predictedEndTranslation.width)
727-
}
728-
)
729-
} else {
730-
content
731-
}
727+
content.gesture(
728+
DragGesture(minimumDistance: 20)
729+
.onEnded { value in
730+
guard enabled else { return }
731+
onEnded(value.translation.width, value.predictedEndTranslation.width)
732+
}
733+
)
732734
}
733735
}
734736

@@ -739,16 +741,13 @@ private struct EntitySwipeGestureModifier: ViewModifier {
739741
let onEnded: (CGFloat, CGFloat) -> Void
740742

741743
func body(content: Content) -> some View {
742-
if enabled {
743-
content.gesture(
744-
DragGesture(minimumDistance: 20)
745-
.targetedToAnyEntity()
746-
.onEnded { value in
747-
onEnded(value.translation.width, value.predictedEndTranslation.width)
748-
}
749-
)
750-
} else {
751-
content
752-
}
744+
content.gesture(
745+
DragGesture(minimumDistance: 20)
746+
.targetedToAnyEntity()
747+
.onEnded { value in
748+
guard enabled else { return }
749+
onEnded(value.translation.width, value.predictedEndTranslation.width)
750+
}
751+
)
753752
}
754753
}

0 commit comments

Comments
 (0)