Skip to content

Commit

Permalink
Merge pull request #16 from splendo/feature/navigation-ios-14
Browse files Browse the repository at this point in the history
Fixed navigation bug on previous iOS 15 versions
  • Loading branch information
carmelogallo authored Feb 4, 2022
2 parents 2aa465c + fdffa36 commit 3a979c8
Showing 1 changed file with 38 additions and 3 deletions.
41 changes: 38 additions & 3 deletions stencils/Navigation.stencil
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,30 @@ struct Navigation<NavigationContent: View>: ViewModifier {
}
}
case .fullscreen:
content.fullScreenCover(isPresented: $state.isPresented) { LazyView(navigationContent()) }
// Before iOS 15 the .fullScreenCover modifier can't be more than one per view
// so we use the workaround found on this thread.
// https://stackoverflow.com/a/64403206/2242854
if #available(iOS 15, *) {
content.fullScreenCover(isPresented: $state.isPresented) { LazyView(navigationContent()) }
} else {
Group {
EmptyView().modifier(FullScreenModifier(isPresented: $state.isPresented, builder: { LazyView(navigationContent()) }))
content
}
}
case .sheet:
content.sheet(isPresented: $state.isPresented) { LazyView(navigationContent()) }
case .replace:
// Before iOS 15 the .sheet modifier can't be more than one per view
// so we use the workaround found on this thread.
// https://stackoverflow.com/a/64403206/2242854
if #available(iOS 15, *) {
content.sheet(isPresented: $state.isPresented) { LazyView(navigationContent()) }
} else {
Group {
EmptyView().sheet(isPresented: $state.isPresented) { LazyView(navigationContent()) }
content
}
}
case .replace:
if state.isPresented {
LazyView(navigationContent())
} else {
Expand All @@ -78,6 +98,21 @@ struct Navigation<NavigationContent: View>: ViewModifier {
}
}

// Needed for simulating fullscreen in iOS 13
struct FullScreenModifier<V: View>: ViewModifier {
let isPresented: Binding<Bool>
let builder: () -> V

@ViewBuilder
func body(content: Content) -> some View {
if #available(iOS 14.0, *) {
content.fullScreenCover(isPresented: isPresented, content: builder)
} else {
content.sheet(isPresented: isPresented, content: builder)
}
}
}

extension View {
func navigation<NavigationContent: View>(
state: RoutingState,
Expand Down

0 comments on commit 3a979c8

Please sign in to comment.