|
1 | 1 | package com.getcode.navigation.core |
2 | 2 |
|
3 | | -import android.annotation.SuppressLint |
4 | 3 | import androidx.compose.runtime.Composable |
5 | | -import androidx.compose.runtime.ProvidableCompositionLocal |
6 | 4 | import androidx.compose.runtime.derivedStateOf |
7 | 5 | import androidx.compose.runtime.getValue |
8 | 6 | import androidx.compose.runtime.remember |
9 | | -import androidx.compose.runtime.staticCompositionLocalOf |
10 | 7 | import cafe.adriel.voyager.core.screen.Screen |
11 | | -import cafe.adriel.voyager.core.stack.Stack |
12 | 8 | import cafe.adriel.voyager.core.stack.StackEvent |
13 | 9 | import cafe.adriel.voyager.navigator.Navigator |
14 | 10 | import com.getcode.navigation.screens.AppScreen |
15 | | -import com.getcode.navigation.screens.ModalContent |
16 | 11 | import timber.log.Timber |
17 | 12 |
|
18 | | -val LocalCodeNavigator: ProvidableCompositionLocal<CodeNavigator> = |
19 | | - staticCompositionLocalOf { NavigatorNull() } |
20 | | - |
21 | | -class NavigatorNull : CodeNavigator { |
22 | | - override val lastItem: Screen? = null |
23 | | - override val lastModalItem: Screen? = null |
24 | | - override val sheetStackRoot: Screen? = null |
25 | | - override val lastEvent: StackEvent = StackEvent.Idle |
26 | | - override val isVisible: Boolean = false |
27 | | - override val progress: Float = 0f |
28 | | - |
29 | | - override var screensNavigator: Navigator? = null |
30 | | - |
31 | | - override fun show(screen: Screen) = Unit |
32 | | - |
33 | | - override fun hide() = Unit |
34 | | - override fun <T> hideWithResult(result: T) = Unit |
35 | | - |
36 | | - override fun push(item: Screen) = Unit |
37 | | - |
38 | | - override fun push(items: List<Screen>) = Unit |
39 | | - |
40 | | - override fun replace(item: Screen) = Unit |
41 | | - |
42 | | - override fun replaceAll(item: Screen, inSheet: Boolean) = Unit |
43 | | - |
44 | | - override fun replaceAll(items: List<Screen>, inSheet: Boolean) = Unit |
45 | | - |
46 | | - override fun pop(): Boolean = false |
47 | | - override fun <T> popWithResult(result: T) = false |
48 | | - |
49 | | - override fun popAll() = Unit |
50 | | - |
51 | | - override fun popUntil(predicate: (Screen) -> Boolean): Boolean = false |
52 | | - |
53 | | - @Composable |
54 | | - override fun saveableState( |
55 | | - key: String, |
56 | | - screen: Screen?, |
57 | | - content: @Composable () -> Unit |
58 | | - ) { |
59 | | - content() |
60 | | - } |
61 | | - |
62 | | -} |
63 | | - |
64 | | -interface CodeNavigator { |
65 | | - val lastItem: Screen? |
66 | | - val lastModalItem: Screen? |
67 | | - val sheetStackRoot: Screen? |
68 | | - val lastEvent: StackEvent |
69 | | - val isVisible: Boolean |
70 | | - val progress: Float |
71 | | - var screensNavigator: Navigator? |
72 | | - fun show(screen: Screen) |
73 | | - fun hide() |
74 | | - fun <T> hideWithResult(result: T) |
75 | | - infix fun push(item: Screen) |
76 | | - |
77 | | - infix fun push(items: List<Screen>) |
78 | | - |
79 | | - infix fun replace(item: Screen) |
80 | | - |
81 | | - fun replaceAll(item: Screen, inSheet: Boolean = true) |
82 | | - |
83 | | - fun replaceAll(items: List<Screen>, inSheet: Boolean = true) |
84 | | - |
85 | | - fun pop(): Boolean |
86 | | - fun <T> popWithResult(result: T): Boolean |
87 | | - |
88 | | - fun popAll() |
89 | | - |
90 | | - infix fun popUntil(predicate: (Screen) -> Boolean): Boolean |
91 | | - |
92 | | - @SuppressLint("ComposableNaming") |
93 | | - @Composable |
94 | | - fun saveableState( |
95 | | - key: String, |
96 | | - screen: Screen?, |
97 | | - content: @Composable () -> Unit |
98 | | - ) |
99 | | -} |
100 | | - |
101 | 13 | class CombinedNavigator( |
102 | 14 | var sheetNavigator: BottomSheetNavigator |
103 | 15 | ) : CodeNavigator { |
@@ -169,17 +81,10 @@ class CombinedNavigator( |
169 | 81 | } |
170 | 82 |
|
171 | 83 | override fun replaceAll(item: Screen, inSheet: Boolean) { |
172 | | - if (isVisible && inSheet) { |
173 | | - sheetNavigator.replaceAll(item) |
174 | | - } else { |
175 | | - if (isVisible) { |
176 | | - hide() |
177 | | - } |
178 | | - screensNavigator?.replaceAll(item) |
179 | | - } |
| 84 | + replaceAll(listOf(item), inSheet) |
180 | 85 | } |
181 | 86 |
|
182 | | - override fun replaceAll(items: List<Screen>, inSheet: Boolean) { |
| 87 | + override fun replaceAll(items: List<Screen>, inSheet: Boolean,) { |
183 | 88 | if (isVisible && inSheet) { |
184 | 89 | sheetNavigator.replaceAll(items) |
185 | 90 | } else { |
|
0 commit comments