android / nowinandroid

A fully functional Android app built entirely with Kotlin and Jetpack Compose
Apache License 2.0
16.95k stars 3.1k forks source link

[Bug]: Can't navigate to 'For You' from 'Interests' after selecting 'News' topic tag #1614

Open marzaise opened 1 month ago

marzaise commented 1 month ago

Is there an existing issue for this?

Is there a StackOverflow question about this issue?

What happened?

A bug happened! Steps to reproduce:

Current behavior Clicking on the first tab of the Navigation Bar (For You) does nothing.

Expected behavior Clicking on the first tab of the Navigation Bar (For You) should navigate to 'For You' (or perhaps perform a back action in this case).

Video foryou_bug_nia.webm

Relevant logcat output

No response

Code of Conduct

padrecedano commented 1 month ago

Hi. Show your NiaNavHost and TopLevelDestination content.

sindrenm commented 3 weeks ago

FWIW, I think this is slightly related to https://issuetracker.google.com/issues/308334893, where I have reported the same thing (see #comment8).

sindrenm commented 3 weeks ago

A related issue here is that the app switches the active navigation bar tab from For You to Interests when you tap a topic from inside of the For You tab. This, IMO, should never happen. The app should instead remain on the same For You tab, but with the interest content that the user requested to see.

The problem then lies in the way the app checks if a route exists in the hierarchy. Since the TopicScreen's destination only exists in a graph in InterestsListDetailScreen, the hierarchy check will return true only for the Interests top level route:

private fun NavDestination?.isRouteInHierarchy(route: KClass<*>) =
    this?.hierarchy?.any {
        it.hasRoute(route)
    } ?: false
sindrenm commented 3 weeks ago

Following up here, as well: There is a public API that I was unaware of that gives access to the back-stack of a given Navigator. It is now documented as per https://android-review.googlesource.com/3312339. :raised_hands: