voyager
voyager copied to clipboard
Linear Navigator with TabNavigator to Linear Navigator
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
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())
}
}
If you are trying to open new Screen
from the tab you have 2 ways:
- Open new
Screen
from the rootNavigator
- You should create inside each tab new
Navigator
, and use it to open a newScreen
. If you do not create newNavigator
, you will see exception that tells you are trying to use aScreen
when you are currently need to useTab
.
If you are trying to open new
Screen
from the tab you have 2 ways:
- Open new
Screen
from the rootNavigator
- You should create inside each tab new
Navigator
, and use it to open a newScreen
. If you do not create newNavigator
, you will see exception that tells you are trying to use aScreen
when you are currently need to useTab
.
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?