@@ -53,149 +53,148 @@ import com.example.compose.snippets.R
53
53
import com.example.compose.snippets.ui.theme.LavenderLight
54
54
import com.example.compose.snippets.ui.theme.RoseLight
55
55
56
- private class SharedElementBasicUsage4 {
57
-
58
- @Preview
59
- @Composable
60
- private fun SharedElementApp () {
61
- var showDetails by remember {
62
- mutableStateOf(false )
63
- }
64
- SharedTransitionLayout {
65
- AnimatedContent (
66
- showDetails,
67
- label = " basic_transition"
68
- ) { targetState ->
69
- if (! targetState) {
70
- MainContent (
71
- onShowDetails = {
72
- showDetails = true
73
- },
74
- animatedVisibilityScope = this @AnimatedContent,
75
- sharedTransitionScope = this @SharedTransitionLayout
76
- )
77
- } else {
78
- DetailsContent (
79
- onBack = {
80
- showDetails = false
81
- },
82
- animatedVisibilityScope = this @AnimatedContent,
83
- sharedTransitionScope = this @SharedTransitionLayout
84
- )
85
- }
56
+ @Preview
57
+ @Composable
58
+ fun SharedBoundsDemo () {
59
+ var showDetails by remember {
60
+ mutableStateOf(false )
61
+ }
62
+ SharedTransitionLayout {
63
+ AnimatedContent (
64
+ showDetails,
65
+ label = " basic_transition"
66
+ ) { targetState ->
67
+ if (! targetState) {
68
+ MainContent (
69
+ onShowDetails = {
70
+ showDetails = true
71
+ },
72
+ animatedVisibilityScope = this @AnimatedContent,
73
+ sharedTransitionScope = this @SharedTransitionLayout
74
+ )
75
+ } else {
76
+ DetailsContent (
77
+ onBack = {
78
+ showDetails = false
79
+ },
80
+ animatedVisibilityScope = this @AnimatedContent,
81
+ sharedTransitionScope = this @SharedTransitionLayout
82
+ )
86
83
}
87
84
}
88
85
}
86
+ }
89
87
90
- // [START android_compose_animations_shared_element_shared_bounds]
91
- @Composable
92
- private fun MainContent (
93
- onShowDetails : () -> Unit ,
94
- modifier : Modifier = Modifier ,
95
- sharedTransitionScope : SharedTransitionScope ,
96
- animatedVisibilityScope : AnimatedVisibilityScope
97
- ) {
98
- with (sharedTransitionScope) {
99
- Row (
100
- modifier = Modifier
101
- .padding(8 .dp)
102
- .sharedBounds(
103
- rememberSharedContentState(key = " bounds" ),
104
- animatedVisibilityScope = animatedVisibilityScope,
105
- enter = fadeIn(),
106
- exit = fadeOut()
107
- )
108
- // [START_EXCLUDE]
109
- .border(1 .dp, Color .Gray .copy(alpha = 0.5f ), RoundedCornerShape (8 .dp))
110
- .background(LavenderLight , RoundedCornerShape (8 .dp))
111
- .clickable {
112
- onShowDetails()
113
- }
114
- .padding(8 .dp)
115
- // [END_EXCLUDE]
116
- ) {
117
- // [START_EXCLUDE]
118
- Image (
119
- painter = painterResource(id = R .drawable.cupcake),
120
- contentDescription = " Cupcake" ,
121
- modifier = Modifier
122
- .sharedElement(
123
- rememberSharedContentState(key = " image" ),
124
- animatedVisibilityScope = animatedVisibilityScope
125
- )
126
- .size(100 .dp)
127
- .clip(CircleShape ),
128
- contentScale = ContentScale .Crop
88
+ // [START android_compose_animations_shared_element_shared_bounds]
89
+ @Composable
90
+ private fun MainContent (
91
+ onShowDetails : () -> Unit ,
92
+ modifier : Modifier = Modifier ,
93
+ sharedTransitionScope : SharedTransitionScope ,
94
+ animatedVisibilityScope : AnimatedVisibilityScope
95
+ ) {
96
+ with (sharedTransitionScope) {
97
+ Row (
98
+ modifier = Modifier
99
+ .padding(8 .dp)
100
+ .sharedBounds(
101
+ rememberSharedContentState(key = " bounds" ),
102
+ animatedVisibilityScope = animatedVisibilityScope,
103
+ enter = fadeIn(),
104
+ exit = fadeOut(),
105
+ resizeMode = SharedTransitionScope .ResizeMode .ScaleToBounds ()
129
106
)
130
- Text (
131
- " Cupcake" , fontSize = 21 .sp,
132
- modifier = Modifier .sharedBounds(
133
- rememberSharedContentState(key = " title" ),
107
+ // [START_EXCLUDE]
108
+ .border(1 .dp, Color .Gray .copy(alpha = 0.5f ), RoundedCornerShape (8 .dp))
109
+ .background(LavenderLight , RoundedCornerShape (8 .dp))
110
+ .clickable {
111
+ onShowDetails()
112
+ }
113
+ .padding(8 .dp)
114
+ // [END_EXCLUDE]
115
+ ) {
116
+ // [START_EXCLUDE]
117
+ Image (
118
+ painter = painterResource(id = R .drawable.cupcake),
119
+ contentDescription = " Cupcake" ,
120
+ modifier = Modifier
121
+ .sharedElement(
122
+ rememberSharedContentState(key = " image" ),
134
123
animatedVisibilityScope = animatedVisibilityScope
135
124
)
125
+ .size(100 .dp)
126
+ .clip(CircleShape ),
127
+ contentScale = ContentScale .Crop
128
+ )
129
+ Text (
130
+ " Cupcake" , fontSize = 21 .sp,
131
+ modifier = Modifier .sharedBounds(
132
+ rememberSharedContentState(key = " title" ),
133
+ animatedVisibilityScope = animatedVisibilityScope
136
134
)
137
- // [END_EXCLUDE]
138
- }
135
+ )
136
+ // [END_EXCLUDE]
139
137
}
140
138
}
139
+ }
141
140
142
- @Composable
143
- private fun DetailsContent (
144
- modifier : Modifier = Modifier ,
145
- onBack : () -> Unit ,
146
- sharedTransitionScope : SharedTransitionScope ,
147
- animatedVisibilityScope : AnimatedVisibilityScope
148
- ) {
149
- with (sharedTransitionScope) {
150
- Column (
151
- modifier = Modifier
152
- .sharedBounds(
153
- rememberSharedContentState(key = " bounds" ),
154
- animatedVisibilityScope = animatedVisibilityScope,
155
- enter = fadeIn(),
156
- exit = fadeOut()
157
- )
158
- // [START_EXCLUDE]
159
- .padding(top = 200 .dp, start = 16 .dp, end = 16 .dp)
160
- .border(1 .dp, Color .Gray .copy(alpha = 0.5f ), RoundedCornerShape (8 .dp))
161
- .background(RoseLight , RoundedCornerShape (8 .dp))
162
- .clickable {
163
- onBack()
164
- }
165
- .padding(8 .dp)
166
- // [END_EXCLUDE]
167
-
168
- ) {
169
- // [START_EXCLUDE]
170
- Image (
171
- painter = painterResource(id = R .drawable.cupcake),
172
- contentDescription = " Cupcake" ,
173
- modifier = Modifier
174
- .sharedElement(
175
- rememberSharedContentState(key = " image" ),
176
- animatedVisibilityScope = animatedVisibilityScope
177
- )
178
- .size(200 .dp)
179
- .clip(CircleShape ),
180
- contentScale = ContentScale .Crop
141
+ @Composable
142
+ private fun DetailsContent (
143
+ modifier : Modifier = Modifier ,
144
+ onBack : () -> Unit ,
145
+ sharedTransitionScope : SharedTransitionScope ,
146
+ animatedVisibilityScope : AnimatedVisibilityScope
147
+ ) {
148
+ with (sharedTransitionScope) {
149
+ Column (
150
+ modifier = Modifier
151
+ .padding(top = 200 .dp, start = 16 .dp, end = 16 .dp)
152
+ .sharedBounds(
153
+ rememberSharedContentState(key = " bounds" ),
154
+ animatedVisibilityScope = animatedVisibilityScope,
155
+ enter = fadeIn(),
156
+ exit = fadeOut(),
157
+ resizeMode = SharedTransitionScope .ResizeMode .ScaleToBounds ()
181
158
)
182
- Text (
183
- " Cupcake" , fontSize = 28 .sp,
184
- modifier = Modifier .sharedBounds(
185
- rememberSharedContentState(key = " title" ),
159
+ // [START_EXCLUDE]
160
+ .border(1 .dp, Color .Gray .copy(alpha = 0.5f ), RoundedCornerShape (8 .dp))
161
+ .background(RoseLight , RoundedCornerShape (8 .dp))
162
+ .clickable {
163
+ onBack()
164
+ }
165
+ .padding(8 .dp)
166
+ // [END_EXCLUDE]
167
+
168
+ ) {
169
+ // [START_EXCLUDE]
170
+ Image (
171
+ painter = painterResource(id = R .drawable.cupcake),
172
+ contentDescription = " Cupcake" ,
173
+ modifier = Modifier
174
+ .sharedElement(
175
+ rememberSharedContentState(key = " image" ),
186
176
animatedVisibilityScope = animatedVisibilityScope
187
177
)
178
+ .size(200 .dp)
179
+ .clip(CircleShape ),
180
+ contentScale = ContentScale .Crop
181
+ )
182
+ Text (
183
+ " Cupcake" , fontSize = 28 .sp,
184
+ modifier = Modifier .sharedBounds(
185
+ rememberSharedContentState(key = " title" ),
186
+ animatedVisibilityScope = animatedVisibilityScope
188
187
)
189
- Text (
190
- " Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur sit amet lobortis velit. " +
191
- " Lorem ipsum dolor sit amet, consectetur adipiscing elit." +
192
- " Curabitur sagittis, lectus posuere imperdiet facilisis, nibh massa " +
193
- " molestie est, quis dapibus orci ligula non magna. Pellentesque rhoncus " +
194
- " hendrerit massa quis ultricies. Curabitur congue ullamcorper leo, at maximus "
195
- )
196
- // [END_EXCLUDE]
197
- }
188
+ )
189
+ Text (
190
+ " Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur sit amet lobortis velit. " +
191
+ " Lorem ipsum dolor sit amet, consectetur adipiscing elit. " +
192
+ " Curabitur sagittis, lectus posuere imperdiet facilisis, nibh massa " +
193
+ " molestie est, quis dapibus orci ligula non magna. Pellentesque rhoncus " +
194
+ " hendrerit massa quis ultricies. Curabitur congue ullamcorper leo, at maximus "
195
+ )
196
+ // [END_EXCLUDE]
198
197
}
199
198
}
200
- // [END android_compose_animations_shared_element_shared_bounds]
201
199
}
200
+ // [END android_compose_animations_shared_element_shared_bounds]
0 commit comments