fix screen opens twice on app reopening in ios (#13157)

This commit is contained in:
Parvesh Monu 2022-03-10 19:20:50 +05:30 committed by GitHub
parent a3f4673177
commit 66482863c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 49 additions and 28 deletions

View File

@ -38,7 +38,7 @@
[status-im.navigation :as navigation]
status-im.notifications-center.core
status-im.pairing.core
status-im.popover.core
[status-im.popover.core :as popover]
status-im.profile.core
status-im.search.core
status-im.signals.core
@ -52,7 +52,7 @@
status-im.utils.logging.core
[status-im.utils.universal-links.core :as universal-links]
[status-im.utils.utils :as utils]
status-im.visibility-status-popover.core
[status-im.visibility-status-popover.core :as visibility-status-popover]
status-im.visibility-status-updates.core
status-im.waku.core
status-im.wallet.accounts.core
@ -60,7 +60,8 @@
[status-im.wallet.core :as wallet]
status-im.wallet.custom-tokens.core
[status-im.navigation.core :as navigation.core]
[status-im.multiaccounts.login.core :as login.core]))
[status-im.multiaccounts.login.core :as login.core]
[status-im.signing.core :as signing]))
(re-frame/reg-fx
:dismiss-keyboard
@ -115,31 +116,47 @@
(fx/defn system-theme-mode-changed
{:events [:system-theme-mode-changed]}
[{:keys [db] :as cofx} theme]
(let [cur-theme (get-in db [:multiaccount :appearance])
current-tab (get db :current-tab :chat)
view-id (:view-id db)
screen-params (get-in db [:navigation/screen-params view-id])
root-id @navigation.core/root-id]
(let [cur-theme (get-in db [:multiaccount :appearance])
current-tab (get db :current-tab :chat)
view-id (:view-id db)
screen-params (get-in db [:navigation/screen-params view-id])
root-id @navigation.core/root-id
dispatch-later (cond-> []
(= view-id :chat)
(conj {:ms 1000
:dispatch [:chat.ui/navigate-to-chat (:current-chat-id db)]})
(and
(= root-id :chat-stack)
(not-any? #(= view-id %) '(:home :empty-tab :wallet :status :my-profile :chat)))
(conj {:ms 1000
:dispatch [:navigate-to view-id screen-params]})
(some #(= view-id %) navigation.core/community-screens)
(conj {:ms 800 :dispatch
[:navigate-to :community
(get-in db [:navigation/screen-params :community])]})
(= view-id :community-emoji-thumbnail-picker)
(conj {:ms 900 :dispatch
[:navigate-to :create-community-channel
(get-in db [:navigation/screen-params :create-community-channel])]}))]
(navigation.core/dismiss-all-modals)
(when (or (nil? cur-theme) (zero? cur-theme))
(fx/merge cofx
{::multiaccounts/switch-theme (if (= :dark theme) 2 1)
:utils/dispatch-later
(cond-> [{:ms 2000 :dispatch
(if (= view-id :chat)
[:chat.ui/navigate-to-chat (:current-chat-id db)]
[:navigate-to view-id screen-params])}]
(some #(= view-id %) navigation.core/community-screens)
(conj {:ms 1000 :dispatch
[:navigate-to :community
(get-in db [:navigation/screen-params :community])]})
(= view-id :community-emoji-thumbnail-picker)
(conj {:ms 1500 :dispatch
[:navigate-to :create-community-channel
(get-in db [:navigation/screen-params :create-community-channel])]}))}
(bottom-sheet/hide-bottom-sheet)
(merge
{::multiaccounts/switch-theme (if (= :dark theme) 2 1)}
(when (seq dispatch-later)
{:utils/dispatch-later dispatch-later}))
(when (get-in db [:bottom-sheet/show?])
(bottom-sheet/hide-bottom-sheet))
(when (get-in db [:popover/popover])
(popover/hide-popover))
(when (get-in db [:visibility-status-popover/popover])
(visibility-status-popover/hide-visibility-status-popover))
(when (get-in db [:signing/tx])
(signing/discard))
(navigation/init-root root-id)
(when (= root-id :chat-stack)
(navigation/change-tab current-tab))))))

View File

@ -390,7 +390,9 @@
:create-community-channel
:community-emoji-thumbnail-picker
:create-community-category
:community-edit-chats))
:community-edit-chats
:community-edit
:community-reorder-categories))
;; change view-id if it is still same after component is disappeared
;; https://github.com/wix/react-native-navigation/issues/5744#issuecomment-563226820

View File

@ -1,11 +1,13 @@
(ns status-im.utils.theme
(:require ["react-native" :refer (Appearance)]
[oops.core :refer [oget ocall]]))
[oops.core :refer [ocall]]))
(def initial-mode (atom (ocall Appearance "getColorScheme")))
;; Note - don't use value returned by change listener
;; https://github.com/facebook/react-native/issues/28525
(defn add-mode-change-listener [callback]
(ocall Appearance "addChangeListener" #(let [mode (oget % "colorScheme")]
(ocall Appearance "addChangeListener" #(let [mode (ocall Appearance "getColorScheme")]
(when-not (= mode @initial-mode)
(reset! initial-mode mode)
(callback (keyword mode))))))