@@ -2,19 +2,27 @@ package com.mr3y.podcaster.ui.components
22
33import androidx.compose.animation.AnimatedVisibilityScope
44import androidx.compose.animation.BoundsTransform
5+ import androidx.compose.animation.EnterTransition
6+ import androidx.compose.animation.ExitTransition
57import androidx.compose.animation.ExperimentalSharedTransitionApi
68import androidx.compose.animation.SharedTransitionScope
79import androidx.compose.animation.SharedTransitionScope.OverlayClip
810import androidx.compose.animation.SharedTransitionScope.PlaceHolderSize
911import androidx.compose.animation.SharedTransitionScope.PlaceHolderSize.Companion.contentSize
12+ import androidx.compose.animation.SharedTransitionScope.ResizeMode
13+ import androidx.compose.animation.SharedTransitionScope.ResizeMode.Companion.ScaleToBounds
1014import androidx.compose.animation.core.Spring.StiffnessMediumLow
1115import androidx.compose.animation.core.VisibilityThreshold
1216import androidx.compose.animation.core.spring
17+ import androidx.compose.animation.fadeIn
18+ import androidx.compose.animation.fadeOut
1319import androidx.compose.runtime.Composable
1420import androidx.compose.runtime.staticCompositionLocalOf
21+ import androidx.compose.ui.Alignment.Companion.Center
1522import androidx.compose.ui.Modifier
1623import androidx.compose.ui.geometry.Rect
1724import androidx.compose.ui.graphics.Path
25+ import androidx.compose.ui.layout.ContentScale
1826import androidx.compose.ui.unit.Density
1927import androidx.compose.ui.unit.LayoutDirection
2028
@@ -59,6 +67,44 @@ fun Modifier.sharedElement(
5967 }
6068}
6169
70+ fun Modifier.sharedBounds (
71+ sharedTransitionScope : SharedTransitionScope ? ,
72+ animatedVisibilityScope : AnimatedVisibilityScope ? ,
73+ state : SharedTransitionScope .SharedContentState ? ,
74+ enter : EnterTransition = fadeIn(),
75+ exit : ExitTransition = fadeOut(),
76+ boundsTransform : BoundsTransform = BoundsTransform { _, _ ->
77+ spring(
78+ stiffness = StiffnessMediumLow ,
79+ visibilityThreshold = Rect .VisibilityThreshold ,
80+ )
81+ },
82+ resizeMode : ResizeMode = ScaleToBounds (ContentScale .FillWidth , Center ),
83+ placeHolderSize : PlaceHolderSize = contentSize,
84+ renderInOverlayDuringTransition : Boolean = true,
85+ zIndexInOverlay : Float = 0f,
86+ clipInOverlayDuringTransition : OverlayClip = ParentClip
87+ ): Modifier {
88+ return if (sharedTransitionScope == null || animatedVisibilityScope == null || state == null ) {
89+ this
90+ } else {
91+ with (sharedTransitionScope) {
92+ sharedBounds(
93+ state,
94+ animatedVisibilityScope,
95+ enter,
96+ exit,
97+ boundsTransform,
98+ resizeMode,
99+ placeHolderSize,
100+ renderInOverlayDuringTransition,
101+ zIndexInOverlay,
102+ clipInOverlayDuringTransition
103+ )
104+ }
105+ }
106+ }
107+
62108fun Modifier.skipToLookaheadSize (
63109 sharedTransitionScope : SharedTransitionScope ? ,
64110): Modifier {
0 commit comments