I’m using a `animateFloatAsState` in my modifier w...
# compose
m
I’m using a
animateFloatAsState
in my modifier which works well for animating my view. However I don’t want to animate changes when using a gesture since this creates a delayed appearance. Is it possible to conditionally animate a state? or am I taking the wrong approach?
Copy code
fun Modifier.expandable(
    handler: MinimizableViewHandler,
    settings: ExpandableSettings
): Modifier = composed {
    val animatedDraggedDelta by animateFloatAsState(
        targetValue = handler.draggedDelta,
    )
    Modifier
        .padding(horizontal = 10 * (1.0 - handler.draggedDelta).dp)
        .padding(bottom = settings.bottomPadding + (settings.expandedBottomPadding * handler.draggedDelta))
        .height((settings.minimizedHeight.value + (handler.draggedDelta * (settings.maximizedHeight.value - settings.minimizedHeight.value))).dp)
        .border(width = 1.dp, color = Color.White.copy(alpha = 1.0f - animatedDraggedDelta), shape = RoundedCornerShape((settings.cornerRadius.value - (20 * animatedDraggedDelta)).dp))
        .clip(RoundedCornerShape((settings.cornerRadius.value - (20 * handler.draggedDelta)).dp))
}
e
you'll have control over that if you drop down to the https://developer.android.com/develop/ui/compose/animation/value-based#animatable API
👍 1
m
right I did wonder. then use
snapTo(targetValue
to update without animation
I think my issue was, I wasn’t sure if this would work on a modifier where by I might have a class to manage the state and dragged delta. As my example the
MinimizableViewHandler