@@ -19,6 +19,7 @@ package com.example.owl.ui.course
19
19
import androidx.compose.animation.core.animateDpAsState
20
20
import androidx.compose.foundation.Image
21
21
import androidx.compose.foundation.clickable
22
+ import androidx.compose.foundation.gestures.Orientation.Vertical
22
23
import androidx.compose.foundation.layout.Box
23
24
import androidx.compose.foundation.layout.BoxWithConstraints
24
25
import androidx.compose.foundation.layout.Column
@@ -28,10 +29,10 @@ import androidx.compose.foundation.layout.Spacer
28
29
import androidx.compose.foundation.layout.aspectRatio
29
30
import androidx.compose.foundation.layout.fillMaxSize
30
31
import androidx.compose.foundation.layout.fillMaxWidth
32
+ import androidx.compose.foundation.layout.height
31
33
import androidx.compose.foundation.layout.offset
32
34
import androidx.compose.foundation.layout.padding
33
- import androidx.compose.foundation.layout.preferredHeight
34
- import androidx.compose.foundation.layout.preferredSize
35
+ import androidx.compose.foundation.layout.size
35
36
import androidx.compose.foundation.lazy.LazyColumn
36
37
import androidx.compose.foundation.lazy.LazyListState
37
38
import androidx.compose.foundation.lazy.LazyRow
@@ -59,12 +60,12 @@ import androidx.compose.material.primarySurface
59
60
import androidx.compose.material.rememberSwipeableState
60
61
import androidx.compose.material.swipeable
61
62
import androidx.compose.runtime.Composable
62
- import androidx.compose.runtime.Providers
63
+ import androidx.compose.runtime.CompositionLocalProvider
63
64
import androidx.compose.runtime.getValue
64
65
import androidx.compose.runtime.remember
66
+ import androidx.compose.runtime.rememberCoroutineScope
65
67
import androidx.compose.ui.Alignment
66
68
import androidx.compose.ui.Modifier
67
- import androidx.compose.ui.gesture.scrollorientationlocking.Orientation
68
69
import androidx.compose.ui.graphics.Color
69
70
import androidx.compose.ui.graphics.graphicsLayer
70
71
import androidx.compose.ui.platform.LocalDensity
@@ -93,6 +94,7 @@ import dev.chrisbanes.accompanist.insets.LocalWindowInsets
93
94
import dev.chrisbanes.accompanist.insets.navigationBarsPadding
94
95
import dev.chrisbanes.accompanist.insets.statusBarsPadding
95
96
import dev.chrisbanes.accompanist.insets.toPaddingValues
97
+ import kotlinx.coroutines.launch
96
98
97
99
private val FabSize = 56 .dp
98
100
private const val ExpandedSheetAlpha = 0.96f
@@ -121,10 +123,15 @@ fun CourseDetails(
121
123
val sheetState = rememberSwipeableState(SheetState .Closed )
122
124
val fabSize = with (LocalDensity .current) { FabSize .toPx() }
123
125
val dragRange = constraints.maxHeight - fabSize
126
+ val scope = rememberCoroutineScope()
124
127
125
128
backHandler(
126
- enabled = sheetState.value == SheetState .Open ,
127
- onBack = { sheetState.animateTo(SheetState .Closed ) }
129
+ enabled = sheetState.currentValue == SheetState .Open ,
130
+ onBack = {
131
+ scope.launch {
132
+ sheetState.animateTo(SheetState .Closed )
133
+ }
134
+ }
128
135
)
129
136
130
137
Box (
@@ -137,7 +144,7 @@ fun CourseDetails(
137
144
- dragRange to SheetState .Open
138
145
),
139
146
thresholds = { _, _ -> FractionalThreshold (0.5f ) },
140
- orientation = Orientation . Vertical
147
+ orientation = Vertical
141
148
)
142
149
) {
143
150
val openFraction = if (sheetState.offset.value.isNaN()) {
@@ -152,7 +159,9 @@ fun CourseDetails(
152
159
this @BoxWithConstraints.constraints.maxWidth.toFloat(),
153
160
this @BoxWithConstraints.constraints.maxHeight.toFloat()
154
161
) { state ->
155
- sheetState.animateTo(state)
162
+ scope.launch {
163
+ sheetState.animateTo(state)
164
+ }
156
165
}
157
166
}
158
167
}
@@ -205,15 +214,15 @@ private fun CourseDescriptionHeader(
205
214
contentDescription = null ,
206
215
modifier = Modifier
207
216
.padding(bottom = 4 .dp)
208
- .preferredSize (24 .dp)
217
+ .size (24 .dp)
209
218
.align(Alignment .CenterVertically )
210
219
)
211
220
Spacer (modifier = Modifier .weight(1f ))
212
221
}
213
222
OutlinedAvatar (
214
223
url = course.instructor,
215
224
modifier = Modifier
216
- .preferredSize (40 .dp)
225
+ .size (40 .dp)
217
226
.align(Alignment .BottomCenter )
218
227
.offset(y = 20 .dp) // overlap bottom of image
219
228
)
@@ -244,8 +253,8 @@ private fun CourseDescriptionBody(course: Course) {
244
253
.fillMaxWidth()
245
254
.padding(horizontal = 16 .dp)
246
255
)
247
- Spacer (modifier = Modifier .preferredHeight (16 .dp))
248
- Providers (LocalContentAlpha provides ContentAlpha .medium) {
256
+ Spacer (modifier = Modifier .height (16 .dp))
257
+ CompositionLocalProvider (LocalContentAlpha provides ContentAlpha .medium) {
249
258
Text (
250
259
text = stringResource(id = R .string.course_desc),
251
260
style = MaterialTheme .typography.body1,
@@ -264,7 +273,7 @@ private fun CourseDescriptionBody(course: Course) {
264
273
.fillMaxWidth()
265
274
.padding(16 .dp)
266
275
)
267
- Providers (LocalContentAlpha provides ContentAlpha .medium) {
276
+ CompositionLocalProvider (LocalContentAlpha provides ContentAlpha .medium) {
268
277
Text (
269
278
text = stringResource(id = R .string.needs),
270
279
style = MaterialTheme .typography.body1,
@@ -318,7 +327,7 @@ private fun RelatedCourses(
318
327
titleStyle = MaterialTheme .typography.body2,
319
328
modifier = Modifier
320
329
.padding(end = 8 .dp)
321
- .preferredSize (288 .dp, 80 .dp),
330
+ .size (288 .dp, 80 .dp),
322
331
iconSize = 14 .dp
323
332
)
324
333
}
@@ -424,7 +433,7 @@ private fun Lessons(
424
433
val fabAlpha = lerp(1f , 0f , 0f , 0.15f , openFraction)
425
434
Box (
426
435
modifier = Modifier
427
- .preferredSize (FabSize )
436
+ .size (FabSize )
428
437
.padding(start = 16 .dp, top = 8 .dp) // visually center contents
429
438
.graphicsLayer { alpha = fabAlpha }
430
439
) {
@@ -452,7 +461,7 @@ private fun Lesson(lesson: Lesson) {
452
461
NetworkImage (
453
462
url = lesson.imageUrl,
454
463
contentDescription = null ,
455
- modifier = Modifier .preferredSize (112 .dp, 64 .dp)
464
+ modifier = Modifier .size (112 .dp, 64 .dp)
456
465
)
457
466
Column (
458
467
modifier = Modifier
@@ -465,15 +474,15 @@ private fun Lesson(lesson: Lesson) {
465
474
maxLines = 2 ,
466
475
overflow = TextOverflow .Ellipsis
467
476
)
468
- Providers (LocalContentAlpha provides ContentAlpha .medium) {
477
+ CompositionLocalProvider (LocalContentAlpha provides ContentAlpha .medium) {
469
478
Row (
470
479
modifier = Modifier .padding(top = 4 .dp),
471
480
verticalAlignment = Alignment .CenterVertically
472
481
) {
473
482
Icon (
474
483
imageVector = Icons .Rounded .PlayCircleOutline ,
475
484
contentDescription = null ,
476
- modifier = Modifier .preferredSize (16 .dp)
485
+ modifier = Modifier .size (16 .dp)
477
486
)
478
487
Text (
479
488
modifier = Modifier .padding(start = 4 .dp),
0 commit comments