From 90863f16700d63215bedd5efcbdd6a4f3c387183 Mon Sep 17 00:00:00 2001 From: Foo Pang Date: Mon, 15 Jan 2018 12:39:54 +0800 Subject: [PATCH] [Fix #2987] Improve screen navigation Signed-off-by: Goran Jovic --- src/status_im/ui/screens/browser/events.cljs | 6 ++--- .../ui/screens/browser/navigation.cljs | 4 +-- src/status_im/ui/screens/contacts/views.cljs | 8 +++--- src/status_im/ui/screens/db.cljs | 27 ++++++++++++++++++- .../ui/screens/group/navigation.cljs | 13 ++------- src/status_im/ui/screens/group/views.cljs | 9 +++---- src/status_im/ui/screens/navigation.cljs | 17 +++++++----- .../ui/screens/network_settings/events.cljs | 1 - .../screens/network_settings/navigation.cljs | 6 ----- .../network_details/views.cljs | 5 ++-- .../ui/screens/network_settings/views.cljs | 2 +- .../ui/screens/qr_scanner/events.cljs | 7 +---- .../ui/screens/qr_scanner/views.cljs | 2 +- src/status_im/ui/screens/subs.cljs | 6 ++++- 14 files changed, 64 insertions(+), 49 deletions(-) delete mode 100644 src/status_im/ui/screens/network_settings/navigation.cljs diff --git a/src/status_im/ui/screens/browser/events.cljs b/src/status_im/ui/screens/browser/events.cljs index 1a9ea34bb8..9239870fd9 100644 --- a/src/status_im/ui/screens/browser/events.cljs +++ b/src/status_im/ui/screens/browser/events.cljs @@ -54,7 +54,7 @@ :url dapp-url :contact (:whisper-identity contact)}] (merge (add-browser-fx cofx browser) - {:dispatch [:navigate-to :browser (:browser-id browser)]})))) + {:dispatch [:navigate-to :browser {:browser/browser-id (:browser-id browser)}]})))) (handlers/register-handler-fx :open-browser @@ -62,7 +62,7 @@ (fn [{:keys [now] :as cofx} [browser]] (let [new-browser (get-new-browser browser now)] (merge (add-browser-fx cofx new-browser) - {:dispatch [:navigate-to :browser (:browser-id new-browser)]})))) + {:dispatch [:navigate-to :browser {:browser/browser-id (:browser-id new-browser)}]})))) (handlers/register-handler-fx :update-browser @@ -76,4 +76,4 @@ :update-browser-options [re-frame/trim-v] (fn [{:keys [db now] :as cofx} [options]] - {:db (update db :browser/options merge options)})) \ No newline at end of file + {:db (update db :browser/options merge options)})) diff --git a/src/status_im/ui/screens/browser/navigation.cljs b/src/status_im/ui/screens/browser/navigation.cljs index f84cc4a51a..79d4b8af8d 100644 --- a/src/status_im/ui/screens/browser/navigation.cljs +++ b/src/status_im/ui/screens/browser/navigation.cljs @@ -2,5 +2,5 @@ (:require [status-im.ui.screens.navigation :as navigation])) (defmethod navigation/preload-data! :browser - [db [_ _ browser-id]] - (assoc db :browser/options {:browser-id browser-id})) \ No newline at end of file + [db [_ _ {:keys [browser/browser-id]}]] + (assoc db :browser/options {:browser-id browser-id})) diff --git a/src/status_im/ui/screens/contacts/views.cljs b/src/status_im/ui/screens/contacts/views.cljs index 4f7626a37f..4f3d3561c8 100644 --- a/src/status_im/ui/screens/contacts/views.cljs +++ b/src/status_im/ui/screens/contacts/views.cljs @@ -26,7 +26,8 @@ {:text (label :t/reorder-groups) :value #(dispatch [:navigate-to :reorder-groups])}]) (defn toolbar-actions [] - [(act/search #(dispatch [:navigate-to :group-contacts nil :show-search])) + [(act/search #(dispatch [:navigate-to :group-contacts {:group/contact-group-id nil + :show-search? :show-search}])) (act/opts (if ios? toolbar-options (rest toolbar-options)))]) (defn toolbar-view [] @@ -63,7 +64,8 @@ [common/form-title subtitle {:count-value contacts-count :extended? edit? - :options [{:action #(dispatch [:navigate-to :edit-contact-group group :contact-group]) + :options [{:action #(dispatch [:navigate-to :edit-contact-group {:group group + :group-type :contact-group}]) :label (label :t/edit-group)}]}]) [view st/contacts-list [common/list-footer] @@ -86,7 +88,7 @@ [touchable-highlight {:on-press #(do (when edit? (dispatch [:set-in [:contacts/list-ui-props :edit?] true])) - (dispatch [:navigate-to :group-contacts (:group-id group)]))} + (dispatch [:navigate-to :group-contacts {:group/contact-group-id (:group-id group)}]))} [view [text {:style st/show-all-text :uppercase? (get-in platform-specific [:uppercase?]) diff --git a/src/status_im/ui/screens/db.cljs b/src/status_im/ui/screens/db.cljs index 1cfb8ad621..be71351715 100644 --- a/src/status_im/ui/screens/db.cljs +++ b/src/status_im/ui/screens/db.cljs @@ -92,6 +92,30 @@ (spec/def :navigation/navigation-stack (spec/nilable seq?)) (spec/def :navigation/prev-tab-view-id (spec/nilable keyword?)) (spec/def :navigation/prev-view-id (spec/nilable keyword?)) +;; navigation screen params +(spec/def :navigation.screen-params/network-details (allowed-keys :req [:networks/selected-network])) +(spec/def :navigation.screen-params/browser (allowed-keys :req [:browser/browser-id])) +(spec/def :navigation.screen-params/contact (spec/nilable map?)) +(spec/def :navigation.screen-params/qr-source (spec/nilable keyword?)) +(spec/def :navigation.screen-params/qr-value (spec/nilable string?)) +(spec/def :navigation.screen-params/qr-viewer (allowed-keys :opt-un [:navigation.screen-params/contact + :navigation.screen-params/qr-source + :navigation.screen-params/qr-value])) +(spec/def :navigation.screen-params/current-qr-context (spec/nilable any?)) +(spec/def :navigation.screen-params/qr-scanner (allowed-keys :opt-un [:navigation.screen-params/current-qr-context])) +(spec/def :navigation.screen-params/show-search? (spec/nilable any?)) +(spec/def :navigation.screen-params/group-contacts (allowed-keys :opt [:group/contact-group-id] + :opt-un [:navigation.screen-params/show-search?])) +(spec/def :navigation.screen-params/group (spec/nilable any?)) +(spec/def :navigation.screen-params/group-type (spec/nilable any?)) +(spec/def :navigation.screen-params/edit-contact-group (allowed-keys :opt-un [:navigation.screen-params/group + :navigation.screen-params/group-type])) +(spec/def :navigation/screen-params (spec/nilable (allowed-keys :opt-un [:navigation.screen-params/network-details + :navigation.screen-params/browser + :navigation.screen-params/qr-viewer + :navigation.screen-params/qr-scanner + :navigation.screen-params/group-contacts + :navigation.screen-params/edit-contact-group]))) ;;;;NETWORK @@ -138,7 +162,8 @@ :inbox/password :browser/browsers :browser/options - :new/open-dapp] + :new/open-dapp + :navigation/screen-params] :opt-un [::current-public-key ::modal diff --git a/src/status_im/ui/screens/group/navigation.cljs b/src/status_im/ui/screens/group/navigation.cljs index d75d5c3057..7d9e1e53fd 100644 --- a/src/status_im/ui/screens/group/navigation.cljs +++ b/src/status_im/ui/screens/group/navigation.cljs @@ -24,25 +24,16 @@ (dissoc db :public-group-topic)) (defmethod nav/preload-data! :group-contacts - [db [_ _ group-id show-search?]] + [db [_ _ {:keys [show-search?]}]] (-> db - (assoc :group/contact-group-id group-id) (update :toolbar-search assoc :show (when show-search? :contact-list) :text ""))) -(defmethod nav/preload-data! :edit-contact-group - [db [_ _ group group-type]] - (if group - (assoc db :group/contact-group-id (:group-id group) - :group/group-type group-type - :new-chat-name (:name group)) - db)) - (defmethod nav/preload-data! :reorder-groups [db [_ _]] (assoc db :group/groups-order (->> (vals (:group/contact-groups db)) (remove :pending?) (sort-by :order >) - (map :group-id)))) \ No newline at end of file + (map :group-id)))) diff --git a/src/status_im/ui/screens/group/views.cljs b/src/status_im/ui/screens/group/views.cljs index 30cb409764..f518c9c0ec 100644 --- a/src/status_im/ui/screens/group/views.cljs +++ b/src/status_im/ui/screens/group/views.cljs @@ -118,13 +118,12 @@ [more-btn contacts-limit contacts-count #(dispatch [:navigate-to :edit-group-contact-list])])])) (defview edit-contact-group [] - (letsubs [group-name [:get :new-chat-name] - group [:get-contact-group] - type [:get-group-type]] - (let [save-btn-enabled? (and (spec/valid? ::v/name group-name) + (letsubs [{:keys [group group-type]} [:get-screen-params]] + (let [group-name (:name group) + save-btn-enabled? (and (spec/valid? ::v/name group-name) (not= group-name (:name group)))] [keyboard-avoiding-view {:style styles/group-container} - [group-toolbar type true] + [group-toolbar group-type true] [group-name-view] [view styles/list-view-container [add-btn #(dispatch [:navigate-to :add-contacts-toggle-list])] diff --git a/src/status_im/ui/screens/navigation.cljs b/src/status_im/ui/screens/navigation.cljs index 84f0f413dd..36ad976ec8 100644 --- a/src/status_im/ui/screens/navigation.cljs +++ b/src/status_im/ui/screens/navigation.cljs @@ -43,10 +43,15 @@ (defn navigate-to "Navigates to particular view" - [{:keys [view-id] :as db} go-to-view-id] - (if (= view-id go-to-view-id) - db - (push-view db go-to-view-id))) + ([db go-to-view-id] + (navigate-to db go-to-view-id nil)) + ([{:keys [view-id] :as db} go-to-view-id screen-params] + (let [db (cond-> db + (seq screen-params) + (assoc-in [:navigation/screen-params go-to-view-id] screen-params))] + (if (= view-id go-to-view-id) + db + (push-view db go-to-view-id))))) ;; event handlers @@ -59,8 +64,8 @@ (register-handler-db :navigate-to (re-frame/enrich preload-data!) - (fn [db [_ new-view-id]] - (navigate-to db new-view-id))) + (fn [db [_ & params]] + (apply navigate-to db params))) (register-handler-db :navigate-to-modal diff --git a/src/status_im/ui/screens/network_settings/events.cljs b/src/status_im/ui/screens/network_settings/events.cljs index d8a69c456a..6c2ac4fd69 100644 --- a/src/status_im/ui/screens/network_settings/events.cljs +++ b/src/status_im/ui/screens/network_settings/events.cljs @@ -2,7 +2,6 @@ (:require [re-frame.core :refer [dispatch dispatch-sync after] :as re-frame] [status-im.utils.handlers :refer [register-handler] :as handlers] [status-im.data-store.networks :as networks] - [status-im.ui.screens.network-settings.navigation] [status-im.ui.screens.accounts.events :as accounts-events] [status-im.i18n :as i18n] [status-im.utils.ethereum.core :as utils])) diff --git a/src/status_im/ui/screens/network_settings/navigation.cljs b/src/status_im/ui/screens/network_settings/navigation.cljs deleted file mode 100644 index 9b21eb3882..0000000000 --- a/src/status_im/ui/screens/network_settings/navigation.cljs +++ /dev/null @@ -1,6 +0,0 @@ -(ns status-im.ui.screens.network-settings.navigation - (:require [status-im.ui.screens.navigation :as navigation])) - -(defmethod navigation/preload-data! :network-details - [db [_ _ network]] - (assoc db :networks/selected-network network)) \ No newline at end of file diff --git a/src/status_im/ui/screens/network_settings/network_details/views.cljs b/src/status_im/ui/screens/network_settings/network_details/views.cljs index 9cbdb946fd..da5711e54b 100644 --- a/src/status_im/ui/screens/network_settings/network_details/views.cljs +++ b/src/status_im/ui/screens/network_settings/network_details/views.cljs @@ -22,9 +22,10 @@ :value #(rf/dispatch [:network-remove])}]) (views/defview network-details [] - (views/letsubs [{:keys [id name config]} [:get :networks/selected-network] + (views/letsubs [{:keys [networks/selected-network]} [:get-screen-params] {:keys [network]} [:get-current-account]] - (let [connected? (= id network)] + (let [{:keys [id name config]} selected-network + connected? (= id network)] [react/view {:flex 1} [status-bar/status-bar] [toolbar/simple-toolbar] diff --git a/src/status_im/ui/screens/network_settings/views.cljs b/src/status_im/ui/screens/network_settings/views.cljs index fa2dcf8f53..e7fd488c36 100644 --- a/src/status_im/ui/screens/network_settings/views.cljs +++ b/src/status_im/ui/screens/network_settings/views.cljs @@ -45,7 +45,7 @@ (fn [{:keys [id name config] :as network}] (let [connected? (= id current-network)] [react/touchable-highlight - {:on-press #(re-frame/dispatch [:navigate-to :network-details network])} + {:on-press #(re-frame/dispatch [:navigate-to :network-details {:networks/selected-network network}])} [react/view styles/network-item [network-icon connected? 40] [react/view {:padding-horizontal 16} diff --git a/src/status_im/ui/screens/qr_scanner/events.cljs b/src/status_im/ui/screens/qr_scanner/events.cljs index f66f916e97..95e29a357e 100644 --- a/src/status_im/ui/screens/qr_scanner/events.cljs +++ b/src/status_im/ui/screens/qr_scanner/events.cljs @@ -1,15 +1,10 @@ (ns status-im.ui.screens.qr-scanner.events (:require [re-frame.core :as re-frame] [status-im.ui.components.camera :as camera] - [status-im.ui.screens.navigation :as nav] [status-im.utils.handlers :as u :refer [register-handler]] [status-im.utils.utils :as utils] [status-im.i18n :as i18n])) -(defmethod nav/preload-data! :qr-scanner - [db [_ _ identifier]] - (assoc db :current-qr-context identifier)) - (defn set-current-identifier [db [_ identifier handler]] (assoc-in db [:qr-codes identifier] handler)) @@ -17,7 +12,7 @@ [_ [_ identifier]] (re-frame/dispatch [:request-permissions [:camera] - #(re-frame/dispatch [:navigate-to :qr-scanner identifier]) + #(re-frame/dispatch [:navigate-to :qr-scanner {:current-qr-context identifier}]) #(utils/show-popup (i18n/label :t/error) (i18n/label :t/camera-access-error))])) diff --git a/src/status_im/ui/screens/qr_scanner/views.cljs b/src/status_im/ui/screens/qr_scanner/views.cljs index c0affb8d96..b714379c56 100644 --- a/src/status_im/ui/screens/qr_scanner/views.cljs +++ b/src/status_im/ui/screens/qr_scanner/views.cljs @@ -15,7 +15,7 @@ [toolbar/simple-toolbar title]])) (defview qr-scanner [] - (letsubs [identifier [:get :current-qr-context] + (letsubs [{identifier :current-qr-context} [:get-screen-params] camera-initialized? (reagent/atom false)] [react/view styles/barcode-scanner-container diff --git a/src/status_im/ui/screens/subs.cljs b/src/status_im/ui/screens/subs.cljs index 6becc8d32f..0953de4222 100644 --- a/src/status_im/ui/screens/subs.cljs +++ b/src/status_im/ui/screens/subs.cljs @@ -27,7 +27,7 @@ (fn [db [_ path]] (get-in db path))) -(reg-sub :signed-up? +(reg-sub :signed-up? :<- [:get-current-account] (fn [current-account] (:signed-up? current-account))) @@ -54,3 +54,7 @@ :<- [:sync-state] (fn [sync-state] (#{:pending :in-progress} sync-state))) + +(reg-sub :get-screen-params + (fn [db [_ view-id]] + (get-in db [:navigation/screen-params (or view-id (:view-id db))])))