Bahn-X / swift-composable-navigator

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

Navigator fails to update view when a variable is passed via the screen #79

Open KenLPham opened 2 years ago

KenLPham commented 2 years ago

Bug description

Basically on startup the app will show AScreen with a variable value of nil to display a loading screen. The deeplinker will parse the link into the following path [AScreen(value: 20), BScreen()]. Since the deeplinker uses replace(path:) it will successfully replace AScreen but fails at presenting BScreen. Parsing the link so that the value of AScreen is nil will present BScreen fine. So it seems the issue is with the value changing.

Steps to reproduce

Example App

Using the code below seems to solve the issue

extension Screen {
    static func == (lhs: Self, rhs: Self) -> Bool {
        lhs.presentationStyle == rhs.presentationStyle && type(of: lhs) == type(of: rhs)
    }
}

public extension AnyScreen {
    static func == (lhs: Self, rhs: Self) -> Bool {
        lhs.screen == rhs.screen
    }
}

Expected behavior

App should navigate to BScreen even when the value in AScreen changes

Environment

Additional context

Related: https://github.com/Bahn-X/swift-composable-navigator/issues/74#issuecomment-979748812

KenLPham commented 2 years ago

After some more testing, modifying the equatable method will cause more issues (like with tab screens). This wouldn't be the best place to try and fix this issue.