반응형
이전에 작성한 분할 화면의 Compose 코드
@Composable
fun SplitLayer(
topLayer: @Composable (modifier: Modifier) -> Unit,
bottomLayer: @Composable (modifier: Modifier) -> Unit,
dragView: @Composable (modifier: Modifier) -> Unit,
min: Float = 0.1f,
max: Float = 0.95f,
modifier: Modifier = Modifier
) {
var height by remember { mutableStateOf(0) }
var percent by remember { mutableFloatStateOf(0.5f) }
Box(
modifier = modifier
.clipToBounds()
.onGloballyPositioned {
height = it.size.height
}
) {
Column(
modifier = Modifier
.fillMaxSize()
) {
val topWeight = 0.5f - (0.5f - percent)
val bottomWeight = 0.5f + (0.5f - percent)
topLayer(
Modifier
.fillMaxWidth()
.weight(topWeight)
)
bottomLayer(
Modifier
.fillMaxWidth()
.weight(bottomWeight)
)
}
var dragHeight by remember { mutableStateOf(0) }
val y = (height * percent) - (dragHeight / 2)
Surface(
color = Color.Transparent,
modifier = Modifier
.fillMaxWidth()
.offset { IntOffset(x = 0, y = y.roundToInt()) }
.onGloballyPositioned { dragHeight = it.size.height }
.pointerInput(Unit) {
detectDragGestures { change, dragAmount ->
change.consume()
percent = (percent + (dragAmount.y / height)).coerceIn(min, max)
}
}
) {
dragView(Modifier)
}
}
}
반응형
'안드로이드 > 개발관련(Kotlin)' 카테고리의 다른 글
텍스트를 클릭하여 이벤트를 실행하는 Text (Compose) (0) | 2024.07.30 |
---|---|
눈금이 있는 Slide (Compose) (0) | 2024.07.30 |
화면 분할 및 크기 조절 (Layout Split) (0) | 2024.05.15 |
[Android] Number Picker (0) | 2024.01.03 |
안드로이드 BottomNavigationView (0) | 2023.04.04 |