From 080b13c30488092c9930da3734180d5958a74d71 Mon Sep 17 00:00:00 2001 From: Parvesh Monu Date: Tue, 24 Jan 2023 20:28:41 +0530 Subject: [PATCH] fix some buttons are not responding after theme change (#14811) --- src/react_native/status.cljs | 0 src/status_im/add_new/core.cljs | 2 +- src/status_im/contact/block.cljs | 2 +- src/status_im/events.cljs | 11 +++++--- src/status_im/group_chats/core.cljs | 4 +-- src/status_im/multiaccounts/core.cljs | 28 ++++++++++++++----- src/status_im/multiaccounts/login/core.cljs | 17 ++++------- src/status_im/qr_scanner/core.cljs | 4 +-- .../ui/screens/appearance/views.cljs | 9 ++---- src/status_im2/config.cljs | 3 -- src/status_im2/constants.cljs | 4 +++ src/status_im2/contexts/chat/events.cljs | 7 +++-- src/status_im2/contexts/shell/animation.cljs | 20 ++++++++----- src/status_im2/contexts/shell/events.cljs | 2 ++ src/status_im2/contexts/shell/view.cljs | 1 + src/status_im2/navigation/core.cljs | 5 ++++ src/status_im2/navigation/events.cljs | 5 ++++ src/status_im2/navigation/roots.cljs | 17 ++++++----- src/status_im2/subs/home.cljs | 6 ++-- 19 files changed, 88 insertions(+), 59 deletions(-) delete mode 100644 src/react_native/status.cljs diff --git a/src/react_native/status.cljs b/src/react_native/status.cljs deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/src/status_im/add_new/core.cljs b/src/status_im/add_new/core.cljs index 983214838c..f8e8547068 100644 --- a/src/status_im/add_new/core.cljs +++ b/src/status_im/add_new/core.cljs @@ -91,7 +91,7 @@ (i18n/label :t/use-valid-contact-code) :yourself (i18n/label :t/can-not-add-yourself)) - :on-dismiss #(re-frame/dispatch [:pop-to-root-tab :chat-stack])}}))) + :on-dismiss #(re-frame/dispatch [:pop-to-root-tab :shell-stack])}}))) (rf/defn qr-code-scanned {:events [:contact/qr-code-scanned]} diff --git a/src/status_im/contact/block.cljs b/src/status_im/contact/block.cljs index 4a5bf82684..92b565998d 100644 --- a/src/status_im/contact/block.cljs +++ b/src/status_im/contact/block.cljs @@ -76,7 +76,7 @@ (re-frame/dispatch [:hide-popover]))) ;; reset navigation to avoid going back to non existing one to one chat (if from-one-to-one-chat? - (navigation/pop-to-root-tab :chat-stack) + (navigation/pop-to-root-tab :shell-stack) (navigation/navigate-back))))) (rf/defn contact-unblocked diff --git a/src/status_im/events.cljs b/src/status_im/events.cljs index 8576152780..d4460fce1f 100644 --- a/src/status_im/events.cljs +++ b/src/status_im/events.cljs @@ -112,10 +112,13 @@ (rf/defn system-theme-mode-changed {:events [:system-theme-mode-changed]} - [cofx _] - (when (multiaccounts.model/logged-in? cofx) - {:multiaccounts.ui/switch-theme (get-in cofx [:db :multiaccount :appearance]) - :dispatch [:reload-new-ui]})) + [{:keys [db] :as cofx} _] + (let [current-theme-type (get-in cofx [:db :multiaccount :appearance])] + (when (and (multiaccounts.model/logged-in? cofx) + (= current-theme-type status-im2.constants/theme-type-system)) + {:multiaccounts.ui/switch-theme + [(get-in db [:multiaccount :appearance]) + (:view-id db) true]}))) (def authentication-options {:reason (i18n/label :t/biometric-auth-reason-login)}) diff --git a/src/status_im/group_chats/core.cljs b/src/status_im/group_chats/core.cljs index f50c56fcc5..cc0e943536 100644 --- a/src/status_im/group_chats/core.cljs +++ b/src/status_im/group_chats/core.cljs @@ -23,7 +23,7 @@ (rf/merge cofx {:db (dissoc (:db cofx) :current-chat-id) :dispatch-n [[:sanitize-messages-and-process-response response] - [:pop-to-root-tab :chat-stack]]} + [:pop-to-root-tab :shell-stack]]} (activity-center/notifications-fetch-unread-count))) (rf/defn handle-chat-update @@ -124,7 +124,7 @@ [cofx chat-id] (rf/merge cofx (chat.events/deactivate-chat chat-id) - (navigation/pop-to-root-tab :chat-stack))) + (navigation/pop-to-root-tab :shell-stack))) (def not-blank? (complement string/blank?)) diff --git a/src/status_im/multiaccounts/core.cljs b/src/status_im/multiaccounts/core.cljs index d40bbde1a2..6c3327112d 100644 --- a/src/status_im/multiaccounts/core.cljs +++ b/src/status_im/multiaccounts/core.cljs @@ -8,11 +8,15 @@ [status-im.native-module.core :as native-module] [status-im.theme.core :as theme] [utils.re-frame :as rf] + [quo2.foundations.colors :as colors] + [status-im2.constants :as constants] [status-im.utils.gfycat.core :as gfycat] [status-im.utils.identicon :as identicon] [status-im.utils.utils :as utils] + [status-im2.setup.hot-reload :as hot-reload] [status-im2.common.theme.core :as utils.theme] - [taoensso.timbre :as log])) + [taoensso.timbre :as log] + [status-im2.contexts.shell.animation :as shell.animation])) ;; validate that the given mnemonic was generated from Status Dictionary (re-frame/reg-fx @@ -173,17 +177,27 @@ (re-frame/reg-fx :multiaccounts.ui/switch-theme - (fn [theme-id] - (let [theme (if (or (= 2 theme-id) (and (= 0 theme-id) (utils.theme/dark-mode?))) - :dark - :light)] - (theme/change-theme theme)))) + (fn [[theme-type view-id reload-ui?]] + (let [[theme status-bar-theme nav-bar-color] + ;; Status bar theme represents status bar icons colors, so opposite to app theme + (if (or (= theme-type constants/theme-type-dark) + (and (= theme-type constants/theme-type-system) + (utils.theme/dark-mode?))) + [:dark :light colors/neutral-100] + [:light :dark colors/white])] + (theme/change-theme theme) + (re-frame/dispatch [:change-root-status-bar-style + (if (shell.animation/home-stack-open?) status-bar-theme :light)]) + (when reload-ui? + (hot-reload/reload) + (when-not (= view-id :shell-stack) + (re-frame/dispatch [:change-root-nav-bar-color nav-bar-color])))))) (rf/defn switch-appearance {:events [:multiaccounts.ui/appearance-switched]} [cofx theme] (rf/merge cofx - {:multiaccounts.ui/switch-theme theme} + {:multiaccounts.ui/switch-theme [theme :appearance true]} (multiaccounts.update/multiaccount-update :appearance theme {}))) (rf/defn switch-profile-picture-show-to diff --git a/src/status_im/multiaccounts/login/core.cljs b/src/status_im/multiaccounts/login/core.cljs index 2464dae28c..ff36279b2e 100644 --- a/src/status_im/multiaccounts/login/core.cljs +++ b/src/status_im/multiaccounts/login/core.cljs @@ -351,7 +351,7 @@ (rf/defn initialize-appearance [cofx] - {:multiaccounts.ui/switch-theme (get-in cofx [:db :multiaccount :appearance])}) + {:multiaccounts.ui/switch-theme [(get-in cofx [:db :multiaccount :appearance]) nil false]}) (rf/defn get-group-chat-invitations [_] @@ -490,7 +490,7 @@ "Decides which root should be initialised depending on user and app state" [db] (if (get db :tos/accepted?) - (re-frame/dispatch [:init-root (if config/new-ui-enabled? :shell-stack :chat-stack)]) + (re-frame/dispatch [:init-root :shell-stack]) (re-frame/dispatch [:init-root :tos]))) (rf/defn login-only-events @@ -539,14 +539,7 @@ (multiaccounts/switch-preview-privacy-mode-flag) (link-preview/request-link-preview-whitelist) (logging/set-log-level (:log-level multiaccount)) - - (if config/new-ui-enabled? - (navigation/init-root :shell-stack) - ;; if it's a first account, the ToS will be accepted at welcome carousel - ;; if not a first account, the ToS might have been accepted by other account logins - (if (or first-account? tos-accepted?) - (navigation/init-root :onboarding-notification) - (navigation/init-root :tos)))))) + (navigation/init-root :shell-stack)))) (defn- keycard-setup? [cofx] @@ -564,7 +557,7 @@ :multiaccount) (assoc :tos-accept-next-root (if login-only? - :chat-stack + :shell-stack :onboarding-notification)) (assoc :logged-in-since now) (assoc :view-id :home))) @@ -737,7 +730,7 @@ (rf/defn welcome-lets-go {:events [:welcome-lets-go]} [_] - {:init-root-fx :chat-stack}) + {:init-root-fx :shell-stack}) (rf/defn multiaccount-selected {:events [:multiaccounts.login.ui/multiaccount-selected]} diff --git a/src/status_im/qr_scanner/core.cljs b/src/status_im/qr_scanner/core.cljs index 9ce28137b3..c6b8486f9e 100644 --- a/src/status_im/qr_scanner/core.cljs +++ b/src/status_im/qr_scanner/core.cljs @@ -76,7 +76,7 @@ :else {:utils/show-popup {:title (i18n/label :t/unable-to-read-this-code) :content (i18n/label :t/ens-name-not-found) - :on-dismiss #(re-frame/dispatch [:pop-to-root-tab :chat-stack])}}))) + :on-dismiss #(re-frame/dispatch [:pop-to-root-tab :shell-stack])}}))) (rf/defn handle-eip681 [cofx data] @@ -116,7 +116,7 @@ :event ::match-scanned-value}) {:dispatch [:navigate-back] :utils/show-popup {:title (i18n/label :t/unable-to-read-this-code) - :on-dismiss #(re-frame/dispatch [:pop-to-root-tab :chat-stack])}}))) + :on-dismiss #(re-frame/dispatch [:pop-to-root-tab :shell-stack])}}))) (rf/defn on-scan {:events [::on-scan-success]} diff --git a/src/status_im/ui/screens/appearance/views.cljs b/src/status_im/ui/screens/appearance/views.cljs index 3e696d6c5a..eac35437c5 100644 --- a/src/status_im/ui/screens/appearance/views.cljs +++ b/src/status_im/ui/screens/appearance/views.cljs @@ -5,17 +5,12 @@ [re-frame.core :as re-frame] [utils.i18n :as i18n] [status-im.react-native.resources :as resources] - [status-im.ui.components.react :as react] - [status-im2.config :as config])) + [status-im.ui.components.react :as react])) (defn button [label icon theme selected?] [react/touchable-highlight - {:on-press (fn [] - (re-frame/dispatch [:multiaccounts.ui/appearance-switched theme]) - (re-frame/dispatch (if config/new-ui-enabled? [:reload-new-ui] [:init-root :chat-stack])) - (re-frame/dispatch [:navigate-change-tab :profile]) - (js/setTimeout #(re-frame/dispatch [:navigate-to :appearance]) 1000))} + {:on-press #(re-frame/dispatch [:multiaccounts.ui/appearance-switched theme])} [react/view (merge {:align-items :center :padding 8 :border-radius 20} (when selected? diff --git a/src/status_im2/config.cljs b/src/status_im2/config.cljs index b02538417c..9b88d5b305 100644 --- a/src/status_im2/config.cljs +++ b/src/status_im2/config.cljs @@ -142,9 +142,6 @@ (def wallet-connect-project-id "87815d72a81d739d2a7ce15c2cfdefb3") -;;TODO for development only should be removed in status 2.0 -(def new-ui-enabled? true) - (def delete-message-undo-time-limit-ms 4000) (def delete-message-for-me-undo-time-limit-ms 4000) diff --git a/src/status_im2/constants.cljs b/src/status_im2/constants.cljs index edbafde851..5935694586 100644 --- a/src/status_im2/constants.cljs +++ b/src/status_im2/constants.cljs @@ -265,3 +265,7 @@ (def ^:const multi-code-prefix "We prefix our keys with 0xe701 prior to serialisation them" "0xe701") + +(def ^:const theme-type-system 0) +(def ^:const theme-type-light 1) +(def ^:const theme-type-dark 2) diff --git a/src/status_im2/contexts/chat/events.cljs b/src/status_im2/contexts/chat/events.cljs index 1323498bf1..9dac4d9a0a 100644 --- a/src/status_im2/contexts/chat/events.cljs +++ b/src/status_im2/contexts/chat/events.cljs @@ -167,9 +167,12 @@ {:db (dissoc db :current-chat-id)} (let [community-id (get-in db [:chats chat-id :community-id])] ;; When navigating back from community chat to community, update switcher card + ;; A close chat event is also called while opening any chat. + ;; That might lead to duplicate :dispatch keys in fx/merge, that's why dispatch-n is + ;; used here. (when (and community-id (not navigate-to-shell?)) - {:dispatch [:shell/add-switcher-card - :community {:community-id community-id}]}))) + {:dispatch-n [[:shell/add-switcher-card + :community {:community-id community-id}]]}))) (delete-for-me/sync-all) (delete-message/send-all) (offload-messages chat-id)))) diff --git a/src/status_im2/contexts/shell/animation.cljs b/src/status_im2/contexts/shell/animation.cljs index 13bffbb43b..36e3cd5c9c 100644 --- a/src/status_im2/contexts/shell/animation.cljs +++ b/src/status_im2/contexts/shell/animation.cljs @@ -1,6 +1,6 @@ (ns status-im2.contexts.shell.animation (:require [quo2.foundations.colors :as colors] - [re-frame.core :as re-frame] + [utils.re-frame :as rf] [react-native.reanimated :as reanimated] [reagent.core :as reagent] [status-im.async-storage.core :as async-storage] @@ -142,6 +142,14 @@ ;; Animations +(defn change-root-status-bar-style + [] + (rf/dispatch [:change-root-status-bar-style + (if (or (colors/dark?) + (not (home-stack-open?))) + :light + :dark)])) + (defn open-home-stack [stack-id animate?] (let [home-stack-state-value (if animate? @@ -153,11 +161,10 @@ (reanimated/set-shared-value (:home-stack-state @shared-values-atom) home-stack-state-value) - (when-not (colors/dark?) - (js/setTimeout - #(re-frame/dispatch [:change-root-status-bar-style :dark]) - shell.constants/shell-animation-time)) (reset! home-stack-state home-stack-state-value) + (js/setTimeout + change-root-status-bar-style + shell.constants/shell-animation-time) (reset! selected-stack-id stack-id) (async-storage/set-item! :selected-stack-id stack-id))) @@ -190,8 +197,7 @@ (reanimated/set-shared-value (:home-stack-state @shared-values-atom) home-stack-state-value) - (when-not (colors/dark?) - (re-frame/dispatch [:change-root-status-bar-style :light])) (reset! home-stack-state home-stack-state-value) + (change-root-status-bar-style) (reset! selected-stack-id nil) (async-storage/set-item! :selected-stack-id nil))) diff --git a/src/status_im2/contexts/shell/events.cljs b/src/status_im2/contexts/shell/events.cljs index bf975929a2..fd3e39cffc 100644 --- a/src/status_im2/contexts/shell/events.cljs +++ b/src/status_im2/contexts/shell/events.cljs @@ -4,6 +4,7 @@ [status-im.utils.core :as utils] [status-im2.constants :as constants] [status-im2.navigation.events :as navigation] + [status-im.async-storage.core :as async-storage] [status-im2.contexts.shell.animation :as animation] [status-im2.contexts.shell.constants :as shell.constants] [status-im.data-store.switcher-cards :as switcher-cards-store])) @@ -24,6 +25,7 @@ :shell/reset-bottom-tabs (fn [] (let [selected-stack-id @animation/selected-stack-id] + (async-storage/set-item! :selected-stack-id nil) (reset! animation/load-communities-stack? (= selected-stack-id :communities-stack)) (reset! animation/load-chats-stack? (= selected-stack-id :chats-stack)) (reset! animation/load-wallet-stack? (= selected-stack-id :wallet-stack)) diff --git a/src/status_im2/contexts/shell/view.cljs b/src/status_im2/contexts/shell/view.cljs index 32d2bc578e..765fdb38df 100644 --- a/src/status_im2/contexts/shell/view.cljs +++ b/src/status_im2/contexts/shell/view.cljs @@ -112,6 +112,7 @@ [:f> (fn [] (let [shared-values (animation/calculate-shared-values)] + (animation/change-root-status-bar-style) [rn/view {:style {:flex 1} :on-layout (when-not @animation/screen-height diff --git a/src/status_im2/navigation/core.cljs b/src/status_im2/navigation/core.cljs index a1050c5c1a..9d5c9c6a46 100644 --- a/src/status_im2/navigation/core.cljs +++ b/src/status_im2/navigation/core.cljs @@ -372,6 +372,11 @@ (fn [style] (navigation/merge-options "shell-stack" {:statusBar {:style style}}))) +(re-frame/reg-fx + :change-root-nav-bar-color-fx + (fn [color] + (navigation/merge-options "shell-stack" {:navigationBar {:backgroundColor color}}))) + (re-frame/reg-fx :pop-to-root-tab-fx (fn [tab] diff --git a/src/status_im2/navigation/events.cljs b/src/status_im2/navigation/events.cljs index 9b92450694..bf8cde840f 100644 --- a/src/status_im2/navigation/events.cljs +++ b/src/status_im2/navigation/events.cljs @@ -123,3 +123,8 @@ {:events [:change-root-status-bar-style]} [_ style] {:change-root-status-bar-style-fx style}) + +(rf/defn change-root-nav-bar-color + {:events [:change-root-nav-bar-color]} + [_ color] + {:change-root-nav-bar-color-fx color}) diff --git a/src/status_im2/navigation/roots.cljs b/src/status_im2/navigation/roots.cljs index 43413ae5ac..6fe7ae22df 100644 --- a/src/status_im2/navigation/roots.cljs +++ b/src/status_im2/navigation/roots.cljs @@ -1,16 +1,19 @@ (ns status-im2.navigation.roots (:require [quo2.foundations.colors :as colors] [react-native.platform :as platform] - [status-im2.navigation.view :as views])) + [status-im2.navigation.view :as views] + [status-im2.navigation.state :as state] + [status-im2.common.theme.core :as utils.theme])) (defn status-bar-options [] - (if platform/android? - {:navigationBar {:backgroundColor colors/neutral-100} - :statusBar {:backgroundColor :transparent - :style :light - :drawBehind true}} - {:statusBar {:style :light}})) + (let [dark-mode? (if (= @state/root-id :shell-stack) (colors/dark?) (utils.theme/dark-mode?))] + (if platform/android? + {:navigationBar {:backgroundColor colors/neutral-100} + :statusBar {:backgroundColor :transparent + :style (if dark-mode? :light :dark) + :drawBehind true}} + {:statusBar {:style (if dark-mode? :light :dark)}}))) (defn topbar-options [] diff --git a/src/status_im2/subs/home.cljs b/src/status_im2/subs/home.cljs index 1452d6f122..73e5963d85 100644 --- a/src/status_im2/subs/home.cljs +++ b/src/status_im2/subs/home.cljs @@ -1,6 +1,5 @@ (ns status-im2.subs.home - (:require [re-frame.core :as re-frame] - [status-im2.config :as config])) + (:require [re-frame.core :as re-frame])) (def memo-home-items (atom nil)) @@ -12,8 +11,7 @@ :<- [:view-id] :<- [:home-items-show-number] (fn [[search-filter filtered-chats communities view-id home-items-show-number]] - (if (or (= view-id :home) - (and config/new-ui-enabled? (= view-id :shell-stack))) + (if (= view-id :shell-stack) (let [communities-count (count communities) chats-count (count filtered-chats) ;; If we have both communities & chats we want to display