Моя цель-отображать изображение на полном экране (полный экранизаж), когда он возвращается на главный экран на экране на основном экране. Анимация от основного экрана до полного экрана работает нормально, но от полного экрана до основного экрана нет, так как не появляется анимация. Это код, который я сделал: < /p>
Код: Выделить всё
@OptIn(ExperimentalSharedTransitionApi::class)
@Composable
fun ImagesTest(){
val images = remember { mutableListOf(Res.drawable.im_test, Res.drawable.im_test_2) }
var enlargeImage: DrawableResource? by remember { mutableStateOf(value = null) }
var showImageFullScreen by remember { mutableStateOf(value = false) }
SharedTransitionLayout {
AnimatedContent(
targetState = showImageFullScreen, label = "ImageTransition"
) { isImageFullScreen ->
if (!isImageFullScreen) {
MainScreenImages(
imagesList = images,
onImageClick = {
enlargeImage = it
showImageFullScreen = true
},
transitionScope = this@SharedTransitionLayout,
animatedVisibilityScope = this@AnimatedContent
)
} else {
enlargeImage?.let {
FullScreenImage(
enlargeImage = it,
closeFullImage = {
enlargeImage = null
showImageFullScreen = false
},
transitionScope = this@SharedTransitionLayout,
animatedVisibilityScope = this@AnimatedContent
)
}
}
}
}
}
@OptIn(ExperimentalSharedTransitionApi::class)
@Composable
private fun MainScreenImages(
imagesList: List,
onImageClick: (DrawableResource) -> Unit,
transitionScope: SharedTransitionScope,
animatedVisibilityScope: AnimatedVisibilityScope
) {
Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
LazyRow(
contentPadding = PaddingValues(horizontal = 8.dp),
horizontalArrangement = Arrangement.spacedBy(8.dp)
) {
items(imagesList, key = { it.hashCode() }) { image ->
with(transitionScope) {
Image(
painter = painterResource(image),
contentDescription = null,
contentScale = ContentScale.Crop,
modifier = Modifier
.size(100.dp)
.clip(MaterialTheme.shapes.small)
.sharedElement(
state = rememberSharedContentState(key = image.hashCode()),
animatedVisibilityScope = animatedVisibilityScope
)
.clickable {
onImageClick(image)
}
)
}
}
}
}
}
@OptIn(ExperimentalSharedTransitionApi::class)
@Composable
private fun FullScreenImage(
enlargeImage: DrawableResource,
closeFullImage: () -> Unit,
transitionScope: SharedTransitionScope,
animatedVisibilityScope: AnimatedVisibilityScope
) {
Column(
modifier = Modifier
.fillMaxSize()
.background(Color.Black.copy(alpha = 0.8f))
.clickable { closeFullImage() },
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
Spacer(modifier = Modifier.weight(1f))
with(transitionScope) {
Image(
painter = painterResource(enlargeImage),
contentDescription = null,
contentScale = ContentScale.Fit,
modifier = Modifier
.fillMaxWidth()
.weight(1f)
.padding(horizontal = 16.dp)
.sharedElement(
state = rememberSharedContentState(key = enlargeImage.hashCode()),
animatedVisibilityScope = animatedVisibilityScope
)
)
}
Spacer(modifier = Modifier.weight(1f))
}
}
Подробнее здесь: https://stackoverflow.com/questions/795 ... ot-working