diff --git a/core/embed/rust/src/ui/component/swipe_detect.rs b/core/embed/rust/src/ui/component/swipe_detect.rs index f827c55d6..c266665f1 100644 --- a/core/embed/rust/src/ui/component/swipe_detect.rs +++ b/core/embed/rust/src/ui/component/swipe_detect.rs @@ -3,6 +3,7 @@ use crate::{ ui::{ animation::Animation, component::{Event, EventCtx, SwipeDirection}, + constant::screen, event::TouchEvent, geometry::{Offset, Point}, util::animation_disabled, @@ -200,6 +201,46 @@ impl SwipeDetect { ((val as f32 / Self::DISTANCE as f32) * Self::PROGRESS_MAX as f32) as u16 } + fn eval_anim_frame(&mut self, ctx: &mut EventCtx) -> Option { + if let Some(locked) = self.locked { + let mut finish = false; + let res = if let Some(animation) = &self.final_animation { + if animation.finished(Instant::now()) { + finish = true; + if animation.to != 0 { + Some(SwipeDetectMsg::Trigger(locked)) + } else { + Some(SwipeDetectMsg::Move(locked, 0)) + } + } else { + ctx.request_anim_frame(); + ctx.request_paint(); + if animation_disabled() { + None + } else { + Some(SwipeDetectMsg::Move( + locked, + animation.value(Instant::now()).max(0) as u16, + )) + } + } + } else { + None + }; + + if finish { + self.locked = None; + ctx.request_anim_frame(); + ctx.request_paint(); + self.final_animation = None; + self.moved = 0; + } + + return res; + } + None + } + pub fn trigger(&mut self, ctx: &mut EventCtx, dir: SwipeDirection, config: SwipeConfig) { ctx.request_anim_frame(); ctx.request_paint(); @@ -232,8 +273,12 @@ impl SwipeDetect { ) -> Option { match (event, self.origin) { (Event::Touch(TouchEvent::TouchStart(pos)), _) => { - // Mark the starting position of this touch. - self.origin.replace(pos); + if self.final_animation.is_none() { + // Mark the starting position of this touch. + self.origin.replace(pos); + } else { + return self.eval_anim_frame(ctx); + } } (Event::Touch(TouchEvent::TouchMove(pos)), Some(origin)) => { if self.final_animation.is_none() { @@ -261,8 +306,6 @@ impl SwipeDetect { } }; - // Todo trigger an action if distance is met - if let Some(SwipeDetectMsg::Move(_, progress)) = res { self.moved = progress; } @@ -272,6 +315,8 @@ impl SwipeDetect { } return res; + } else { + return self.eval_anim_frame(ctx); } } (Event::Touch(TouchEvent::TouchEnd(pos)), Some(origin)) => { @@ -326,45 +371,12 @@ impl SwipeDetect { return Some(SwipeDetectMsg::Trigger(locked)); } return None; + } else { + return self.eval_anim_frame(ctx); } } (Event::Timer(EventCtx::ANIM_FRAME_TIMER), _) => { - if let Some(locked) = self.locked { - let mut finish = false; - let res = if let Some(animation) = &self.final_animation { - if animation.finished(Instant::now()) { - finish = true; - if animation.to != 0 { - Some(SwipeDetectMsg::Trigger(locked)) - } else { - Some(SwipeDetectMsg::Move(locked, 0)) - } - } else { - ctx.request_anim_frame(); - ctx.request_paint(); - if animation_disabled() { - None - } else { - Some(SwipeDetectMsg::Move( - locked, - animation.value(Instant::now()).max(0) as u16, - )) - } - } - } else { - None - }; - - if finish { - self.locked = None; - ctx.request_anim_frame(); - ctx.request_paint(); - self.final_animation = None; - self.moved = 0; - } - - return res; - } + return self.eval_anim_frame(ctx); } _ => { // Do nothing.