Skip to content

Commit

Permalink
use f for keyframe (#652)
Browse files Browse the repository at this point in the history
  • Loading branch information
jrmoulton authored Nov 1, 2024
1 parent 450aa8b commit 9309eb8
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
14 changes: 7 additions & 7 deletions examples/animations/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ fn app_view() -> impl IntoView {
let animation = RwSignal::new(
Animation::new()
.duration(5.seconds())
.keyframe(0, |kf| kf.computed_style())
.keyframe(50, |kf| {
kf.style(|s| s.background(Color::BLACK).size(30, 30))
.keyframe(0, |f| f.computed_style())
.keyframe(50, |f| {
f.style(|s| s.background(Color::BLACK).size(30, 30))
.ease_in()
})
.keyframe(100, |kf| {
kf.style(|s| s.background(Color::AQUAMARINE).size(10, 300))
.keyframe(100, |f| {
f.style(|s| s.background(Color::AQUAMARINE).size(10, 300))
.ease_out()
})
.repeat(true)
Expand All @@ -36,8 +36,8 @@ fn app_view() -> impl IntoView {
.style(|s| s.background(Color::BLUE).size(50, 100))
.animation(move |_| animation.get())
.animation(move |a| {
a.keyframe(100, |kf| {
kf.style(|s| s.border(5.).border_color(Color::PURPLE))
a.keyframe(100, |f| {
f.style(|s| s.border(5.).border_color(Color::PURPLE))
})
.duration(5.seconds())
.repeat(true)
Expand Down
2 changes: 1 addition & 1 deletion examples/view-transition/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl ViewSwitcher {
.style(|s| s.padding(8))
.animation(|a| {
a.view_transition()
.keyframe(0, |kf| kf.style(|s| s.padding(0)))
.keyframe(0, |f| f.style(|s| s.padding(0)))
})
}
}
Expand Down
16 changes: 8 additions & 8 deletions src/animate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,28 +421,28 @@ impl Animation {
self.run_on_create(true)
.run_on_remove(true)
.initial_state(AnimStateCommand::Stop)
.keyframe(0, |kf| kf.computed_style().ease(Spring::gentle()))
.keyframe(100, |kf| kf.computed_style().ease(Spring::gentle()))
.keyframe(0, |f| f.computed_style().ease(Spring::gentle()))
.keyframe(100, |f| f.computed_style().ease(Spring::gentle()))
}

/// Quickly set an animation to be a view transition and override the default easing function on keyframes 0 and 100.
pub fn view_transition_with_ease(self, ease: impl Easing + 'static + Clone) -> Self {
self.view_transition()
.keyframe(0, |kf| kf.computed_style().ease(ease.clone()))
.keyframe(100, |kf| kf.computed_style().ease(ease.clone()))
.keyframe(0, |f| f.computed_style().ease(ease.clone()))
.keyframe(100, |f| f.computed_style().ease(ease.clone()))
}

/// Quickly set an animation to be a view transition and set the animation to animate from scale 0% to the "normal" computed style of a view (the view with no animations applied).
pub fn scale_effect(self) -> Self {
self.view_transition()
.keyframe(0, |kf| kf.style(|s| s.scale(0.pct())))
.keyframe(0, |f| f.style(|s| s.scale(0.pct())))
.debug_name("Scale the width and height from zero to the default")
}

/// Quickly set an animation to be a view transition and set the animation to animate from size(0, 0) to the "normal" computed style of a view (the view with no animations applied).
pub fn scale_size_effect(self) -> Self {
self.view_transition()
.keyframe(0, |kf| kf.style(|s| s.size(0, 0)))
.keyframe(0, |f| f.style(|s| s.size(0, 0)))
.debug_name("Scale the width and height from zero to the default")
}
}
Expand Down Expand Up @@ -503,8 +503,8 @@ impl Animation {
) -> Self {
let frame = key_frame(KeyFrame::new(frame_id));
let frame_style = frame.style.clone();
if let Some(kf) = self.key_frames.insert(frame_id, frame) {
if let KeyFrameStyle::Style(style) = kf.style {
if let Some(f) = self.key_frames.insert(frame_id, frame) {
if let KeyFrameStyle::Style(style) = f.style {
for prop in style.style_props() {
self.cache.remove_prop(prop, frame_id);
}
Expand Down
10 changes: 5 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,13 @@
//! .style(|s| s.background(Color::RED).size(500, 100))
//! .animation(move |a| {
//! a.duration(5.seconds())
//! .keyframe(0, |kf| kf.computed_style())
//! .keyframe(50, |kf| {
//! kf.style(|s| s.background(Color::BLACK).size(30, 30))
//! .keyframe(0, |f| f.computed_style())
//! .keyframe(50, |f| {
//! f.style(|s| s.background(Color::BLACK).size(30, 30))
//! .ease_in()
//! })
//! .keyframe(100, |kf| {
//! kf.style(|s| s.background(Color::AQUAMARINE).size(10, 300))
//! .keyframe(100, |f| {
//! f.style(|s| s.background(Color::AQUAMARINE).size(10, 300))
//! .ease_out()
//! })
//! .auto_reverse(true)
Expand Down

0 comments on commit 9309eb8

Please sign in to comment.