Skip to content

Instantly share code, notes, and snippets.

@ahmedrizwan
Created May 27, 2020 11:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ahmedrizwan/a698e8b55ec76b6c1f34c3cbbc4359cd to your computer and use it in GitHub Desktop.
Save ahmedrizwan/a698e8b55ec76b6c1f34c3cbbc4359cd to your computer and use it in GitHub Desktop.
@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