[yew-devel] [PATCH yew-widget-toolkit v2 05/12] touch: page stack: don't use animation by default

Dominik Csapak d.csapak at proxmox.com
Mon Jun 30 10:25:02 CEST 2025


only when set from outside.

This changes the type to an `Oprtion` and omits the state change to
grow/shrink when the animation_style is `None` to not show an animation
in that case.

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
new in v2
 src/touch/page_stack.rs | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/src/touch/page_stack.rs b/src/touch/page_stack.rs
index bb05058..42299ae 100644
--- a/src/touch/page_stack.rs
+++ b/src/touch/page_stack.rs
@@ -1,5 +1,6 @@
 use std::rc::Rc;
 
+use yew::html::IntoPropValue;
 use yew::prelude::*;
 use yew::virtual_dom::{VComp, VNode};
 //use yew::html::IntoEventCallback;
@@ -41,8 +42,8 @@ pub struct PageStack {
     #[prop_or_default]
     stack: Vec<Html>,
 
-    #[prop_or(PageAnimationStyle::Push)]
-    animation_style: PageAnimationStyle,
+    #[prop_or_default]
+    animation_style: Option<PageAnimationStyle>,
 }
 
 impl PageStack {
@@ -50,8 +51,11 @@ impl PageStack {
         yew::props!(Self { stack: pages })
     }
 
-    pub fn animation_style(mut self, style: PageAnimationStyle) -> Self {
-        self.animation_style = style;
+    pub fn animation_style(
+        mut self,
+        style: impl IntoPropValue<Option<PageAnimationStyle>>,
+    ) -> Self {
+        self.animation_style = style.into_prop_value();
         self
     }
 }
@@ -112,10 +116,12 @@ impl Component for PwtPageStack {
         let props = ctx.props();
 
         if let Some(last) = self.stack.last() {
-            match props.stack.len().cmp(&self.stack.len()) {
-                std::cmp::Ordering::Less => self.state = ViewState::Shrink(last.clone()),
-                std::cmp::Ordering::Greater => self.state = ViewState::Grow(last.clone()),
-                _ => {}
+            if props.animation_style.is_some() {
+                match props.stack.len().cmp(&self.stack.len()) {
+                    std::cmp::Ordering::Less => self.state = ViewState::Shrink(last.clone()),
+                    std::cmp::Ordering::Greater => self.state = ViewState::Grow(last.clone()),
+                    _ => {}
+                }
             }
         }
 
-- 
2.39.5





More information about the yew-devel mailing list