mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-08-02 11:58:32 +00:00
refactor(core/rust): create a single code path allowed to modify SwipeFlow state
This commit is contained in:
parent
7b6ce56ac3
commit
e9bb598d2f
@ -147,25 +147,35 @@ impl SwipeFlow {
|
|||||||
&mut self.store[self.state.index()]
|
&mut self.store[self.state.index()]
|
||||||
}
|
}
|
||||||
|
|
||||||
fn goto(&mut self, ctx: &mut EventCtx, attach_type: AttachType) {
|
fn update_page_count(&mut self, attach_type: AttachType) {
|
||||||
|
// update page count
|
||||||
|
self.internal_pages = self.current_page_mut().get_internal_page_count() as u16;
|
||||||
|
// reset internal state:
|
||||||
|
self.internal_state = if let Swipe(Direction::Down) = attach_type {
|
||||||
|
// if coming from below, set to the last page
|
||||||
|
self.internal_pages.saturating_sub(1)
|
||||||
|
} else {
|
||||||
|
// else reset to the first page
|
||||||
|
0
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Transition to a different state.
|
||||||
|
///
|
||||||
|
/// This is the only way to change the current flow state.
|
||||||
|
fn goto(&mut self, ctx: &mut EventCtx, new_state: FlowState, attach_type: AttachType) {
|
||||||
|
// update current page
|
||||||
|
self.state = new_state;
|
||||||
|
|
||||||
|
// reset and unlock swipe config
|
||||||
self.swipe = SwipeDetect::new();
|
self.swipe = SwipeDetect::new();
|
||||||
self.allow_swipe = true;
|
self.allow_swipe = true;
|
||||||
|
|
||||||
|
// send an Attach event to the new page
|
||||||
self.current_page_mut()
|
self.current_page_mut()
|
||||||
.event(ctx, Event::Attach(attach_type));
|
.event(ctx, Event::Attach(attach_type));
|
||||||
|
|
||||||
self.internal_pages = self.current_page_mut().get_internal_page_count() as u16;
|
self.update_page_count(attach_type);
|
||||||
|
|
||||||
match attach_type {
|
|
||||||
Swipe(Direction::Up) => {
|
|
||||||
self.internal_state = 0;
|
|
||||||
}
|
|
||||||
Swipe(Direction::Down) => {
|
|
||||||
self.internal_state = self.internal_pages.saturating_sub(1);
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx.request_paint();
|
ctx.request_paint();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -191,6 +201,10 @@ impl SwipeFlow {
|
|||||||
let mut decision = Decision::Nothing;
|
let mut decision = Decision::Nothing;
|
||||||
let mut return_transition: AttachType = AttachType::Initial;
|
let mut return_transition: AttachType = AttachType::Initial;
|
||||||
|
|
||||||
|
if let Event::Attach(attach_type) = event {
|
||||||
|
self.update_page_count(attach_type);
|
||||||
|
}
|
||||||
|
|
||||||
let mut attach = false;
|
let mut attach = false;
|
||||||
|
|
||||||
let e = if self.allow_swipe {
|
let e = if self.allow_swipe {
|
||||||
@ -199,8 +213,6 @@ impl SwipeFlow {
|
|||||||
.get_swipe_config()
|
.get_swipe_config()
|
||||||
.with_pagination(self.internal_state, self.internal_pages);
|
.with_pagination(self.internal_state, self.internal_pages);
|
||||||
|
|
||||||
self.internal_pages = page.get_internal_page_count() as u16;
|
|
||||||
|
|
||||||
match self.swipe.event(ctx, event, config) {
|
match self.swipe.event(ctx, event, config) {
|
||||||
Some(SwipeEvent::End(dir)) => {
|
Some(SwipeEvent::End(dir)) => {
|
||||||
if let Some(override_decision) = self.decision_override.take() {
|
if let Some(override_decision) = self.decision_override.take() {
|
||||||
@ -270,8 +282,7 @@ impl SwipeFlow {
|
|||||||
|
|
||||||
match decision {
|
match decision {
|
||||||
Decision::Transition(new_state, attach) => {
|
Decision::Transition(new_state, attach) => {
|
||||||
self.state = new_state;
|
self.goto(ctx, new_state, attach);
|
||||||
self.goto(ctx, attach);
|
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
Decision::Return(msg) => {
|
Decision::Return(msg) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user