Skip to content

Commit d348176

Browse files
committed
Fix: Prevent overriding child view presentation detents
When NavigationStackFlow is initialized without the 'detents' parameter, it was applying .presentationDetents([]) (empty set) which incorrectly overrode presentation detents defined in child views. This change introduces OptionalPresentationDetentsModifier that only applies presentation detents when they are explicitly provided (non-nil), allowing child views to define their own detents without interference. Issue: - Child views using .presentationDetents() were being overridden - Sheets would open at maximum detent instead of specified heights - Close buttons and custom detent behaviors were broken Solution: - Replace .presentationDetents(navigationDetents ?? []) with conditional modifier - Only apply detents when explicitly provided via init parameter - Preserve backward compatibility for existing code
1 parent 6105f1e commit d348176

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

Sources/FuturedArchitecture/Architecture/NavigationStackFlow.swift

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public struct NavigationStackFlow<Coordinator: NavigationStackCoordinator, Conte
2828
NavigationStack(path: $coordinator.path) {
2929
content().navigationDestination(for: Coordinator.Destination.self, destination: coordinator.scene(for:))
3030
}
31-
.presentationDetents(navigationDetents ?? [])
31+
.modifier(OptionalPresentationDetentsModifier(detents: navigationDetents))
3232
.sheet(item: sheetBinding, onDismiss: coordinator.onModalDismiss, content: coordinator.scene(for:))
3333
#if !os(macOS)
3434
.fullScreenCover(item: fullscreenCoverBinding, onDismiss: coordinator.onModalDismiss, content: coordinator.scene(for:))
@@ -53,3 +53,17 @@ public struct NavigationStackFlow<Coordinator: NavigationStackCoordinator, Conte
5353
}
5454
#endif
5555
}
56+
57+
/// A view modifier that conditionally applies presentation detents only when they are non-nil.
58+
/// This prevents overriding child view detents with an empty set when no detents are specified.
59+
private struct OptionalPresentationDetentsModifier: ViewModifier {
60+
let detents: Set<PresentationDetent>?
61+
62+
func body(content: Content) -> some View {
63+
if let detents {
64+
content.presentationDetents(detents)
65+
} else {
66+
content
67+
}
68+
}
69+
}

0 commit comments

Comments
 (0)