Comments (2)
I was able to get state-restoration working with a small modification:
@Composable
fun ScreenTransition(
navigator: TabNavigator,
transition: AnimatedContentTransitionScope<Tab>.() -> ContentTransform,
modifier: Modifier = Modifier,
- content: TabNavigatorContent = { it.current.Content() }
) {
AnimatedContent(
targetState = navigator.current,
transitionSpec = transition,
modifier = modifier
) { tab ->
navigator.saveableState("transition", tab) {
- content(navigator)
+ tab.Content()
}
}
}
from voyager.
I'm able to achieve transitions in between tabs with some source mode modifications.
However this is not restoring the previous saved state.
class TabNavigator internal constructor(
internal val navigator: Navigator
) {
var current: Tab
get() = navigator.lastItem as Tab
set(tab) {
lastEvent =
if (tab.options.index >= current.options.index) StackEvent.Push else StackEvent.Pop
navigator.replaceAll(tab)
}
var lastEvent: StackEvent = StackEvent.Push
@Composable
fun saveableState(
key: String,
tab: Tab = current,
content: @Composable () -> Unit
) {
navigator.saveableState(key, tab, content = content)
}
}
@Composable
fun SlideTransition(
navigator: TabNavigator,
modifier: Modifier = Modifier,
orientation: SlideOrientation = SlideOrientation.Horizontal,
animationSpec: FiniteAnimationSpec<IntOffset> = spring(
stiffness = Spring.StiffnessMediumLow,
visibilityThreshold = IntOffset.VisibilityThreshold
),
content: TabNavigatorContent = { it.current.Content() }
) {
ScreenTransition(
navigator = navigator,
modifier = modifier,
content = content,
transition = {
val (initialOffset, targetOffset) = when (navigator.lastEvent) {
StackEvent.Pop -> ({ size: Int -> -size }) to ({ size: Int -> size })
else -> ({ size: Int -> size }) to ({ size: Int -> -size })
}
when (orientation) {
SlideOrientation.Horizontal ->
slideInHorizontally(animationSpec, initialOffset) togetherWith
slideOutHorizontally(animationSpec, targetOffset)
SlideOrientation.Vertical ->
slideInVertically(animationSpec, initialOffset) togetherWith
slideOutVertically(animationSpec, targetOffset)
}
}
)
}
@Composable
fun ScreenTransition(
navigator: TabNavigator,
transition: AnimatedContentTransitionScope<Tab>.() -> ContentTransform,
modifier: Modifier = Modifier,
content: TabNavigatorContent = { it.current.Content() }
) {
AnimatedContent(
targetState = navigator.current,
transitionSpec = transition,
modifier = modifier
) { tab ->
navigator.saveableState("transition", tab) {
content(navigator)
}
}
}
from voyager.
Related Issues (20)
- Popping navigator in background doesn't work
- navigator.pop() followed by navigator.push(screen) does not dispose the ScreenModel from the popped screen HOT 8
- Crash on Android because ScreenTransition do not inherit from Serializable HOT 5
- Double Navigation Bar Issue. HOT 1
- Can't pass the Dynamic Data using Tab Navigator
- iOS swipe to close does not work HOT 1
- Koin ScreenModel inject crash starting from 1.1.0-alpha04 HOT 1
- Screen transition broken in 1.1.0-beta02
- Can't pop root in Compose for Desktop
- [Desktop] Density is not updated on changing the window to a screen with different density
- [KMP ViewModels][Voyager][Koin] Crush if you try to navigate back
- Override the back press in each Screen in Compose Multiplatform HOT 3
- Snackbar overlapped by BottomSheet when using BottomSheetNavigator
- HorizontalPager HOT 1
- [WASM] [Font] tofu are displayed instead of the actual font HOT 1
- Android Activity Lifecycle events stop being forwarded by AndroidScreenLifecycleOwner after screen rotation
- BottomSheetNavigator - IOS Build error HOT 4
- Navigation testing
- Problem with @Transient during Screen serialization
- 最新版本打包ios 会报错
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from voyager.