Created
April 13, 2024 14:57
-
-
Save Rahkeen/0336737fd810010d0c95094b761161d2 to your computer and use it in GitHub Desktop.
Some weird stuff going on.
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
@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, | |
enter = fadeIn(), | |
exit = fadeOut() | |
) | |
.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, | |
enter = fadeIn(), | |
exit = fadeOut() | |
) | |
.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() | |
.height(200.dp) | |
.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