Created
May 27, 2020 11:21
-
-
Save ahmedrizwan/a698e8b55ec76b6c1f34c3cbbc4359cd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Composable | |
fun TopView( | |
boxHeight: Dp, | |
drag: Drag | |
) { | |
val position = drag.position | |
val flingConfig = drag.flingConfig | |
val yOffset = with(DensityAmbient.current) { position.value.toDp() } | |
val scrollerPosition = ScrollerPosition() | |
// scroll the history list to bottom when dragging the top panel | |
// 90dp history item height is an approximation | |
scrollerPosition.smoothScrollBy(operationsHistory.size * 90.dp.value) | |
Card( | |
Modifier.offset(y = yOffset, x = 0.dp).fillMaxWidth() | |
.draggable( | |
startDragImmediately = position.isRunning, | |
dragDirection = DragDirection.Vertical, | |
onDragStopped = { position.fling(flingConfig, it) } | |
) { delta -> | |
position.snapTo(position.value + delta) | |
// consume all delta no matter the bounds to avoid nested dragging (as example) | |
delta | |
} | |
.preferredHeight(boxHeight), | |
elevation = 4.dp, | |
shape = MaterialTheme.shapes.large, | |
color = Color.White | |
) { | |
Column( | |
modifier = Modifier.fillMaxSize(), | |
verticalArrangement = Arrangement.Bottom, | |
horizontalGravity = ContentGravity.CenterHorizontally | |
) { | |
HistoryTopBar() | |
HistoryList(scrollerPosition) | |
Spacer(modifier = Modifier.preferredHeight(2.dp)) | |
CollapsableContent(boxHeight, position) | |
RoundedDash() | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment