Navigator fixes (#343)

Former-commit-id: 96e8f32c37
This commit is contained in:
Alexander Pantyuhov 2016-10-17 14:51:33 +03:00
parent d40125cd79
commit e9777a6a0a
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,30 +78,30 @@
(dispatch [:set :keyboard-height 0])))) (dispatch [:set :keyboard-height 0]))))
:render :render
(fn [] (fn []
(let [current-view (validate-current-view @view-id @signed-up?)] (when @view-id
(log/debug current-view) (let [current-view (validate-current-view @view-id @signed-up?)]
(let [component (case current-view (let [component (case current-view
: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
:add-participants new-participants :add-participants new-participants
:remove-participants remove-participants :remove-participants remove-participants
:chat-list main-tabs :chat-list main-tabs
:new-group new-group :new-group new-group
:group-settings group-settings :group-settings group-settings
:contact-list main-tabs :contact-list main-tabs
:group-contacts contact-list :group-contacts contact-list
:new-contact new-contact :new-contact new-contact
:qr-scanner qr-scanner :qr-scanner qr-scanner
:chat chat :chat chat
:profile profile :profile profile
:profile-photo-capture profile-photo-capture :profile-photo-capture profile-photo-capture
:accounts accounts :accounts accounts
:login login :login login
: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?])
contact (subscribe [:get-in [:contacts @chat-id]]) accounts (subscribe [:get :accounts])
sync-state (subscribe [:get :sync-state])] contact (subscribe [:get-in [:contacts @chat-id]])
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,34 +63,28 @@
#(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) :discovery main-tabs
(if (contains? #{:login :chat} @view-id) :discovery-tag discovery-tag
@view-id :discovery-search-results discovery-search-results
:accounts))] :add-participants new-participants
(log/debug startup-view) :remove-participants remove-participants
(let [component (case (if true startup-view :chat) :chat-list main-tabs
:discovery main-tabs :new-group new-group
:discovery-tag discovery-tag :group-settings group-settings
:discovery-search-results discovery-search-results :contact-list main-tabs
:add-participants new-participants :group-contacts contact-list
:remove-participants remove-participants :new-contact new-contact
:chat-list main-tabs :qr-scanner qr-scanner
:new-group new-group :chat chat
:group-settings group-settings :profile profile
:contact-list main-tabs :profile-photo-capture profile-photo-capture
:group-contacts contact-list :accounts accounts
:new-contact new-contact :login login
:qr-scanner qr-scanner :my-profile my-profile)]
:chat chat [component]))))})))
:profile profile
:profile-photo-capture profile-photo-capture
:accounts accounts
:login login
:my-profile my-profile)]
[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