Created
April 12, 2024 19:00
-
-
Save Rahkeen/8882fa73569743fb7860c8c2f4ff07f2 to your computer and use it in GitHub Desktop.
Simplified Container Transform Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum class Scene { | |
Grid, | |
Closeup; | |
fun toggle() = if (this == Grid) Closeup else Grid | |
} | |
@Preview | |
@Composable | |
fun ContainerTransformWeirdness() { | |
var scene by remember { mutableStateOf(Scene.Grid) } | |
SharedTransitionLayout(modifier = Modifier.fillMaxSize()) { | |
AnimatedContent( | |
targetState = scene, | |
transitionSpec = { | |
fadeIn() togetherWith fadeOut() | |
}, | |
label = "Screen Transition" | |
) { target -> | |
when (target) { | |
Scene.Grid -> { | |
Column( | |
modifier = Modifier | |
.fillMaxSize() | |
.windowInsetsPadding(WindowInsets.statusBars) | |
.padding(8.dp), | |
verticalArrangement = Arrangement.spacedBy(8.dp) | |
) { | |
FakeSearchBar( | |
modifier = Modifier | |
.fillMaxWidth() | |
.height(60.dp) | |
) | |
LazyVerticalGrid( | |
modifier = Modifier.fillMaxSize(), | |
columns = GridCells.Fixed(2) | |
) { | |
item { | |
Column( | |
modifier = Modifier | |
.sharedBounds( | |
sharedContentState = rememberSharedContentState(key = "container"), | |
animatedVisibilityScope = this@AnimatedContent | |
) | |
.fillMaxWidth() | |
.height(300.dp) | |
.clip(RoundedCornerShape(16.dp)) | |
.background(color = Purple80) | |
.clickable { | |
scene = scene.toggle() | |
} | |
) { | |
Box( | |
modifier = Modifier | |
.sharedElement( | |
state = rememberSharedContentState(key = "element"), | |
animatedVisibilityScope = this@AnimatedContent | |
) | |
.fillMaxWidth() | |
.height(200.dp) | |
.clip(RoundedCornerShape(16.dp)) | |
.background(color = Purple40) | |
) | |
} | |
} | |
} | |
} | |
} | |
Scene.Closeup -> { | |
BackHandler { | |
scene = scene.toggle() | |
} | |
Column( | |
modifier = Modifier | |
.sharedBounds( | |
sharedContentState = rememberSharedContentState(key = "container"), | |
animatedVisibilityScope = this@AnimatedContent | |
) | |
.fillMaxSize() | |
.clip(RoundedCornerShape(16.dp)) | |
.background(color = Purple80) | |
.padding(8.dp), | |
verticalArrangement = Arrangement.spacedBy(8.dp) | |
) { | |
Box( | |
modifier = Modifier | |
.sharedElement( | |
state = rememberSharedContentState(key = "element"), | |
animatedVisibilityScope = this@AnimatedContent | |
) | |
.fillMaxWidth() | |
.aspectRatio(1f) | |
.clip(RoundedCornerShape(16.dp)) | |
.background(color = Purple40) | |
) | |
Column( | |
modifier = Modifier | |
.fillMaxSize() | |
.clip(RoundedCornerShape(16.dp)) | |
.background(color = Color.White) | |
) { | |
} | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment