|
1 | 1 | (ns status-im.navigation.effects
|
2 | 2 | (:require
|
| 3 | + [quo.foundations.colors :as colors] |
3 | 4 | [quo.theme]
|
4 | 5 | [react-native.core :as rn]
|
5 | 6 | [react-native.navigation :as navigation]
|
| 7 | + [react-native.platform :as platform] |
| 8 | + [status-im.contexts.shell.jump-to.constants :as shell.constants] |
| 9 | + [status-im.contexts.shell.jump-to.utils :as jump-to.utils] |
6 | 10 | [status-im.navigation.options :as options]
|
7 | 11 | [status-im.navigation.roots :as roots]
|
8 | 12 | [status-im.navigation.state :as state]
|
9 | 13 | [status-im.navigation.view :as views]
|
10 | 14 | [taoensso.timbre :as log]
|
11 | 15 | [utils.re-frame :as rf]))
|
12 | 16 |
|
13 |
| -(defn- set-status-bar-color |
14 |
| - [theme] |
15 |
| - (rn/set-status-bar-style |
16 |
| - (if (= theme :dark) |
17 |
| - "light-content" |
18 |
| - "dark-content") |
19 |
| - true)) |
| 17 | +(defn get-status-nav-color |
| 18 | + [view-id] |
| 19 | + (let [theme (or (get-in views/screens [view-id :options :theme]) |
| 20 | + (quo.theme/get-theme)) |
| 21 | + [rnn-status-bar rn-status-bar] |
| 22 | + (if (or (= theme :dark) |
| 23 | + @state/alert-banner-shown? |
| 24 | + (and (= view-id :shell-stack) (not (jump-to.utils/home-stack-open?)))) |
| 25 | + [:light "light-content"] |
| 26 | + [:dark "dark-content"]) |
| 27 | + home-stack? (some #(= view-id %) shell.constants/stacks-ids) |
| 28 | + ;; Home screen nav bar always dark due to bottom tabs |
| 29 | + nav-bar-color (if (or home-stack? |
| 30 | + (= view-id :shell-stack) |
| 31 | + (= theme :dark)) |
| 32 | + colors/neutral-100 |
| 33 | + colors/white) |
| 34 | + comp-id (if (or home-stack? |
| 35 | + (jump-to.utils/shell-navigation? view-id) |
| 36 | + (= view-id :shell)) |
| 37 | + :shell-stack |
| 38 | + view-id)] |
| 39 | + [rnn-status-bar rn-status-bar nav-bar-color comp-id])) |
| 40 | + |
| 41 | +(defn reload-status-nav-color-fx |
| 42 | + [view-id] |
| 43 | + (when (and (= @state/root-id :shell-stack) view-id) |
| 44 | + (let [[rnn-status-bar rn-status-bar nav-bar-color comp-id] (get-status-nav-color view-id)] |
| 45 | + (if platform/ios? |
| 46 | + (rn/set-status-bar-style rn-status-bar true) |
| 47 | + (navigation/merge-options |
| 48 | + (name comp-id) |
| 49 | + {:statusBar {:style rnn-status-bar} |
| 50 | + :navigationBar {:backgroundColor nav-bar-color}}))))) |
| 51 | + |
| 52 | +(rf/reg-fx :reload-status-nav-color-fx reload-status-nav-color-fx) |
20 | 53 |
|
21 | 54 | (rf/reg-fx :set-view-id-fx
|
22 | 55 | (fn [view-id]
|
| 56 | + (reload-status-nav-color-fx view-id) |
23 | 57 | (rf/dispatch [:screens/on-will-focus view-id])
|
24 |
| - (when-let [{:keys [on-focus options]} (get views/screens view-id)] |
25 |
| - (set-status-bar-color (or (:theme options) |
26 |
| - (quo.theme/get-theme))) |
| 58 | + (when-let [{:keys [on-focus]} (get views/screens view-id)] |
27 | 59 | (when on-focus
|
28 | 60 | (rf/dispatch on-focus)))))
|
29 | 61 |
|
|
167 | 199 | opts)}})))
|
168 | 200 |
|
169 | 201 | (rf/reg-fx :show-toasts
|
170 |
| - (fn [] |
171 |
| - (show-overlay "toasts" |
172 |
| - {:overlay {:interceptTouchOutside false} |
173 |
| - :layout {:componentBackgroundColor :transparent |
174 |
| - :orientation ["portrait"]}}))) |
| 202 | + (fn [view-id] |
| 203 | + (let [[rnn-status-bar nav-bar-color] (get-status-nav-color view-id)] |
| 204 | + (show-overlay "toasts" |
| 205 | + (assoc (options/statusbar-and-navbar-options nil rnn-status-bar nav-bar-color) |
| 206 | + :overlay |
| 207 | + {:interceptTouchOutside false}))))) |
175 | 208 |
|
176 | 209 | (rf/reg-fx :hide-toasts
|
177 | 210 | (fn [] (navigation/dissmiss-overlay "toasts")))
|
|
186 | 219 |
|
187 | 220 | ;;;; Alert Banner
|
188 | 221 | (rf/reg-fx :show-alert-banner
|
189 |
| - (fn [] (show-overlay "alert-banner" {:overlay {:interceptTouchOutside false}}))) |
| 222 | + (fn [view-id] |
| 223 | + (show-overlay "alert-banner" {:overlay {:interceptTouchOutside false}}) |
| 224 | + (reset! state/alert-banner-shown? true) |
| 225 | + (reload-status-nav-color-fx view-id))) |
190 | 226 |
|
191 | 227 | (rf/reg-fx :hide-alert-banner
|
192 |
| - (fn [] (navigation/dissmiss-overlay "alert-banner"))) |
| 228 | + (fn [view-id] |
| 229 | + (navigation/dissmiss-overlay "alert-banner") |
| 230 | + (reset! state/alert-banner-shown? false) |
| 231 | + (reload-status-nav-color-fx view-id))) |
193 | 232 |
|
194 | 233 | ;;;; Merge options
|
195 | 234 |
|
|
0 commit comments