Merge pull request #360 from status-im/bug/#343

Navigator fixes (#343)

Former-commit-id: 8b0058aa94
This commit is contained in:
Roman Volosovskyi 2016-10-18 14:17:55 +03:00 committed by GitHub
commit d5e044baa6
11 changed files with 74 additions and 70 deletions

View File

@ -6,7 +6,6 @@
[status-im.components.status :as status] [status-im.components.status :as status]
[status-im.utils.types :refer [json->clj]] [status-im.utils.types :refer [json->clj]]
[status-im.utils.identicon :refer [identicon]] [status-im.utils.identicon :refer [identicon]]
[status-im.db :refer [default-view]]
[status-im.utils.random :as random] [status-im.utils.random :as random]
[status-im.i18n :refer [label]] [status-im.i18n :refer [label]]
[status-im.constants :refer [content-type-command-request]] [status-im.constants :refer [content-type-command-request]]

View File

@ -3,7 +3,6 @@
[status-im.utils.handlers :refer [register-handler] :as u] [status-im.utils.handlers :refer [register-handler] :as u]
[taoensso.timbre :as log] [taoensso.timbre :as log]
[status-im.utils.types :refer [json->clj]] [status-im.utils.types :refer [json->clj]]
[status-im.db :refer [default-view]]
[status-im.data-store.core :as data-store] [status-im.data-store.core :as data-store]
[status-im.components.status :as status] [status-im.components.status :as status]
[status-im.constants :refer [console-chat-id]])) [status-im.constants :refer [console-chat-id]]))

View File

@ -12,6 +12,7 @@
[status-im.accounts.styles :as st])) [status-im.accounts.styles :as st]))
(defn on-press [address] (defn on-press [address]
(dispatch [:navigate-to-clean :accounts])
(dispatch [:navigate-to :login address]) (dispatch [:navigate-to :login address])
(dispatch [:set-in [:login :address] address])) (dispatch [:set-in [:login :address] address]))

View File

@ -78,8 +78,8 @@
(dispatch [:set :keyboard-height 0])))) (dispatch [:set :keyboard-height 0]))))
:render :render
(fn [] (fn []
(when @view-id
(let [current-view (validate-current-view @view-id @signed-up?)] (let [current-view (validate-current-view @view-id @signed-up?)]
(log/debug current-view)
(let [component (case current-view (let [component (case current-view
:discovery main-tabs :discovery main-tabs
:discovery-tag discovery-tag :discovery-tag discovery-tag
@ -101,7 +101,7 @@
:recover recover :recover recover
:confirm confirm :confirm confirm
:my-profile my-profile)] :my-profile my-profile)]
[component])))}))) [component]))))})))
(defn init [& [env]] (defn init [& [env]]
(dispatch-sync [:reset-app]) (dispatch-sync [:reset-app])

View File

@ -97,10 +97,11 @@
[chat-icon]]])))) [chat-icon]]]))))
(defview chat-toolbar [] (defview chat-toolbar []
[show-actions [:chat-ui-props :show-actions?]] [show-actions? [:chat-ui-props :show-actions?]
accounts [:get :accounts]]
[view [view
[status-bar] [status-bar]
[toolbar {:hide-nav? show-actions [toolbar {:hide-nav? (or (empty? accounts) show-actions?)
:custom-content [toolbar-content-view] :custom-content [toolbar-content-view]
:custom-action [toolbar-action] :custom-action [toolbar-action]
:style (get-in platform-specific [:component-styles :toolbar])}]]) :style (get-in platform-specific [:component-styles :toolbar])}]])

View File

@ -50,11 +50,13 @@
name name
contacts contacts
chat-id]} (subscribe [:chat-properties [:group-chat :name :contacts :chat-id]]) chat-id]} (subscribe [:chat-properties [:group-chat :name :contacts :chat-id]])
show-actions (subscribe [:chat-ui-props :show-actions?]) show-actions? (subscribe [:chat-ui-props :show-actions?])
accounts (subscribe [:get :accounts])
contact (subscribe [:get-in [:contacts @chat-id]]) contact (subscribe [:get-in [:contacts @chat-id]])
sync-state (subscribe [:get :sync-state])] sync-state (subscribe [:get :sync-state])]
(fn [] (fn []
[view (st/chat-name-view @show-actions) [view (st/chat-name-view (or (empty? @accounts)
@show-actions?))
[text {:style st/chat-name-text [text {:style st/chat-name-text
:number-of-lines 1 :number-of-lines 1
:font :toolbar-title} :font :toolbar-title}

View File

@ -36,7 +36,7 @@
new-chat? new-chat?
(into [{:image {:source {:uri :icon_add} (into [{:image {:source {:uri :icon_add}
:style st/toolbar-icon} :style st/toolbar-icon}
:handler #(dispatch [:navigate-forget :group-contacts :people])}]))] :handler #(dispatch [:navigate-to :group-contacts :people])}]))]
[toolbar {:nav-action {:image {:source {:uri :icon_hamburger} [toolbar {:nav-action {:image {:source {:uri :icon_hamburger}
:style st/hamburger-icon} :style st/hamburger-icon}
:handler open-drawer} :handler open-drawer}
@ -56,7 +56,7 @@
[action-button-item [action-button-item
{:title (label :t/new-chat) {:title (label :t/new-chat)
:buttonColor :#9b59b6 :buttonColor :#9b59b6
:onPress #(dispatch [:navigate-forget :group-contacts :people])} :onPress #(dispatch [:navigate-to :group-contacts :people])}
[ion-icon {:name :md-create [ion-icon {:name :md-create
:style st/create-icon}]] :style st/create-icon}]]
[action-button-item [action-button-item

View File

@ -16,7 +16,9 @@
(defmethod nav/preload-data! :group-contacts (defmethod nav/preload-data! :group-contacts
[db [_ _ group]] [db [_ _ group]]
(assoc db :contacts-group group)) (if group
(assoc db :contacts-group group)
db))
(defmethod nav/preload-data! :new-group (defmethod nav/preload-data! :new-group
[db _] [db _]

View File

@ -7,8 +7,6 @@
;; schema of app-db ;; schema of app-db
(def schema {:greeting s/Str}) (def schema {:greeting s/Str})
(def default-view :chat)
;; initial state of app-db ;; initial state of app-db
(def app-db {:identity-password "replace-me-with-user-entered-password" (def app-db {:identity-password "replace-me-with-user-entered-password"
:identity "me" :identity "me"
@ -40,8 +38,8 @@
:chat-ui-props {:show-actions? false :chat-ui-props {:show-actions? false
:show-bottom-info? false} :show-bottom-info? false}
:selected-participants #{} :selected-participants #{}
:view-id default-view :view-id nil
:navigation-stack (list default-view) :navigation-stack '()
:current-tag nil :current-tag nil
:qr-codes {} :qr-codes {}
:keyboard-height 0 :keyboard-height 0

View File

@ -28,9 +28,16 @@
(defn orientation->keyword [o] (defn orientation->keyword [o]
(keyword (.toLowerCase o))) (keyword (.toLowerCase o)))
(defn validate-current-view
[current-view signed-up?]
(if (or (contains? #{:login :chat :recover :accounts} current-view)
signed-up?)
current-view
:chat))
(defn app-root [] (defn app-root []
(let [signed-up (subscribe [:signed-up?]) (let [signed-up? (subscribe [:signed-up?])
_ (log/debug "signed up: " @signed-up) _ (log/debug "signed up: " @signed-up?)
view-id (subscribe [:get :view-id]) view-id (subscribe [:get :view-id])
account-id (subscribe [:get :current-account-id]) account-id (subscribe [:get :current-account-id])
keyboard-height (subscribe [:get :keyboard-height])] keyboard-height (subscribe [:get :keyboard-height])]
@ -56,15 +63,9 @@
#(dispatch [:set :keyboard-height 0])))) #(dispatch [:set :keyboard-height 0]))))
:render :render
(fn [] (fn []
(let [startup-view (if @account-id (when @view-id
(if @signed-up (let [current-view (validate-current-view @view-id @signed-up?)]
@view-id (let [component (case current-view
:chat)
(if (contains? #{:login :chat} @view-id)
@view-id
:accounts))]
(log/debug startup-view)
(let [component (case (if true startup-view :chat)
:discovery main-tabs :discovery main-tabs
:discovery-tag discovery-tag :discovery-tag discovery-tag
:discovery-search-results discovery-search-results :discovery-search-results discovery-search-results
@ -83,7 +84,7 @@
:accounts accounts :accounts accounts
:login login :login login
:my-profile my-profile)] :my-profile my-profile)]
[component])))}))) [component]))))})))
(defn init [] (defn init []
(dispatch-sync [:reset-app]) (dispatch-sync [:reset-app])

View File

@ -1,6 +1,7 @@
(ns status-im.navigation.handlers (ns status-im.navigation.handlers
(:require [re-frame.core :refer [dispatch debug enrich after]] (:require [re-frame.core :refer [dispatch debug enrich after]]
[status-im.utils.handlers :refer [register-handler]])) [status-im.utils.handlers :refer [register-handler]]
[taoensso.timbre :as log]))
(defn push-view [db view-id] (defn push-view [db view-id]
(-> db (-> db