Fix for weird behaviour if back is pressed in 2nd onboarding (#775)

This commit is contained in:
alwx 2017-02-13 13:02:42 +03:00 committed by Roman Volosovskyi
parent 4bd800f5ca
commit c1abe16f89
10 changed files with 68 additions and 43 deletions

View File

@ -58,6 +58,7 @@
(register-handler :create-account (register-handler :create-account
(u/side-effect! (u/side-effect!
(fn [_ [_ password]] (fn [_ [_ password]]
(dispatch [:set :creating-account? true])
(s/execute-later #(dispatch [:account-generation-message]) 400) (s/execute-later #(dispatch [:account-generation-message]) 400)
(status/create-account (status/create-account
password password

View File

@ -41,10 +41,15 @@
;; todo: it might be better always return false from ;; todo: it might be better always return false from
;; this listener and handle application's closing ;; this listener and handle application's closing
;; in handlers ;; in handlers
(let [stack (subscribe [:get :navigation-stack])] (let [stack (subscribe [:get :navigation-stack])
(when (< 1 (count @stack)) creating? (subscribe [:get :creating-account?])]
(dispatch [:navigate-back]) (cond
true)))] @creating? true
(< 1 (count @stack))
(do (dispatch [:navigate-back]) true)
:else false)))]
(.addEventListener back-android "hardwareBackPress" new-listener))) (.addEventListener back-android "hardwareBackPress" new-listener)))
(defn orientation->keyword [o] (defn orientation->keyword [o]

View File

@ -16,3 +16,8 @@
(+ input-height suggestions-header-height)) (+ input-height suggestions-header-height))
(def emoji-container-height 250) (def emoji-container-height 250)
(def crazy-math-message-id "crazy-math-message")
(def passphrase-message-id "passphraze-message")
(def intro-status-message-id "intro-status")
(def intro-message1-id "intro-message1")

View File

@ -254,13 +254,13 @@
(register-handler :account-generation-message (register-handler :account-generation-message
(u/side-effect! (u/side-effect!
(fn [_] (fn [_]
(when-not (messages/get-by-id sign-up-service/passphraze-message-id) (when-not (messages/get-by-id chat-consts/passphrase-message-id)
(sign-up-service/account-generation-message))))) (sign-up-service/account-generation-message)))))
(register-handler :show-mnemonic (register-handler :show-mnemonic
(u/side-effect! (u/side-effect!
(fn [_ [_ mnemonic]] (fn [_ [_ mnemonic]]
(let [crazy-math-message? (messages/get-by-id sign-up-service/crazy-math-message)] (let [crazy-math-message? (messages/get-by-id chat-consts/crazy-math-message-id)]
(sign-up-service/passphrase-messages mnemonic crazy-math-message?))))) (sign-up-service/passphrase-messages mnemonic crazy-math-message?)))))
(register-handler :sign-up (register-handler :sign-up

View File

@ -28,10 +28,12 @@
[status-im.chat.views.bottom-info :refer [bottom-info-view]] [status-im.chat.views.bottom-info :refer [bottom-info-view]]
[status-im.chat.views.toolbar-content :refer [toolbar-content-view]] [status-im.chat.views.toolbar-content :refer [toolbar-content-view]]
[status-im.chat.views.suggestions :refer [suggestion-container]] [status-im.chat.views.suggestions :refer [suggestion-container]]
[status-im.chat.constants :as const]
[status-im.i18n :refer [label label-pluralize]] [status-im.i18n :refer [label label-pluralize]]
[status-im.components.animation :as anim] [status-im.components.animation :as anim]
[status-im.components.sync-state.offline :refer [offline-view]] [status-im.components.sync-state.offline :refer [offline-view]]
[status-im.constants :refer [content-type-status]])) [status-im.constants :refer [content-type-status]]
[taoensso.timbre :as log]))
(defn contacts-by-identity [contacts] (defn contacts-by-identity [contacts]
(->> contacts (->> contacts
@ -109,10 +111,11 @@
(defview chat-toolbar [] (defview chat-toolbar []
[show-actions? [:chat-ui-props :show-actions?] [show-actions? [:chat-ui-props :show-actions?]
accounts [:get :accounts]] accounts [:get :accounts]
creating? [:get :creating-account?]]
[view [view
[status-bar] [status-bar]
[toolbar {:hide-nav? (or (empty? accounts) show-actions?) [toolbar {:hide-nav? (or (empty? accounts) show-actions? creating?)
: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])}]
@ -121,7 +124,7 @@
(defn get-intro-status-message [all-messages] (defn get-intro-status-message [all-messages]
(let [{:keys [timestamp content-type]} (last all-messages)] (let [{:keys [timestamp content-type]} (last all-messages)]
(when (not= content-type content-type-status) (when (not= content-type content-type-status)
{:message-id "intro-status" {:message-id const/intro-status-message-id
:content-type content-type-status :content-type content-type-status
:timestamp (or timestamp (time/now-ms))}))) :timestamp (or timestamp (time/now-ms))})))
@ -170,11 +173,11 @@
(anim/start (anim/spring val {:toValue @offset})))) (anim/start (anim/spring val {:toValue @offset}))))
(defview messages-container [messages] (defview messages-container [messages]
[offset [:messages-offset] [offset [:messages-offset]
messages-offset (anim/create-value 0) messages-offset (anim/create-value 0)
context {:offset offset context {:offset offset
:val messages-offset} :val messages-offset}
on-update (messages-container-animation-logic context)] on-update (messages-container-animation-logic context)]
{:component-did-mount on-update {:component-did-mount on-update
:component-did-update on-update} :component-did-update on-update}
[animated-view [animated-view
@ -182,13 +185,13 @@
messages]) messages])
(defview chat [] (defview chat []
[group-chat [:chat :group-chat] [group-chat [:chat :group-chat]
show-actions? [:chat-ui-props :show-actions?] show-actions? [:chat-ui-props :show-actions?]
show-bottom-info? [:chat-ui-props :show-bottom-info?] show-bottom-info? [:chat-ui-props :show-bottom-info?]
show-emoji? [:chat-ui-props :show-emoji?] show-emoji? [:chat-ui-props :show-emoji?]
command? [:command?] command? [:command?]
layout-height [:get :layout-height]] layout-height [:get :layout-height]]
{:component-did-mount #(dispatch [:check-autorun]) {:component-did-mount #(dispatch [:check-autorun])
:component-will-unmount #(dispatch [:set-chat-ui-props :show-emoji? false])} :component-will-unmount #(dispatch [:set-chat-ui-props :show-emoji? false])}
[view {:style st/chat-view [view {:style st/chat-view
:onLayout (fn [event] :onLayout (fn [event]

View File

@ -10,6 +10,7 @@
content-type-command content-type-command
content-type-command-request content-type-command-request
content-type-status]] content-type-status]]
[status-im.chat.constants :as const]
[status-im.i18n :refer [label]] [status-im.i18n :refer [label]]
[clojure.string :as s])) [clojure.string :as s]))
@ -110,11 +111,10 @@
:from console-chat-id :from console-chat-id
:to "me"}])) :to "me"}]))
(def crazy-math-message "crazy-math-message")
;; -- Saving password ---------------------------------------- ;; -- Saving password ----------------------------------------
(defn account-generation-message [] (defn account-generation-message []
(dispatch [:received-message (dispatch [:received-message
{:message-id crazy-math-message {:message-id const/crazy-math-message-id
:content (label :t/account-generation-message) :content (label :t/account-generation-message)
:content-type text-content-type :content-type text-content-type
:outgoing false :outgoing false
@ -122,11 +122,9 @@
:from console-chat-id :from console-chat-id
:to "me"}])) :to "me"}]))
(def passphraze-message-id "passphraze-message")
(defn passphrase-messages [mnemonic crazy-math-message?] (defn passphrase-messages [mnemonic crazy-math-message?]
(dispatch [:received-message (dispatch [:received-message
{:message-id passphraze-message-id {:message-id const/passphrase-message-id
:content (if crazy-math-message? :content (if crazy-math-message?
(label :t/phew-here-is-your-passphrase) (label :t/phew-here-is-your-passphrase)
(label :t/here-is-your-passphrase)) (label :t/here-is-your-passphrase))
@ -146,7 +144,7 @@
(start-signup)) (start-signup))
(def intro-status (def intro-status
{:message-id "intro-status" {:message-id const/intro-status-message-id
:content (label :t/intro-status) :content (label :t/intro-status)
:from console-chat-id :from console-chat-id
:chat-id console-chat-id :chat-id console-chat-id
@ -159,7 +157,7 @@
(dispatch [:received-message-when-commands-loaded (dispatch [:received-message-when-commands-loaded
console-chat-id console-chat-id
{:chat-id console-chat-id {:chat-id console-chat-id
:message-id "intro-message1" :message-id const/intro-message1-id
:content (command-content :content (command-content
:password :password
(label :t/intro-message1)) (label :t/intro-message1))

View File

@ -7,8 +7,10 @@
[status-im.chat.constants :as c] [status-im.chat.constants :as c]
[status-im.chat.views.plain-message :as plain-message] [status-im.chat.views.plain-message :as plain-message]
[status-im.chat.views.command :as command] [status-im.chat.views.command :as command]
[status-im.constants :refer [content-type-status]] [status-im.constants :refer [content-type-status
[status-im.utils.platform :refer [platform-specific ios?]])) console-chat-id]]
[status-im.utils.platform :refer [platform-specific ios?]]
[taoensso.timbre :as log]))
(register-sub :chat-properties (register-sub :chat-properties
(fn [db [_ properties]] (fn [db [_ properties]]

View File

@ -55,7 +55,7 @@
[last-activity {:sync-state sync-state}] [last-activity {:sync-state sync-state}]
(if public? (if public?
[view {:flex-direction :row} [view {:flex-direction :row}
[text {:font :default [text {:font :default
:style (get-in platform-specific [:component-styles :toolbar-last-activity])} :style (get-in platform-specific [:component-styles :toolbar-last-activity])}
(label :t/public-group-status)]] (label :t/public-group-status)]]
[view {:flex-direction :row} [view {:flex-direction :row}
@ -77,10 +77,12 @@
show-actions? (subscribe [:chat-ui-props :show-actions?]) show-actions? (subscribe [:chat-ui-props :show-actions?])
accounts (subscribe [:get :accounts]) 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])
creating? (subscribe [:get :creating-account?])]
(fn [] (fn []
[view (st/chat-name-view (or (empty? @accounts) [view (st/chat-name-view (or (empty? @accounts)
@show-actions?)) @show-actions?
@creating?))
(let [chat-name (if (str/blank? @name) (let [chat-name (if (str/blank? @name)
(generate-gfy) (generate-gfy)
(or (get-contact-translated @chat-id :name @name) (or (get-contact-translated @chat-id :name @name)

View File

@ -80,7 +80,8 @@
(dispatch [:init-debug-mode address]) (dispatch [:init-debug-mode address])
(dispatch [:send-account-update-if-needed]) (dispatch [:send-account-update-if-needed])
(dispatch [:start-requesting-discoveries]) (dispatch [:start-requesting-discoveries])
(dispatch [:remove-old-discoveries!])))) (dispatch [:remove-old-discoveries!])
(dispatch [:set :creating-account? false]))))
(register-handler :reset-app (register-handler :reset-app
(u/side-effect! (u/side-effect!

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 subscribe debug enrich after]]
[status-im.utils.handlers :refer [register-handler]])) [status-im.utils.handlers :refer [register-handler]]
[status-im.constants :refer [console-chat-id]]))
(defn push-view [db view-id] (defn push-view [db view-id]
(-> db (-> db
@ -50,6 +51,11 @@
(fn [db [_ view-id]] (fn [db [_ view-id]]
(replace-view db view-id))) (replace-view db view-id)))
(defn- can-navigate-back? [db]
(and (not (db :creating-account?))
;; ...
))
(register-handler :navigate-back (register-handler :navigate-back
(enrich -preload-data!) (enrich -preload-data!)
(fn [{:keys [navigation-stack view-id modal] :as db} _] (fn [{:keys [navigation-stack view-id modal] :as db} _]
@ -59,13 +65,15 @@
(>= 1 (count navigation-stack)) db (>= 1 (count navigation-stack)) db
:else :else
(let [[previous-view-id :as navigation-stack'] (pop navigation-stack) (if (can-navigate-back? db)
first-in-stack (first navigation-stack)] (let [[previous-view-id :as navigation-stack'] (pop navigation-stack)
(if (= view-id first-in-stack) first-in-stack (first navigation-stack)]
(-> db (if (= view-id first-in-stack)
(assoc :view-id previous-view-id) (-> db
(assoc :navigation-stack navigation-stack')) (assoc :view-id previous-view-id)
(assoc db :view-id first-in-stack)))))) (assoc :navigation-stack navigation-stack'))
(assoc db :view-id first-in-stack)))
db))))
(register-handler :navigate-to-tab (register-handler :navigate-to-tab
(enrich preload-data!) (enrich preload-data!)