|
10 | 10 | [status-im.ui.components.react :as react]
|
11 | 11 | [quo.components.text-input :as quo.text-input]
|
12 | 12 | [status-im.ui.components.icons.icons :as icons]
|
13 |
| - [quo.design-system.colors :as quo.colors])) |
| 13 | + [quo.design-system.colors :as quo.colors] |
| 14 | + ["react-native" :as rn])) |
14 | 15 |
|
15 | 16 | (def debug? ^boolean js/goog.DEBUG)
|
16 | 17 |
|
| 18 | +(def splash-screen (-> rn .-NativeModules .-SplashScreen)) |
| 19 | + |
17 | 20 | (defonce root-comp-id (atom nil))
|
| 21 | +(defonce root-id (atom nil)) |
18 | 22 | (defonce pushed-screen-id (atom nil))
|
19 | 23 | (defonce curr-modal (atom nil))
|
20 | 24 | (defonce modals (atom []))
|
| 25 | +(defonce dissmissing (atom false)) |
21 | 26 |
|
22 | 27 | ;; REGISTER COMPONENT (LAZY)
|
23 | 28 | (defn reg-comp [key]
|
|
57 | 62 | :icon (icons/icon-source :main-icons/close)}}
|
58 | 63 | options)))
|
59 | 64 |
|
60 |
| -(re-frame/reg-fx |
61 |
| - :open-modal-fx |
62 |
| - (fn [comp] |
63 |
| - (let [{:keys [options]} (get views/screens comp)] |
64 |
| - (reset! curr-modal true) |
65 |
| - (swap! modals conj comp) |
66 |
| - (.showModal Navigation |
67 |
| - (clj->js {:stack {:children |
68 |
| - [{:component |
69 |
| - {:name comp |
70 |
| - :id comp |
71 |
| - :options (update-modal-topbar-options |
72 |
| - (merge (roots/status-bar-options) |
73 |
| - (roots/default-root) |
74 |
| - options))}}]}}))))) |
| 65 | +(defn open-modal [comp] |
| 66 | + (let [{:keys [options]} (get views/screens comp)] |
| 67 | + (if @dissmissing |
| 68 | + (reset! dissmissing comp) |
| 69 | + (do |
| 70 | + (println "SHOW MODAL" comp) |
| 71 | + (reset! curr-modal true) |
| 72 | + (swap! modals conj comp) |
| 73 | + (.showModal Navigation |
| 74 | + (clj->js {:stack {:children |
| 75 | + [{:component |
| 76 | + {:name comp |
| 77 | + :id comp |
| 78 | + :options (update-modal-topbar-options |
| 79 | + (merge (roots/status-bar-options) |
| 80 | + (roots/default-root) |
| 81 | + options))}}]}})))))) |
| 82 | + |
| 83 | +(re-frame/reg-fx :open-modal-fx open-modal) |
75 | 84 |
|
76 | 85 | ;; DISSMISS MODAL
|
77 | 86 | (defn dissmissModal []
|
| 87 | + (println "dissmissModal" @modals) |
| 88 | + (reset! dissmissing true) |
78 | 89 | (.dismissModal Navigation (name (last @modals))))
|
79 | 90 |
|
80 | 91 | (defonce register-nav-button-reg
|
|
83 | 94 | (fn [^js evn]
|
84 | 95 | (let [id (.-buttonId evn)]
|
85 | 96 | (if (= "dismiss-modal" id)
|
86 |
| - (dissmissModal) |
| 97 | + (do |
| 98 | + (when-let [event (get-in views/screens [(last @modals) :on-dissmiss])] |
| 99 | + (re-frame/dispatch event)) |
| 100 | + (dissmissModal)) |
87 | 101 | (when-let [handler (get-in views/screens [(keyword id) :right-handler])]
|
88 | 102 | (handler)))))))
|
89 | 103 |
|
90 | 104 | (defonce register-modal-reg
|
91 | 105 | (.registerModalDismissedListener
|
92 | 106 | (.events Navigation)
|
93 | 107 | (fn [_]
|
94 |
| - (when-let [event (get-in views/screens [(last @modals) :on-dissmiss])] |
95 |
| - (re-frame/dispatch event)) |
| 108 | + (println "DismissedListener" @dissmissing @modals) |
96 | 109 | (if (> (count @modals) 1)
|
97 | 110 | (let [new-modals (butlast @modals)]
|
98 | 111 | (reset! modals (vec new-modals))
|
99 | 112 | (re-frame/dispatch [:set :view-id (last new-modals)]))
|
100 | 113 | (do
|
101 | 114 | (reset! modals [])
|
102 | 115 | (reset! curr-modal false)
|
103 |
| - (re-frame/dispatch [:set :view-id @pushed-screen-id])))))) |
| 116 | + (re-frame/dispatch [:set :view-id @pushed-screen-id]))) |
| 117 | + |
| 118 | + (let [comp @dissmissing] |
| 119 | + (reset! dissmissing false) |
| 120 | + (when (keyword? comp) |
| 121 | + (open-modal comp)))))) |
104 | 122 |
|
105 | 123 | ;; SCREEN DID APPEAR
|
106 | 124 | (defonce screen-appear-reg
|
|
129 | 147 | ;; SET ROOT
|
130 | 148 | (re-frame/reg-fx
|
131 | 149 | :init-root-fx
|
132 |
| - (fn [root-id] |
133 |
| - (reset! root-comp-id root-id) |
134 |
| - (.setRoot Navigation (clj->js (get (roots/roots) root-id))))) |
| 150 | + (fn [new-root-id] |
| 151 | + (reset! root-comp-id new-root-id) |
| 152 | + (reset! root-id new-root-id) |
| 153 | + (.setRoot Navigation (clj->js (get (roots/roots) new-root-id))))) |
| 154 | + |
| 155 | +(defonce rset-app-launched |
| 156 | + (.registerAppLaunchedListener (.events Navigation) |
| 157 | + (fn [] |
| 158 | + (when @root-id |
| 159 | + (reset! root-comp-id @root-id) |
| 160 | + (.setRoot Navigation (clj->js (get (roots/roots) @root-id)))) |
| 161 | + (.hide ^js splash-screen)))) |
135 | 162 |
|
136 | 163 | (defn get-screen-component [comp]
|
137 | 164 | (let [{:keys [options]} (get views/screens comp)]
|
|
214 | 241 | (clj->js
|
215 | 242 | {:component {:name comp
|
216 | 243 | :id comp
|
217 |
| - :options (merge (if platform/android? |
218 |
| - {:statusBar {:translucent true}} |
219 |
| - (roots/status-bar-options)) |
| 244 | + :options (merge (cond-> (roots/status-bar-options) |
| 245 | + platform/android? |
| 246 | + (assoc-in [:statusBar :translucent] true)) |
220 | 247 | {:layout {:componentBackgroundColor (if platform/android?
|
221 | 248 | (:backdrop @quo.colors/theme)
|
222 | 249 | "transparent")}
|
|
0 commit comments