voyager icon indicating copy to clipboard operation
voyager copied to clipboard

Linear Navigator with TabNavigator to Linear Navigator

Open LiuPack opened this issue 1 year ago • 3 comments

My page structure is Screen nested Tab at the bottom of the stack. When using LocalNavigator to jump to a new Screen in Tab, an error will appear: Screen cannot be cast to Tab. In order to open a new Screen in Tab, I wrote a top-level function internal val LocalParentNavigator @Composable get() = LocalNavigator.currentOrThrow.parent ?: LocalNavigator.currentOrThrow Through this, we can get the Navigator at the bottom of the stack to jump to the new Screen, but there will be a new problem. When I perform pop from the new Screen and return to the Screen with Tab, the Tab will be reorganized. Now there is What is a better way to handle Screen->Tab->Screen

LiuPack avatar Jan 03 '24 07:01 LiuPack

If you're trying to do what I think you are trying to do I think you want to put a navigator in your tabs. That way you can just call LocalNavigator.currentOrThrow to get the inner navigator, which will be different from LocalTabNavigator.current.

class HomeTab: Tab {
    override val options: TabOptions { ... }

    @Composable
    override fun Content() {
        Navigator(InnerTabScreen())
    }
}

Qw4z1 avatar Jan 26 '24 16:01 Qw4z1

If you are trying to open new Screen from the tab you have 2 ways:

  1. Open new Screen from the root Navigator
  2. You should create inside each tab new Navigator, and use it to open a new Screen. If you do not create new Navigator, you will see exception that tells you are trying to use a Screen when you are currently need to use Tab.

Velord avatar Jan 28 '24 21:01 Velord

If you are trying to open new Screen from the tab you have 2 ways:

  1. Open new Screen from the root Navigator
  2. You should create inside each tab new Navigator, and use it to open a new Screen. If you do not create new Navigator, you will see exception that tells you are trying to use a Screen when you are currently need to use Tab.

The first way to test is OK, but need to write the callback function to the root node, some trouble. The second type of jump is inside the tab, that is, it is not a new page, but a new page in the tab. Is there only the first way to open a new page?

yangwuan55 avatar Feb 25 '24 06:02 yangwuan55