|
24 | 24 | package ss.navigation.suite |
25 | 25 |
|
26 | 26 | import androidx.activity.compose.LocalActivity |
27 | | -import androidx.compose.animation.AnimatedContent |
28 | 27 | import androidx.compose.animation.AnimatedVisibility |
29 | 28 | import androidx.compose.animation.core.tween |
30 | 29 | import androidx.compose.animation.fadeIn |
31 | | -import androidx.compose.animation.fadeOut |
32 | 30 | import androidx.compose.animation.slideInVertically |
33 | | -import androidx.compose.animation.togetherWith |
34 | 31 | import androidx.compose.foundation.layout.Box |
35 | 32 | import androidx.compose.foundation.layout.PaddingValues |
36 | 33 | import androidx.compose.foundation.layout.fillMaxSize |
@@ -132,48 +129,41 @@ private fun NavigationSuite( |
132 | 129 | ) |
133 | 130 | } |
134 | 131 |
|
135 | | - val currentBackStack = rememberTabBackStack( |
| 132 | + val backStack = rememberTabBackStack( |
136 | 133 | items = state.items, |
137 | 134 | selectedScreen = state.selectedItem, |
138 | | - rootScreenProvider = { it.screen() } |
139 | | - ) |
140 | | - val circuitNavigator = rememberCircuitNavigator(currentBackStack) |
141 | | - val navigator = rememberInterceptingNavigator( |
142 | | - navigator = circuitNavigator, |
143 | | - interceptors = interceptors, |
| 135 | + rootScreenProvider = { it.screen() }, |
144 | 136 | ) |
145 | 137 |
|
146 | 138 | val content: @Composable (PaddingValues) -> Unit = { |
147 | | - AnimatedContent( |
148 | | - targetState = currentBackStack, |
149 | | - transitionSpec = { |
150 | | - fadeIn(animationSpec = tween(300)).togetherWith(fadeOut(animationSpec = tween(300))) |
151 | | - }, |
152 | | - label = "content", |
153 | | - ) { backStack -> |
154 | | - CompositionLocalProvider( |
155 | | - LocalNavbarController provides controller, |
156 | | - LocalScrollToTop provides scrollToTopSignal, |
157 | | - ) { |
158 | | - NavigableCircuitContent( |
159 | | - navigator = navigator, |
160 | | - backStack = backStack, |
161 | | - modifier = Modifier.fillMaxSize(), |
162 | | - decoratorFactory = |
163 | | - remember(navigator) { |
164 | | - GestureNavigationDecorationFactory(onBackInvoked = navigator::pop) |
165 | | - }, |
166 | | - ) |
167 | | - } |
| 139 | + val circuitNavigator = rememberCircuitNavigator(backStack) |
| 140 | + val navigator = rememberInterceptingNavigator( |
| 141 | + navigator = circuitNavigator, |
| 142 | + interceptors = interceptors, |
| 143 | + ) |
| 144 | + val decoratorFactory = remember(navigator) { |
| 145 | + GestureNavigationDecorationFactory(onBackInvoked = navigator::pop) |
| 146 | + } |
| 147 | + |
| 148 | + CompositionLocalProvider( |
| 149 | + LocalNavbarController provides controller, |
| 150 | + LocalScrollToTop provides scrollToTopSignal, |
| 151 | + ) { |
| 152 | + NavigableCircuitContent( |
| 153 | + navigator = navigator, |
| 154 | + backStack = backStack, |
| 155 | + modifier = Modifier.fillMaxSize(), |
| 156 | + decoratorFactory = decoratorFactory, |
| 157 | + ) |
168 | 158 | } |
169 | 159 | } |
170 | 160 |
|
171 | 161 | fun handleSelection(isSelected: Boolean, model: NavbarItem) { |
172 | 162 | if (isSelected) { |
173 | | - if (currentBackStack.size > 1) { |
| 163 | + if (backStack.size > 1) { |
174 | 164 | // Reset backstack to the home screen i.e |
175 | 165 | // clear every screen in this stack |
176 | | - currentBackStack.popUntil { it.screen == state.selectedItem } |
| 166 | + backStack.popUntil { it.screen == state.selectedItem } |
177 | 167 | } else { |
178 | 168 | // Signal a scroll-to-top on current screen |
179 | 169 | scrollToTopSignal.tryEmit(Unit) |
|
0 commit comments