Skip to content

Commit 130186e

Browse files
committed
feat(ui/navigation): support bottomsheet.show() with a full stack of screens
instead of showing the first and pushing the rest as a secondary action, we now do the event as one atomic action Signed-off-by: Brandon McAnsh <git@bmcreations.dev>
1 parent da9697c commit 130186e

2 files changed

Lines changed: 37 additions & 12 deletions

File tree

ui/navigation/src/main/kotlin/com/getcode/navigation/core/BottomSheetNavigator.kt

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,21 @@ class BottomSheetNavigator @InternalVoyagerApi constructor(
170170
}
171171
}
172172

173+
fun show(screens: List<Screen>) {
174+
coroutineScope.launch {
175+
if (sheetStacks.isEmpty) {
176+
replaceAll(screens)
177+
// setup stack
178+
val firstScreen = items.first()
179+
val remainingScreens = items.drop(1)
180+
sheetStacks.push(firstScreen to remainingScreens)
181+
sheetState.show()
182+
} else {
183+
hideAndShow(screens)
184+
}
185+
}
186+
}
187+
173188
private suspend fun hideAndShow(screen: Screen) {
174189
if (isVisible) {
175190
// animate sheet out
@@ -188,6 +203,26 @@ class BottomSheetNavigator @InternalVoyagerApi constructor(
188203
}
189204
}
190205

206+
private suspend fun hideAndShow(screens: List<Screen>) {
207+
if (isVisible) {
208+
// animate sheet out
209+
sheetState.hide()
210+
// replacing w/ dummy sheet
211+
replaceAll(HiddenBottomSheetScreen)
212+
// push new stack
213+
val firstScreen = items.first()
214+
val remainingScreens = items.drop(1)
215+
sheetStacks.push(firstScreen to remainingScreens)
216+
// show new sheet
217+
replaceAll(screens)
218+
sheetState.show()
219+
} else {
220+
Timber.e("shouldn't get here; but ensuring a sheet is shown when requested.")
221+
sheetStacks.popAll()
222+
show(screens)
223+
}
224+
}
225+
191226

192227
fun hide() {
193228
coroutineScope.launch {

ui/navigation/src/main/kotlin/com/getcode/navigation/core/CombinedNavigator.kt

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,8 @@ class CombinedNavigator(
4949
}
5050

5151
override fun show(items: List<Screen>) {
52-
launch {
53-
if (items.isEmpty()) return@launch
54-
val firstScreen = items.first()
55-
val remainingScreens = items.drop(1)
56-
sheetNavigator.show(firstScreen)
57-
if (remainingScreens.isNotEmpty()) {
58-
while (!sheetFullyVisible) {
59-
delay(50)
60-
}
61-
sheetNavigator.push(remainingScreens)
62-
}
63-
}
52+
if (items.isEmpty()) return
53+
sheetNavigator.show(items)
6454
}
6555

6656
override fun hide() {

0 commit comments

Comments
 (0)