refactor: move selectMainTab logic to MutableList<Route> extension function
This commit is contained in:
@@ -47,15 +47,6 @@ fun App() {
|
|||||||
mutableStateListOf(Route.Records)
|
mutableStateListOf(Route.Records)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Selecting a main tab keeps Records as the root, so system Back always returns home.
|
|
||||||
fun selectMainTab(page: WebPage?) {
|
|
||||||
backStack.clear()
|
|
||||||
backStack.add(Route.Records)
|
|
||||||
if (page != null) {
|
|
||||||
backStack.add(Route.Web(page = page))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
val darkTheme = isSystemInDarkTheme()
|
val darkTheme = isSystemInDarkTheme()
|
||||||
|
|
||||||
// The current top destination drives the shared chrome: the top and bottom bars are shown
|
// The current top destination drives the shared chrome: the top and bottom bars are shown
|
||||||
@@ -77,9 +68,9 @@ fun App() {
|
|||||||
if (isMainScreen) {
|
if (isMainScreen) {
|
||||||
MainBottomBar(
|
MainBottomBar(
|
||||||
selectedPage = selectedPage,
|
selectedPage = selectedPage,
|
||||||
onRecordsClick = { selectMainTab(null) },
|
onRecordsClick = { backStack.selectMainTab(null) },
|
||||||
onDeepenClick = { selectMainTab(WebPages.DEEPEN) },
|
onDeepenClick = { backStack.selectMainTab(WebPages.DEEPEN) },
|
||||||
onAboutClick = { selectMainTab(WebPages.ABOUT) },
|
onAboutClick = { backStack.selectMainTab(WebPages.ABOUT) },
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -119,3 +110,12 @@ fun App() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Selecting a main tab keeps Records as the root, so system Back always returns home.
|
||||||
|
private fun MutableList<Route>.selectMainTab(page: WebPage?) {
|
||||||
|
this.clear()
|
||||||
|
this.add(Route.Records)
|
||||||
|
if (page != null) {
|
||||||
|
this.add(Route.Web(page = page))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user