Skip to content

Commit ffba396

Browse files
authored
fix distortion of app theme due to change in system theme (#12934)
1 parent 9616922 commit ffba396

File tree

6 files changed

+88
-15
lines changed

6 files changed

+88
-15
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<color name="alert_text">#ffffff</color>
4+
</resources>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<color name="alert_text">#000000</color>
4+
</resources>

android/app/src/main/res/values/styles.xml

+6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<item name="android:forceDarkAllowed">true</item>
99
<item name="android:windowTranslucentStatus">false</item>
1010
<item name="android:statusBarColor">?attr/backgroundColor</item>
11+
<item name="android:alertDialogTheme">@style/AlertDialogTheme</item>
1112
</style>
1213

1314
<style name="LightTheme" parent="AppTheme">
@@ -21,4 +22,9 @@
2122
<item name="backgroundColor">#000000</item>
2223
<item name="android:windowLightStatusBar">false</item>
2324
</style>
25+
26+
<style name="AlertDialogTheme" parent="Base.Theme.AppCompat.Light.Dialog.Alert">
27+
<item name="android:textColor">@color/alert_text</item>
28+
<item name="android:textColorPrimary">@color/alert_text</item>
29+
</style>
2430
</resources>

src/status_im/events.cljs

+32-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
[status-im.async-storage.core :as async-storage]
77
status-im.backup.core
88
status-im.bootnodes.core
9-
status-im.bottom-sheet.core
9+
[status-im.bottom-sheet.core :as bottom-sheet]
1010
status-im.browser.core
1111
status-im.browser.permissions
1212
[status-im.chat.models :as chat]
@@ -58,7 +58,9 @@
5858
status-im.wallet.accounts.core
5959
status-im.wallet.choose-recipient.core
6060
[status-im.wallet.core :as wallet]
61-
status-im.wallet.custom-tokens.core))
61+
status-im.wallet.custom-tokens.core
62+
[status-im.navigation.core :as navigation.core]
63+
[status-im.multiaccounts.login.core :as login.core]))
6264

6365
(re-frame/reg-fx
6466
:dismiss-keyboard
@@ -112,10 +114,35 @@
112114

113115
(fx/defn system-theme-mode-changed
114116
{:events [:system-theme-mode-changed]}
115-
[{:keys [db]} theme]
116-
(let [cur-theme (get-in db [:multiaccount :appearance])]
117+
[{:keys [db] :as cofx} theme]
118+
(let [cur-theme (get-in db [:multiaccount :appearance])
119+
current-tab (get db :current-tab :chat)
120+
view-id (:view-id db)
121+
screen-params (get-in db [:navigation/screen-params view-id])
122+
root-id @navigation.core/root-id]
123+
(navigation.core/dismiss-all-modals)
117124
(when (or (nil? cur-theme) (zero? cur-theme))
118-
{::multiaccounts/switch-theme (if (= :dark theme) 2 1)})))
125+
(fx/merge cofx
126+
{::multiaccounts/switch-theme (if (= :dark theme) 2 1)
127+
:utils/dispatch-later
128+
(cond-> [{:ms 2000 :dispatch
129+
(if (= view-id :chat)
130+
[:chat.ui/navigate-to-chat (:current-chat-id db)]
131+
[:navigate-to view-id screen-params])}]
132+
133+
(some #(= view-id %) navigation.core/community-screens)
134+
(conj {:ms 1000 :dispatch
135+
[:navigate-to :community
136+
(get-in db [:navigation/screen-params :community])]})
137+
138+
(= view-id :community-emoji-thumbnail-picker)
139+
(conj {:ms 1500 :dispatch
140+
[:navigate-to :create-community-channel
141+
(get-in db [:navigation/screen-params :create-community-channel])]}))}
142+
(bottom-sheet/hide-bottom-sheet)
143+
(navigation/init-root root-id)
144+
(when (= root-id :chat-stack)
145+
(navigation/change-tab current-tab))))))
119146

120147
(def authentication-options
121148
{:reason (i18n/label :t/biometric-auth-reason-login)})

src/status_im/navigation/core.cljs

+37-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
(ns status-im.navigation.core
22
(:require
33
["react-native" :as rn]
4+
[clojure.set :as clojure.set]
45
["react-native-gesture-handler" :refer (gestureHandlerRootHOC)]
56
["react-native-navigation" :refer (Navigation)]
67
[quo.components.text-input :as quo.text-input]
@@ -157,12 +158,14 @@
157158
(.registerComponentDidDisappearListener
158159
(.events Navigation)
159160
(fn [^js evn]
160-
(when-not (#{"popover" "bottom-sheet" "signing-sheet" "visibility-status-popover"}
161-
(.-componentName evn))
162-
(doseq [[_ {:keys [ref value]}] @quo.text-input/text-input-refs]
163-
(.setNativeProps ^js ref (clj->js {:text value})))
164-
(doseq [[^js text-input default-value] @react/text-input-refs]
165-
(.setNativeProps text-input (clj->js {:text default-value})))))))
161+
(let [view-id (keyword (.-componentName evn))]
162+
(when-not (#{"popover" "bottom-sheet" "signing-sheet" "visibility-status-popover"}
163+
(.-componentName evn))
164+
(re-frame/dispatch [::view-disappeared view-id])
165+
(doseq [[_ {:keys [ref value]}] @quo.text-input/text-input-refs]
166+
(.setNativeProps ^js ref (clj->js {:text value})))
167+
(doseq [[^js text-input default-value] @react/text-input-refs]
168+
(.setNativeProps text-input (clj->js {:text default-value}))))))))
166169

167170
;; SET ROOT
168171
(re-frame/reg-fx
@@ -277,7 +280,10 @@
277280
(.registerBottomTabSelectedListener
278281
(.events Navigation)
279282
(fn [^js evn]
280-
(let [comp (get tab-root-ids (.-selectedTabIndex evn))]
283+
(let [selected-tab-index (.-selectedTabIndex evn)
284+
comp (get tab-root-ids selected-tab-index)
285+
tab-key (get (clojure.set/map-invert tab-key-idx) selected-tab-index)]
286+
(re-frame/dispatch [:set :current-tab tab-key])
281287
(when (and platform/android? (= @root-comp-id comp))
282288
(.popToRoot Navigation (name comp)))
283289
(reset! root-comp-id comp)))))
@@ -377,3 +383,27 @@
377383
(log/debug :navigate-replace-fx view-id)
378384
(.pop Navigation (name @root-comp-id))
379385
(navigate view-id)))
386+
387+
(def community-screens '(:community-management
388+
:community-members
389+
:community-requests-to-join
390+
:create-community-channel
391+
:community-emoji-thumbnail-picker
392+
:create-community-category
393+
:community-edit-chats))
394+
395+
;; change view-id if it is still same after component is disappeared
396+
;; https://github.com/wix/react-native-navigation/issues/5744#issuecomment-563226820
397+
(fx/defn view-disappeared
398+
{:events [::view-disappeared]}
399+
[{:keys [db]} view-id]
400+
(when (= view-id (:view-id db))
401+
{:db (assoc db :view-id (cond
402+
(= view-id :community-emoji-thumbnail-picker)
403+
:create-community-channel
404+
405+
(some #(= view-id %) community-screens)
406+
:community
407+
408+
:else
409+
:home))}))

src/status_im/ui/screens/chat/photos.cljs

+5-3
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44
[status-im.ui.screens.chat.styles.photos :as style]
55
[status-im.profile.db :as profile.db]
66
[status-im.multiaccounts.core :as multiaccounts]
7-
[status-im.utils.image :as utils.image]))
7+
[status-im.utils.image :as utils.image]
8+
[quo.design-system.colors :as colors]))
89

910
(def memo-photo-rend
1011
(memoize
11-
(fn [photo-path size accessibility-label]
12+
(fn [photo-path size accessibility-label _]
1213
(let [identicon? (when photo-path (profile.db/base64-png? photo-path))]
1314
[react/view {:style (style/photo-container size)}
1415
[react/image {:source (utils.image/source photo-path)
@@ -18,8 +19,9 @@
1819
(when identicon?
1920
[react/view {:style (style/photo-border size)}])]))))
2021

22+
;; "(colors/dark?)" is passed to memoized function to avoid previous themes cache
2123
(defn photo [photo-path {:keys [size accessibility-label]}]
22-
[memo-photo-rend photo-path size accessibility-label])
24+
[memo-photo-rend photo-path size accessibility-label (colors/dark?)])
2325

2426
;; We optionally pass identicon for perfomance reason, so it does not have to be calculated for each message
2527
(defn member-photo [pub-key identicon]

0 commit comments

Comments
 (0)