forked from status-im/status-legacy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcore.cljs
More file actions
80 lines (72 loc) · 3.3 KB
/
core.cljs
File metadata and controls
80 lines (72 loc) · 3.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
(ns status-im.android.core
(:require [reagent.core :as reagent]
[re-frame.core :refer [subscribe dispatch dispatch-sync]]
status-im.utils.db
status-im.ui.screens.db
status-im.ui.screens.events
status-im.ui.screens.subs
status-im.data-store.core
[status-im.ui.screens.views :as views]
[status-im.ui.components.react :as react]
[status-im.native-module.core :as status]
[status-im.utils.notifications :as notifications]
[status-im.core :as core]
[status-im.utils.snoopy :as snoopy]))
(defn init-back-button-handler! []
(let [new-listener (fn []
;; todo: it might be better always return false from
;; this listener and handle application's closing
;; in handlers
(let [stack (subscribe [:get :navigation-stack])
result-box (subscribe [:get-current-chat-ui-prop :result-box])
webview (subscribe [:get :webview-bridge])
view-id (subscribe [:get :view-id])
chat-id (subscribe [:get-current-chat-id])]
(cond
(and @webview (:can-go-back? @result-box))
(do (.goBack @webview) true)
(#{:home :wallet :my-profile} view-id)
(do (.exitApp react/back-handler))
(< 1 (count @stack))
(do (dispatch [:navigate-back]) true)
:else false)))]
(.addEventListener react/back-handler "hardwareBackPress" new-listener)))
(defn app-state-change-handler [state]
(dispatch [:app-state-change state]))
(defn app-root []
(let [keyboard-height (subscribe [:get :keyboard-height])]
(reagent/create-class
{:component-will-mount
(fn []
(.addListener react/keyboard
"keyboardDidShow"
(fn [e]
(let [h (.. e -endCoordinates -height)]
(dispatch [:hide-tab-bar])
(when-not (= h @keyboard-height)
(dispatch [:set :keyboard-height h])
(dispatch [:set :keyboard-max-height h])))))
(.addListener react/keyboard
"keyboardDidHide"
(fn [_]
(dispatch [:show-tab-bar])
(when (zero? @keyboard-height)
(dispatch [:set :keyboard-height 0]))))
(.hide react/splash-screen)
(.addEventListener react/app-state "change" app-state-change-handler))
:component-did-mount
(fn []
(notifications/on-refresh-fcm-token)
;; TODO(oskarth): Background click_action handler
(notifications/on-notification))
:component-will-unmount
(fn []
(.stop react/http-bridge)
(.removeEventListener react/app-state "change" app-state-change-handler))
:display-name "root"
:reagent-render views/main})))
(defn init []
(status/set-soft-input-mode status/adjust-resize)
(init-back-button-handler!)
(core/init app-root)
(snoopy/subscribe!))