use cranpose_animation::{spring, AnimationType};
use cranpose_core::State;
use cranpose_macros::composable;
use cranpose_ui::Modifier;
use cranpose_ui::MutableInteractionSource;
use cranpose_ui_graphics::GraphicsLayer;
pub struct LiquidMotion;
impl LiquidMotion {
pub fn snappy() -> AnimationType {
spring(0.85, 900.0)
}
pub fn bouncy() -> AnimationType {
spring(0.55, 500.0)
}
pub fn smooth() -> AnimationType {
spring(1.0, 400.0)
}
pub fn blob_leading() -> AnimationType {
spring(0.8, 900.0)
}
pub fn blob_trailing() -> AnimationType {
spring(0.9, 380.0)
}
}
#[composable]
pub fn liquid_press_scale(
modifier: Modifier,
interaction_source: MutableInteractionSource,
pressed_scale: f32,
) -> (Modifier, State<bool>, State<f32>) {
let pressed = interaction_source.collectIsPressedAsState();
let scale = cranpose_animation::animateFloatAsState(
if pressed.get() {
pressed_scale.max(1.0)
} else {
1.0
},
LiquidMotion::snappy(),
"liquid-press-scale",
);
let content_alpha = cranpose_animation::animateFloatAsState(
if pressed.get() { 0.35 } else { 1.0 },
LiquidMotion::smooth(),
"liquid-press-content",
);
let modifier = modifier.graphics_layer(move || {
let scale = scale.get();
GraphicsLayer {
scale_x: scale,
scale_y: scale,
..Default::default()
}
});
(modifier, pressed, content_alpha)
}