mirror of
https://github.com/status-im/status-react.git
synced 2025-02-26 01:25:33 +00:00
fix device theme change listener in ios (#15724)
This commit is contained in:
parent
1b0374a156
commit
0649c66dde
@ -41,6 +41,10 @@
|
|||||||
[comp]
|
[comp]
|
||||||
(.catch (.dismissOverlay Navigation comp) #()))
|
(.catch (.dismissOverlay Navigation comp) #()))
|
||||||
|
|
||||||
|
(defn dissmiss-all-overlays
|
||||||
|
[]
|
||||||
|
(.catch (.dismissAllOverlays Navigation) #()))
|
||||||
|
|
||||||
(defn reg-app-launched-listener
|
(defn reg-app-launched-listener
|
||||||
[handler]
|
[handler]
|
||||||
(.registerAppLaunchedListener ^js (.events ^js Navigation) handler))
|
(.registerAppLaunchedListener ^js (.events ^js Navigation) handler))
|
||||||
|
@ -60,6 +60,9 @@
|
|||||||
status-im2.contexts.onboarding.events
|
status-im2.contexts.onboarding.events
|
||||||
status-im.chat.models.gaps
|
status-im.chat.models.gaps
|
||||||
[status-im2.navigation.events :as navigation]
|
[status-im2.navigation.events :as navigation]
|
||||||
|
[status-im2.common.theme.core :as theme]
|
||||||
|
[react-native.core :as rn]
|
||||||
|
[react-native.platform :as platform]
|
||||||
status-im2.contexts.chat.home.events))
|
status-im2.contexts.chat.home.events))
|
||||||
|
|
||||||
(re-frame/reg-fx
|
(re-frame/reg-fx
|
||||||
@ -90,6 +93,10 @@
|
|||||||
(re-frame/reg-fx
|
(re-frame/reg-fx
|
||||||
::app-state-change-fx
|
::app-state-change-fx
|
||||||
(fn [state]
|
(fn [state]
|
||||||
|
(when (and platform/ios? (= state "active"))
|
||||||
|
;; Change the app theme if the ios device theme was updated when the app was in the background
|
||||||
|
;; https://github.com/status-im/status-mobile/issues/15708
|
||||||
|
(theme/change-device-theme (rn/get-color-scheme)))
|
||||||
(status/app-state-change state)))
|
(status/app-state-change state)))
|
||||||
|
|
||||||
(re-frame/reg-fx
|
(re-frame/reg-fx
|
||||||
|
@ -150,6 +150,7 @@
|
|||||||
(re-frame/dispatch [:change-shell-status-bar-style
|
(re-frame/dispatch [:change-shell-status-bar-style
|
||||||
(if (shell.animation/home-stack-open?) status-bar-theme :light)])
|
(if (shell.animation/home-stack-open?) status-bar-theme :light)])
|
||||||
(when reload-ui?
|
(when reload-ui?
|
||||||
|
(rf/dispatch [:dissmiss-all-overlays])
|
||||||
(hot-reload/reload)
|
(hot-reload/reload)
|
||||||
(when-not (= view-id :shell-stack)
|
(when-not (= view-id :shell-stack)
|
||||||
(re-frame/dispatch [:change-shell-nav-bar-color nav-bar-color]))))))
|
(re-frame/dispatch [:change-shell-nav-bar-color nav-bar-color]))))))
|
||||||
|
@ -1,18 +1,29 @@
|
|||||||
(ns status-im2.common.theme.core
|
(ns status-im2.common.theme.core
|
||||||
(:require [quo.theme :as quo]
|
(:require [quo.theme :as quo]
|
||||||
[quo2.theme :as quo2]
|
[quo2.theme :as quo2]
|
||||||
[react-native.core :as rn]))
|
[utils.re-frame :as rf]
|
||||||
|
[oops.core :refer [oget]]
|
||||||
|
[react-native.core :as rn]
|
||||||
|
[react-native.platform :as platform]))
|
||||||
|
|
||||||
(def device-theme (atom (rn/get-color-scheme)))
|
(def device-theme (atom (rn/get-color-scheme)))
|
||||||
|
|
||||||
;; Note - don't use value returned by change listener
|
(defn change-device-theme
|
||||||
;; https://github.com/facebook/react-native/issues/28525
|
[theme]
|
||||||
|
(when-not (= theme @device-theme)
|
||||||
|
(reset! device-theme theme)
|
||||||
|
(rf/dispatch [:system-theme-mode-changed (keyword theme)])))
|
||||||
|
|
||||||
|
;; Appearance change listener fires false events in ios when the app is in the background
|
||||||
|
;; So, we are ignoring those events and when the device returns form the background,
|
||||||
|
;; we are manually checking the device theme, in ::app-state-change-fx
|
||||||
|
;; https://github.com/status-im/status-mobile/issues/15708
|
||||||
(defn add-device-theme-change-listener
|
(defn add-device-theme-change-listener
|
||||||
[callback]
|
[]
|
||||||
(rn/appearance-add-change-listener #(let [theme (rn/get-color-scheme)]
|
(rn/appearance-add-change-listener
|
||||||
(when-not (= theme @device-theme)
|
#(when (or platform/android?
|
||||||
(reset! device-theme theme)
|
(not= (oget rn/app-state "currentState") "background"))
|
||||||
(callback (keyword theme))))))
|
(change-device-theme (oget % "colorScheme")))))
|
||||||
|
|
||||||
(defn device-theme-dark?
|
(defn device-theme-dark?
|
||||||
[]
|
[]
|
||||||
|
@ -30,8 +30,7 @@
|
|||||||
(re-frame/reg-fx
|
(re-frame/reg-fx
|
||||||
:setup/init-theme
|
:setup/init-theme
|
||||||
(fn []
|
(fn []
|
||||||
(theme/add-device-theme-change-listener
|
(theme/add-device-theme-change-listener)))
|
||||||
#(re-frame/dispatch [:system-theme-mode-changed %]))))
|
|
||||||
|
|
||||||
(rf/defn initialize-views
|
(rf/defn initialize-views
|
||||||
{:events [:setup/initialize-view]}
|
{:events [:setup/initialize-view]}
|
||||||
|
@ -160,6 +160,8 @@
|
|||||||
;; OVERLAY
|
;; OVERLAY
|
||||||
(def dissmiss-overlay navigation/dissmiss-overlay)
|
(def dissmiss-overlay navigation/dissmiss-overlay)
|
||||||
|
|
||||||
|
(def dissmiss-all-overlays navigation/dissmiss-all-overlays)
|
||||||
|
|
||||||
(defn show-overlay
|
(defn show-overlay
|
||||||
([comp] (show-overlay comp {}))
|
([comp] (show-overlay comp {}))
|
||||||
([comp opts]
|
([comp opts]
|
||||||
@ -173,6 +175,8 @@
|
|||||||
:overlay {:interceptTouchOutside true}}
|
:overlay {:interceptTouchOutside true}}
|
||||||
opts)}})))
|
opts)}})))
|
||||||
|
|
||||||
|
(re-frame/reg-fx :dissmiss-all-overlays-fx dissmiss-all-overlays)
|
||||||
|
|
||||||
;; toast
|
;; toast
|
||||||
(navigation/register-component "toasts" (fn [] views/toasts) js/undefined)
|
(navigation/register-component "toasts" (fn [] views/toasts) js/undefined)
|
||||||
|
|
||||||
|
@ -70,7 +70,6 @@
|
|||||||
{:events [:hide-bottom-sheet]}
|
{:events [:hide-bottom-sheet]}
|
||||||
[{:keys [db]}]
|
[{:keys [db]}]
|
||||||
(let [{:keys [hide? sheets]} (:bottom-sheet db)]
|
(let [{:keys [hide? sheets]} (:bottom-sheet db)]
|
||||||
(println :hide-bottom-sheet (not hide?) (seq sheets))
|
|
||||||
(when (and (not hide?) (seq sheets))
|
(when (and (not hide?) (seq sheets))
|
||||||
{:db (assoc-in db [:bottom-sheet :hide?] true)})))
|
{:db (assoc-in db [:bottom-sheet :hide?] true)})))
|
||||||
|
|
||||||
@ -140,3 +139,12 @@
|
|||||||
key-uid
|
key-uid
|
||||||
:keycard-pairing]))]
|
:keycard-pairing]))]
|
||||||
{:set-root (if keycard-account? :multiaccounts-keycard :multiaccounts)}))
|
{:set-root (if keycard-account? :multiaccounts-keycard :multiaccounts)}))
|
||||||
|
|
||||||
|
(rf/defn dismiss-all-overlays
|
||||||
|
{:events [:dissmiss-all-overlays]}
|
||||||
|
[{:keys [db]}]
|
||||||
|
{:dissmiss-all-overlays-fx nil
|
||||||
|
:db (-> db
|
||||||
|
(dissoc :popover/popover)
|
||||||
|
(dissoc :visibility-status-popover/popover)
|
||||||
|
(assoc-in [:bottom-sheet :hide?] true))})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user