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

goTo(screen) should not navigate if top of stack == screen #1317

Closed
edenman opened this issue Apr 3, 2024 · 7 comments
Closed

goTo(screen) should not navigate if top of stack == screen #1317

edenman opened this issue Apr 3, 2024 · 7 comments

Comments

@edenman
Copy link
Contributor

edenman commented Apr 3, 2024

I can write an extension method that does this for me:

fun Navigator.goToIfNecessary(screen: Screen) {
    if (peek() != screen) {
        goTo(screen)
    }
}

but I'd love for this to be the default behavior so I don't have to remember to call it anywhere there could be a duplication. Thoughts?

@ZacSweers
Copy link
Collaborator

I'd be open to this as a PR to NavigatorImpl. It is a bit of an odd case, but maybe we could make it configurable in rememberCircuitNavigator when creating the navigator. CC @stagg

@ZacSweers
Copy link
Collaborator

ZacSweers commented Apr 3, 2024

The main question would be what to do if someone tries it. I'm not a big fan of silently no-op-ing 🤔

@edenman
Copy link
Contributor Author

edenman commented Apr 3, 2024

Yeah. I'll admit it's a bit unexpected as the caller, but I can't imagine a situation where you'd want to navigate anywhere if you passed in the same screen we're already on. Maybe some apps would want to treat this as a refresh? I guess there could be a onGoToSameScreen callback but that seems like overkill.

@stagg
Copy link
Collaborator

stagg commented Apr 3, 2024

Seems like a resonable guard to have. Think if you'd want to show the same Screen again it could easily be done with an unequal value. A sort of in place replace would still need to be done with a pop + push.

The main question would be what to do if someone tries it. I'm not a big fan of silently no-op-ing 🤔

This does open up goTo to return a result, either a success/fail boolean or a more descriptive enum.

@ZacSweers
Copy link
Collaborator

That's an interesting idea, and would give intercepting navigators the ability to communicate more too. I like it. I think starting with a Boolean return is good, we could look at an enum if it's really needed later

@edenman
Copy link
Contributor Author

edenman commented Apr 4, 2024

I'm not convinced returning a boolean/enum is the right ergonomic choice but obviously this is not my project so yall are free to do what you want.

That said, in my experience with Flow's goBack method that returned a boolean, it was a frequent source of bugs because inevitably callers would forget to check the return value. Or they'd do val ignored = flo.goBack().

I'd propose just changing the behavior, and optionally add a top-level onGoToSameScreen callback if there are apps that want to crash or log an error or show a toast/dialog or shake the screen or whatever.

github-merge-queue bot pushed a commit that referenced this issue Apr 13, 2024
Implements #1317 with the bool result return approach. Open to also
going with the passed in callback which was another suggested approach.
@ZacSweers
Copy link
Collaborator

Implemented in #1331

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants