Bahn-X / swift-composable-navigator

An open source library for building deep-linkable SwiftUI applications with composition, testing and ergonomics in mind
MIT License
580 stars 25 forks source link

Add replace(content: Content, for id: ScreenID) #27

Closed ohitsdaniel closed 3 years ago

ohitsdaniel commented 3 years ago

When wildcards are triggered, they currently do not replace the element in the routing path element they 'caught'. Let's add replace(content: Content, for id: ScreenID) to mitigate this and replace the content for the current screen ID whenever a Wildcard Wrapper View appears.

struct WildcardView<Content: View, Wildcard: Screen> {
   @Environment(\.navigator) var navigator
   @Environment(\.currentScreenID) var id
   let wildcard: Wildcard
   let content: Content

   var body: some View {
       content
           .uiKitOnAppear {
              // check if content == wildcard and only replace if not.
               navigator.replace(content: wildcard, for id: id)
           }
   } 
}