Here is my Code ! ;) And my Box is aligned at the top left, but I want the box in the center. You know how I can do this?
OptIn(ExperimentalWearMaterialApi::class)
@Composable
fun OnTouch() {
val width = 100.dp
val squareSize = 50.dp
val swipeableState = rememberSwipeableState(0)
val sizePx = with(LocalDensity.current) { squareSize.toPx() }
val anchors = mapOf(0f to 0, sizePx to 1) // Maps anchor points (in px) to states
Box(
contentAlignment = Alignment.Center, modifier = Modifier
.width(width)
.swipeable(
state = swipeableState,
anchors = anchors,
thresholds = { _, _ -> FractionalThreshold(0.3f) },
orientation = Orientation.Horizontal
)
.background(Color.LightGray)
) {
Box(
Modifier
.offset { IntOffset(swipeableState.offset.value.roundToInt(), 0) }
.size(squareSize)
.background(Color.DarkGray)
)
}
}
thanks in advance ! ;) I did search the documentation but found nothing...