1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
@Composable fun ComposableSample() { var blockSize = 48.dp var blockSizePx = with(LocalDensity.current) { blockSize.toPx() } var swipeableState = rememberSwipeableState(initialValue = Status.CLOSE) var anchors = mapOf( 0f to Status.CLOSE, blockSizePx to Status.OPEN ) Box( modifier = Modifier .size( height = blockSize, width = blockSize * 2 ) .background(Color.LightGray) ) { Box( modifier = Modifier .swipeable( state = swipeableState, anchors = anchors, thresholds = { from, to -> if (from == Status.CLOSE) { FractionalThreshold(0.3f) } else { FractionalThreshold(0.5f) } }, orientation = Orientation.Horizontal, ) .offset { IntOffset(swipeableState.offset.value.toInt(), 0) } .size(blockSize) .background(Color.DarkGray) ) } }
enum class Status { CLOSE, OPEN }
|