Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: error "Navigator ... is replacing an already attached ..." #580

Merged
merged 2 commits into from
Oct 27, 2023

Conversation

hoc081098
Copy link
Contributor

@hoc081098 hoc081098 commented Oct 20, 2023

When changing startRoute, that causes navController.navigatorProvider.addNavigator(CustomActivityNavigator(context)) is called again.
check(previousNavigator?.isAttached != true) don't passes.

package androidx.navigation

public open class NavigatorProvider {
 @CallSuper
    public open fun addNavigator(
        name: String,
        navigator: Navigator<out NavDestination>
    ): Navigator<out NavDestination>? {
        ...
        val previousNavigator = _navigators[name]
        if (previousNavigator == navigator) {
            return navigator
        }
        check(previousNavigator?.isAttached != true) {
            "Navigator $navigator is replacing an already attached $previousNavigator"
        }
       ...
    }
}

P/S:
Although changing startRoute does not follow Fixed start destination, but in some cases, we must to do this.

…en changing `startRoute` -> `addNavigator(CustomActivityNavigator(context))` is called again
@hoangchungk53qx1
Copy link
Contributor

@hoc081098 💯

@gabrielittner
Copy link
Member

Thanks for this PR and the other one, I'll take a loot at them this week

Copy link
Member

@gabrielittner gabrielittner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. We should probably turn the Set parameters into ImmutableSet at some point to make he effect and remember more efficient

@gabrielittner gabrielittner merged commit 002c327 into freeletics:main Oct 27, 2023
2 checks passed
@hoc081098 hoc081098 deleted the fix_crash branch November 6, 2023 09:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants