Skip to content

Commit

Permalink
fix animation view state again
Browse files Browse the repository at this point in the history
  • Loading branch information
jrmoulton committed Sep 4, 2024
1 parent 2aa0bad commit 13d9a08
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
9 changes: 5 additions & 4 deletions src/animate/animation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ pub enum Animate {
#[derive(Clone)]
pub struct Animation {
pub(crate) state: AnimState,
pub(crate) view_state: RwSignal<SmallVec<[(ViewId, StackOffset<Animation>); 1]>>,
pub(crate) view_state: SmallVec<[RwSignal<SmallVec<[(ViewId, StackOffset<Animation>); 1]>>; 1]>,
// This easing is used for when animating towards the default style (the style before the animation is applied).
// pub(crate) easing: Easing,
pub(crate) auto_reverse: bool,
Expand All @@ -107,7 +107,7 @@ impl Default for Animation {
fn default() -> Self {
Animation {
state: AnimState::Idle,
view_state: RwSignal::new(SmallVec::new()),
view_state: SmallVec::new_const(),
auto_reverse: false,
delay: Duration::ZERO,
duration: Duration::from_secs(1),
Expand Down Expand Up @@ -307,9 +307,10 @@ impl Animation {
command: impl Fn() -> AnimStateCommand + 'static,
apply_inital: bool,
) -> Self {
let view_state = self.view_state;
let states = RwSignal::new(SmallVec::new_const());
self.view_state.push(states);
let initial_command = create_updater(command, move |command| {
for (view_id, stack_offset) in view_state.get_untracked() {
for (view_id, stack_offset) in states.get_untracked() {
view_id.update_animation_state(stack_offset, command)
}
});
Expand Down
4 changes: 0 additions & 4 deletions src/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use std::{any::Any, cell::RefCell, rc::Rc};

use floem_reactive::SignalUpdate;
use floem_winit::window::WindowId;
use peniko::kurbo::{Insets, Point, Rect, Size};
use slotmap::new_key_type;
Expand Down Expand Up @@ -335,9 +334,6 @@ impl ViewId {

pub(crate) fn update_animation(&self, offset: StackOffset<Animation>, animation: Animation) {
let state = self.state();
animation
.view_state
.update(move |stack| stack.push((*self, offset)));
state.borrow_mut().animation.set(offset, animation);
self.request_style();
}
Expand Down
7 changes: 4 additions & 3 deletions src/views/decorator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,9 +322,10 @@ pub trait Decorators: IntoView<V = Self::DV> + Sized {
view_id.update_animation(offset, animation);
},
);
initial_animation
.view_state
.update(|stack| stack.push((view_id, offset)));
for effect_state in &initial_animation.view_state {
effect_state.update(|stack| stack.push((view_id, offset)));
}

state.borrow_mut().animation.push(initial_animation);

view
Expand Down

0 comments on commit 13d9a08

Please sign in to comment.