amar_1995
03/10/2020, 8:08 PMmatvei
03/11/2020, 9:43 PMvipulasri
03/12/2020, 5:14 AMswipe-to-refresh
doesn't support dsl as of now.matvei
03/12/2020, 10:38 AMvipulasri
03/12/2020, 10:40 AMmatvei
03/12/2020, 10:46 AM@Composable
fun SwipeToRefreshLayout(
resheshingState: Boolean,
onRefresh: () -> Unit,
swipeIcon: @Composable() () -> Unit,
content: @Composable() () -> Unit
) {
val size = with(DensityAmbient.current) { 100.dp.toPx().value }
//min is below - to hide
val min = -size
val max = size * 2
StateDraggable(
state = resheshingState,
onStateChange = { if (it) onRefresh() },
anchorsToState = listOf(min to false, max to true),
animationBuilder = TweenBuilder(),
dragDirection = DragDirection.Vertical,
minValue = min,
maxValue = max
) { value ->
val dpOffset = with(DensityAmbient.current) {
(value.value * 0.5).px.toDp()
}
Stack {
content()
Box(LayoutGravity.TopCenter + LayoutOffset(0.dp, dpOffset)) {
swipeIcon()
}
}
}
}
}
vipulasri
03/12/2020, 10:47 AMRyan Mentley
03/13/2020, 8:22 AM