[Fix #2987] Improve screen navigation

Signed-off-by: Goran Jovic <goranjovic@gmail.com>
This commit is contained in:
Foo Pang 2018-01-15 12:39:54 +08:00 committed by Goran Jovic
parent cbc61500f7
commit 90863f1670
No known key found for this signature in database
GPG Key ID: A778DE3CD7D2D10D
14 changed files with 64 additions and 49 deletions

View File

@ -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)}))
{:db (update db :browser/options merge options)}))

View File

@ -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}))
[db [_ _ {:keys [browser/browser-id]}]]
(assoc db :browser/options {:browser-id browser-id}))

View File

@ -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?])

View File

@ -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

View File

@ -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))))
(map :group-id))))

View File

@ -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])]

View File

@ -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

View File

@ -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]))

View File

@ -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))

View File

@ -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]

View File

@ -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}

View File

@ -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))]))

View File

@ -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

View File

@ -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))])))