in Owl/app/src/main/java/com/example/owl/ui/course/CourseDetails.kt [117:170]
fun CourseDetails(
course: Course,
selectCourse: (Long) -> Unit,
upPress: () -> Unit
) {
PinkTheme {
BoxWithConstraints {
val sheetState = rememberSwipeableState(SheetState.Closed)
val fabSize = with(LocalDensity.current) { FabSize.toPx() }
val dragRange = constraints.maxHeight - fabSize
val scope = rememberCoroutineScope()
BackHandler(
enabled = sheetState.currentValue == SheetState.Open,
onBack = {
scope.launch {
sheetState.animateTo(SheetState.Closed)
}
}
)
Box(
// The Lessons sheet is initially closed and appears as a FAB. Make it openable by
// swiping or clicking the FAB.
Modifier.swipeable(
state = sheetState,
anchors = mapOf(
0f to SheetState.Closed,
-dragRange to SheetState.Open
),
thresholds = { _, _ -> FractionalThreshold(0.5f) },
orientation = Vertical
)
) {
val openFraction = if (sheetState.offset.value.isNaN()) {
0f
} else {
-sheetState.offset.value / dragRange
}.coerceIn(0f, 1f)
CourseDescription(course, selectCourse, upPress)
LessonsSheet(
course,
openFraction,
this@BoxWithConstraints.constraints.maxWidth.toFloat(),
this@BoxWithConstraints.constraints.maxHeight.toFloat()
) { state ->
scope.launch {
sheetState.animateTo(state)
}
}
}
}
}
}