From 8c9af1ab511da359c5959f0cd7d4ed0ae51da73f Mon Sep 17 00:00:00 2001 From: Vitaliy Vlasov Date: Wed, 14 Aug 2019 21:30:46 +0300 Subject: [PATCH] Fix Android back button issues on intro screens Signed-off-by: Vitaliy Vlasov --- src/status_im/multiaccounts/create/core.cljs | 2 +- src/status_im/multiaccounts/recover/core.cljs | 7 +++-- .../ui/screens/keycard/recovery/views.cljs | 5 ++- .../ui/screens/multiaccounts/login/views.cljs | 2 +- .../ui/screens/multiaccounts/views.cljs | 2 +- src/status_im/ui/screens/navigation.cljs | 31 ++++++------------- .../ui/screens/routing/intro_login_stack.cljs | 10 +++--- 7 files changed, 28 insertions(+), 31 deletions(-) diff --git a/src/status_im/multiaccounts/create/core.cljs b/src/status_im/multiaccounts/create/core.cljs index 856f12f683..e2bde93beb 100644 --- a/src/status_im/multiaccounts/create/core.cljs +++ b/src/status_im/multiaccounts/create/core.cljs @@ -75,7 +75,7 @@ (navigation/navigate-to-cofx :intro-wizard nil)) (fx/merge {:db (dissoc db :intro-wizard)} - (navigation/navigate-to-clean (if first-time-setup? :intro :multiaccounts) nil))))) + (navigation/navigate-back))))) (fx/defn exit-wizard [{:keys [db] :as cofx}] (fx/merge {:db (dissoc db :intro-wizard)} diff --git a/src/status_im/multiaccounts/recover/core.cljs b/src/status_im/multiaccounts/recover/core.cljs index 47eae36657..a45a6e68d4 100644 --- a/src/status_im/multiaccounts/recover/core.cljs +++ b/src/status_im/multiaccounts/recover/core.cljs @@ -210,8 +210,11 @@ (fx/defn cancel-pressed {:events [:recover.ui/cancel-pressed]} - [cofx] - (navigation/navigate-back cofx)) + [{:keys [db] :as cofx}] + ;; Workaround for multiple Cancel button clicks + ;; that can break navigation tree + (when-not (#{:multiaccounts :login} (:view-id db)) + (navigation/navigate-back cofx))) (fx/defn select-storage-next-pressed {:events [:recover.select-storage.ui/next-pressed] diff --git a/src/status_im/ui/screens/keycard/recovery/views.cljs b/src/status_im/ui/screens/keycard/recovery/views.cljs index 645a1b2411..f43032b325 100644 --- a/src/status_im/ui/screens/keycard/recovery/views.cljs +++ b/src/status_im/ui/screens/keycard/recovery/views.cljs @@ -3,6 +3,7 @@ (:require [status-im.ui.components.react :as react] [status-im.ui.screens.keycard.styles :as styles] [status-im.ui.screens.keycard.views :as views] + [status-im.ui.components.toolbar.actions :as actions] [status-im.ui.components.toolbar.view :as toolbar] [status-im.ui.components.colors :as colors] [status-im.ui.components.icons.vector-icons :as vector-icons] @@ -22,7 +23,9 @@ [toolbar/toolbar {:transparent? true :style {:margin-top 32}} - toolbar/default-nav-back + (toolbar/nav-button + (actions/back #(re-frame/dispatch + [:recover.ui/cancel-pressed]))) nil] [react/view {:flex 1 :flex-direction :column diff --git a/src/status_im/ui/screens/multiaccounts/login/views.cljs b/src/status_im/ui/screens/multiaccounts/login/views.cljs index 094f21bc51..e43ce30385 100644 --- a/src/status_im/ui/screens/multiaccounts/login/views.cljs +++ b/src/status_im/ui/screens/multiaccounts/login/views.cljs @@ -24,7 +24,7 @@ {:style {:border-bottom-width 0 :margin-top 0}} (when can-navigate-back? - [toolbar/nav-button (act/back #(re-frame/dispatch [:navigate-to-clean :multiaccounts]))]) + [toolbar/nav-button (act/back #(re-frame/dispatch [:navigate-reset :multiaccounts]))]) nil]) (defn login-multiaccount [password-text-input] diff --git a/src/status_im/ui/screens/multiaccounts/views.cljs b/src/status_im/ui/screens/multiaccounts/views.cljs index 7d6c370ad6..746e3f13da 100644 --- a/src/status_im/ui/screens/multiaccounts/views.cljs +++ b/src/status_im/ui/screens/multiaccounts/views.cljs @@ -56,7 +56,7 @@ :key-fn :address :render-fn (fn [multiaccount] [multiaccount-view multiaccount])}]] [react/view - [components.common/button {:on-press #(re-frame/dispatch [:multiaccounts.create.ui/intro-wizard true]) + [components.common/button {:on-press #(re-frame/dispatch [:multiaccounts.create.ui/intro-wizard false]) :button-style styles/bottom-button :label (i18n/label :t/generate-a-new-key)}] [react/view styles/bottom-button-container diff --git a/src/status_im/ui/screens/navigation.cljs b/src/status_im/ui/screens/navigation.cljs index 4707ed7e0c..12600001f9 100644 --- a/src/status_im/ui/screens/navigation.cljs +++ b/src/status_im/ui/screens/navigation.cljs @@ -14,16 +14,6 @@ ;; public fns -(fx/defn navigate-to-clean - [{:keys [db]} view-id screen-params] - (log/debug "current view-id " (:view-id db) - "changing to " view-id) - (let [db (cond-> db - (seq screen-params) - (assoc-in [:navigation/screen-params view-id] screen-params))] - {:db (push-view db view-id) - ::navigate-to-clean view-id})) - (fx/defn navigate-forget [{:keys [db]} view-id] {:db (assoc db :view-id view-id)}) @@ -57,9 +47,10 @@ (fx/defn navigate-reset [{:keys [db]} {:keys [index actions] :as config}] - {:db (assoc db :view-id - (:routeName (get actions index))) - ::navigate-reset config}) + (let [view-id (:routeName (get actions index))] + {:db (assoc db :view-id view-id + :navigation-stack (list view-id)) + ::navigate-reset config})) (def unload-data-interceptor (re-frame/->interceptor @@ -92,14 +83,6 @@ (log/debug :navigate-reset config) (navigation/navigate-reset config))) -(re-frame/reg-fx - ::navigate-to-clean - (fn [view-id] - (log/debug :navigate-to-clean view-id) - (navigation/navigate-reset - {:index 0 - :actions [{:routeName view-id}]}))) - ;; event handlers (handlers/register-handler-fx @@ -132,6 +115,12 @@ (fn [cofx _] (navigate-back cofx))) +(handlers/register-handler-fx + :navigate-reset + (fn [cofx [_ view-id]] + (navigate-reset cofx {:index 0 + :actions [{:routeName view-id}]}))) + (handlers/register-handler-fx :navigate-to-clean (fn [cofx [_ view-id params]] diff --git a/src/status_im/ui/screens/routing/intro_login_stack.cljs b/src/status_im/ui/screens/routing/intro_login_stack.cljs index 76dd94ed1b..39357b07ac 100644 --- a/src/status_im/ui/screens/routing/intro_login_stack.cljs +++ b/src/status_im/ui/screens/routing/intro_login_stack.cljs @@ -48,15 +48,17 @@ (defn login-stack [view-id] {:name :login-stack :screens (cond-> [:login + :multiaccounts + :intro-wizard :progress + :keycard-recovery-intro :create-multiaccount :recover-multiaccount :recover-multiaccount-enter-phrase :recover-multiaccount-select-storage :recover-multiaccount-enter-password :recover-multiaccount-confirm-password - :recover-multiaccount-success - :multiaccounts] + :recover-multiaccount-success] config/hardwallet-enabled? (concat [:hardwallet-authentication-method @@ -71,8 +73,8 @@ :hardwallet-setup :hardwallet-success])) :config (if - ;; add view-id here if you'd like that view to be - ;; first view when app is started + ;; add view-id here if you'd like that view to be + ;; first view when app is started (#{:login :progress :multiaccounts :enter-pin-login :keycard-login-pin} view-id) {:initialRouteName view-id} {:initialRouteName :login})})