Skip to content

Commit 0649c66

Browse files
authored
fix device theme change listener in ios (#15724)
1 parent 1b0374a commit 0649c66

File tree

7 files changed

+45
-11
lines changed

7 files changed

+45
-11
lines changed

src/react_native/navigation.cljs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@
4141
[comp]
4242
(.catch (.dismissOverlay Navigation comp) #()))
4343

44+
(defn dissmiss-all-overlays
45+
[]
46+
(.catch (.dismissAllOverlays Navigation) #()))
47+
4448
(defn reg-app-launched-listener
4549
[handler]
4650
(.registerAppLaunchedListener ^js (.events ^js Navigation) handler))

src/status_im/events.cljs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@
6060
status-im2.contexts.onboarding.events
6161
status-im.chat.models.gaps
6262
[status-im2.navigation.events :as navigation]
63+
[status-im2.common.theme.core :as theme]
64+
[react-native.core :as rn]
65+
[react-native.platform :as platform]
6366
status-im2.contexts.chat.home.events))
6467

6568
(re-frame/reg-fx
@@ -90,6 +93,10 @@
9093
(re-frame/reg-fx
9194
::app-state-change-fx
9295
(fn [state]
96+
(when (and platform/ios? (= state "active"))
97+
;; Change the app theme if the ios device theme was updated when the app was in the background
98+
;; https://github.com/status-im/status-mobile/issues/15708
99+
(theme/change-device-theme (rn/get-color-scheme)))
93100
(status/app-state-change state)))
94101

95102
(re-frame/reg-fx

src/status_im/multiaccounts/core.cljs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@
150150
(re-frame/dispatch [:change-shell-status-bar-style
151151
(if (shell.animation/home-stack-open?) status-bar-theme :light)])
152152
(when reload-ui?
153+
(rf/dispatch [:dissmiss-all-overlays])
153154
(hot-reload/reload)
154155
(when-not (= view-id :shell-stack)
155156
(re-frame/dispatch [:change-shell-nav-bar-color nav-bar-color]))))))

src/status_im2/common/theme/core.cljs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,29 @@
11
(ns status-im2.common.theme.core
22
(:require [quo.theme :as quo]
33
[quo2.theme :as quo2]
4-
[react-native.core :as rn]))
4+
[utils.re-frame :as rf]
5+
[oops.core :refer [oget]]
6+
[react-native.core :as rn]
7+
[react-native.platform :as platform]))
58

69
(def device-theme (atom (rn/get-color-scheme)))
710

8-
;; Note - don't use value returned by change listener
9-
;; https://github.com/facebook/react-native/issues/28525
11+
(defn change-device-theme
12+
[theme]
13+
(when-not (= theme @device-theme)
14+
(reset! device-theme theme)
15+
(rf/dispatch [:system-theme-mode-changed (keyword theme)])))
16+
17+
;; Appearance change listener fires false events in ios when the app is in the background
18+
;; So, we are ignoring those events and when the device returns form the background,
19+
;; we are manually checking the device theme, in ::app-state-change-fx
20+
;; https://github.com/status-im/status-mobile/issues/15708
1021
(defn add-device-theme-change-listener
11-
[callback]
12-
(rn/appearance-add-change-listener #(let [theme (rn/get-color-scheme)]
13-
(when-not (= theme @device-theme)
14-
(reset! device-theme theme)
15-
(callback (keyword theme))))))
22+
[]
23+
(rn/appearance-add-change-listener
24+
#(when (or platform/android?
25+
(not= (oget rn/app-state "currentState") "background"))
26+
(change-device-theme (oget % "colorScheme")))))
1627

1728
(defn device-theme-dark?
1829
[]

src/status_im2/events.cljs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@
3030
(re-frame/reg-fx
3131
:setup/init-theme
3232
(fn []
33-
(theme/add-device-theme-change-listener
34-
#(re-frame/dispatch [:system-theme-mode-changed %]))))
33+
(theme/add-device-theme-change-listener)))
3534

3635
(rf/defn initialize-views
3736
{:events [:setup/initialize-view]}

src/status_im2/navigation/core.cljs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@
160160
;; OVERLAY
161161
(def dissmiss-overlay navigation/dissmiss-overlay)
162162

163+
(def dissmiss-all-overlays navigation/dissmiss-all-overlays)
164+
163165
(defn show-overlay
164166
([comp] (show-overlay comp {}))
165167
([comp opts]
@@ -173,6 +175,8 @@
173175
:overlay {:interceptTouchOutside true}}
174176
opts)}})))
175177

178+
(re-frame/reg-fx :dissmiss-all-overlays-fx dissmiss-all-overlays)
179+
176180
;; toast
177181
(navigation/register-component "toasts" (fn [] views/toasts) js/undefined)
178182

src/status_im2/navigation/events.cljs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@
7070
{:events [:hide-bottom-sheet]}
7171
[{:keys [db]}]
7272
(let [{:keys [hide? sheets]} (:bottom-sheet db)]
73-
(println :hide-bottom-sheet (not hide?) (seq sheets))
7473
(when (and (not hide?) (seq sheets))
7574
{:db (assoc-in db [:bottom-sheet :hide?] true)})))
7675

@@ -140,3 +139,12 @@
140139
key-uid
141140
:keycard-pairing]))]
142141
{:set-root (if keycard-account? :multiaccounts-keycard :multiaccounts)}))
142+
143+
(rf/defn dismiss-all-overlays
144+
{:events [:dissmiss-all-overlays]}
145+
[{:keys [db]}]
146+
{:dissmiss-all-overlays-fx nil
147+
:db (-> db
148+
(dissoc :popover/popover)
149+
(dissoc :visibility-status-popover/popover)
150+
(assoc-in [:bottom-sheet :hide?] true))})

0 commit comments

Comments
 (0)