19
19
package com.example.compose.snippets.animations.sharedelement
20
20
21
21
import androidx.compose.animation.AnimatedContent
22
+ import androidx.compose.animation.AnimatedVisibility
22
23
import androidx.compose.animation.AnimatedVisibilityScope
23
24
import androidx.compose.animation.ExperimentalSharedTransitionApi
24
25
import androidx.compose.animation.SharedTransitionLayout
@@ -38,6 +39,7 @@ import androidx.compose.foundation.shape.CircleShape
38
39
import androidx.compose.foundation.shape.RoundedCornerShape
39
40
import androidx.compose.material3.Text
40
41
import androidx.compose.runtime.Composable
42
+ import androidx.compose.runtime.compositionLocalOf
41
43
import androidx.compose.runtime.getValue
42
44
import androidx.compose.runtime.mutableStateOf
43
45
import androidx.compose.runtime.remember
@@ -395,3 +397,44 @@ private fun UnmatchedBoundsExample() {
395
397
}
396
398
// [END android_compose_animation_shared_element_bounds_unmatched]
397
399
}
400
+
401
+ private object UniqueKeySnippet {
402
+ // [START android_compose_shared_elements_unique_key]
403
+ data class SnackSharedElementKey (
404
+ val snackId : Long ,
405
+ val origin : String ,
406
+ val type : SnackSharedElementType
407
+ )
408
+
409
+ enum class SnackSharedElementType {
410
+ Bounds ,
411
+ Image ,
412
+ Title ,
413
+ Tagline ,
414
+ Background
415
+ }
416
+
417
+ @Composable
418
+ fun SharedElementUniqueKey () {
419
+ // [START_EXCLUDE]
420
+ SharedTransitionLayout {
421
+ AnimatedVisibility (visible = true ) {
422
+ // [END_EXCLUDE]
423
+ Box (modifier = Modifier
424
+ .sharedElement(
425
+ rememberSharedContentState(
426
+ key = SnackSharedElementKey (
427
+ snackId = 1 ,
428
+ origin = " latest" ,
429
+ type = SnackSharedElementType .Image
430
+ )
431
+ ),
432
+ animatedVisibilityScope = this @AnimatedVisibility
433
+ ))
434
+ // [START_EXCLUDE]
435
+ }
436
+ }
437
+ // [END_EXCLUDE]
438
+ }
439
+ // [END android_compose_shared_elements_unique_key]
440
+ }
0 commit comments