pub struct UseAnimation<Animated: AnimatedValue> { /* private fields */ }Expand description
Animate your elements. Use use_animation to use this.
Implementations§
Source§impl<Animated: AnimatedValue> UseAnimation<Animated>
impl<Animated: AnimatedValue> UseAnimation<Animated>
Sourcepub fn is_running(&self) -> bool
pub fn is_running(&self) -> bool
Checks if there is any animation running.
Sourcepub fn has_run_yet(&self) -> bool
pub fn has_run_yet(&self) -> bool
Checks if it has run yet, by subscribing.
Sourcepub fn peek_has_run_yet(&self) -> bool
pub fn peek_has_run_yet(&self) -> bool
Checks if it has run yet, doesn’t subscribe. Useful for when you just mounted your component.
Sourcepub fn run(&self, direction: AnimDirection)
pub fn run(&self, direction: AnimDirection)
Run the animation with a given AnimDirection
Methods from Deref<Target = Signal<Animated>>§
pub fn point_to(&self, other: Signal<T, S>) -> Result<(), BorrowError>
pub fn point_to(&self, other: Signal<T, S>) -> Result<(), BorrowError>
Point to another signal. This will subscribe the other signal to all subscribers of this signal.
pub fn manually_drop(&self)
pub fn manually_drop(&self)
Drop the value out of the signal, invalidating the signal in the process.
pub fn origin_scope(&self) -> ScopeId
pub fn origin_scope(&self) -> ScopeId
Get the scope the signal was created in.
pub fn id(&self) -> GenerationalBoxId
pub fn id(&self) -> GenerationalBoxId
Get the generational id of the signal.
pub fn write_silent(&self) -> <S as AnyStorage>::Mut<'static, T>
👎Deprecated: This pattern is no longer recommended. Prefer peek or creating new signals instead.
pub fn write_silent(&self) -> <S as AnyStorage>::Mut<'static, T>
peek or creating new signals instead.This pattern is no longer recommended. Prefer peek or creating new signals instead.
This function is the equivalent of the write_silent method on use_ref.
§What you should use instead
§Reading and Writing to data in the same scope
Reading and writing to the same signal in the same scope will cause that scope to rerun forever:
let mut signal = use_signal(|| 0);
// This makes the scope rerun whenever we write to the signal
println!("{}", *signal.read());
// This will rerun the scope because we read the signal earlier in the same scope
*signal.write() += 1;You may have used the write_silent method to avoid this infinite loop with use_ref like this:
let signal = use_signal(|| 0);
// This makes the scope rerun whenever we write to the signal
println!("{}", *signal.read());
// Write silent will not rerun any subscribers
*signal.write_silent() += 1;Instead you can use the peek and write methods instead. The peek method will not subscribe to the current scope which will avoid an infinite loop if you are reading and writing to the same signal in the same scope.
let mut signal = use_signal(|| 0);
// Peek will read the value but not subscribe to the current scope
println!("{}", *signal.peek());
// Write will update any subscribers which does not include the current scope
*signal.write() += 1;§Reading and Writing to different data
§Why is this pattern no longer recommended?
This pattern is no longer recommended because it is very easy to allow your state and UI to grow out of sync. write_silent globally opts out of automatic state updates which can be difficult to reason about.
Lets take a look at an example: main.rs:
fn app() -> Element {
let signal = use_context_provider(|| Signal::new(0));
// We want to log the value of the signal whenever the app component reruns
println!("{}", *signal.read());
rsx! {
button {
// If we don't want to rerun the app component when the button is clicked, we can use write_silent
onclick: move |_| *signal.write_silent() += 1,
"Increment"
}
Child {}
}
}child.rs:
fn Child() -> Element {
let signal: Signal<i32> = use_context();
// It is difficult to tell that changing the button to use write_silent in the main.rs file will cause UI to be out of sync in a completely different file
rsx! {
"{signal}"
}
}Instead peek locally opts out of automatic state updates explicitly for a specific read which is easier to reason about.
Here is the same example using peek: main.rs:
fn app() -> Element {
let mut signal = use_context_provider(|| Signal::new(0));
// We want to log the value of the signal whenever the app component reruns, but we don't want to rerun the app component when the signal is updated so we use peek instead of read
println!("{}", *signal.peek());
rsx! {
button {
// We can use write like normal and update the child component automatically
onclick: move |_| *signal.write() += 1,
"Increment"
}
Child {}
}
}child.rs:
fn Child() -> Element {
let signal: Signal<i32> = use_context();
rsx! {
"{signal}"
}
}Trait Implementations§
Source§impl<Animated: Clone + AnimatedValue> Clone for UseAnimation<Animated>
impl<Animated: Clone + AnimatedValue> Clone for UseAnimation<Animated>
Source§fn clone(&self) -> UseAnimation<Animated>
fn clone(&self) -> UseAnimation<Animated>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<Animated: AnimatedValue> Deref for UseAnimation<Animated>
impl<Animated: AnimatedValue> Deref for UseAnimation<Animated>
Source§impl<Animated: PartialEq + AnimatedValue> PartialEq for UseAnimation<Animated>
impl<Animated: PartialEq + AnimatedValue> PartialEq for UseAnimation<Animated>
impl<T: AnimatedValue> Copy for UseAnimation<T>
impl<Animated: AnimatedValue> StructuralPartialEq for UseAnimation<Animated>
Auto Trait Implementations§
impl<Animated> Freeze for UseAnimation<Animated>
impl<Animated> !RefUnwindSafe for UseAnimation<Animated>
impl<Animated> !Send for UseAnimation<Animated>
impl<Animated> !Sync for UseAnimation<Animated>
impl<Animated> Unpin for UseAnimation<Animated>where
Animated: Unpin,
impl<Animated> !UnwindSafe for UseAnimation<Animated>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> InitializeFromFunction<T> for T
impl<T> InitializeFromFunction<T> for T
§fn initialize_from_function(f: fn() -> T) -> T
fn initialize_from_function(f: fn() -> T) -> T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more