Repository navigation
Expand file tree
/
Copy pathcore.cljs
More file actions
133 lines (128 loc) · 6.2 KB
/
Copy pathcore.cljs
File metadata and controls
133 lines (128 loc) · 6.2 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
(ns status-im.android.core
(:require-macros
[natal-shell.back-android :refer [add-event-listener remove-event-listener]])
(:require [reagent.core :as r :refer [atom]]
[re-frame.core :refer [subscribe dispatch dispatch-sync]]
[status-im.handlers]
[status-im.subs]
[status-im.components.react :refer [app-registry
keyboard
orientation
view
modal
splash-screen]]
[status-im.components.main-tabs :refer [main-tabs]]
[status-im.contacts.views.contact-list :refer [contact-list]]
[status-im.contacts.views.new-contact :refer [new-contact]]
[status-im.qr-scanner.screen :refer [qr-scanner]]
[status-im.discovery.search-results :refer [discovery-search-results]]
[status-im.chat.screen :refer [chat]]
[status-im.accounts.login.screen :refer [login]]
[status-im.accounts.recover.screen :refer [recover]]
[status-im.accounts.screen :refer [accounts]]
[status-im.transactions.screen :refer [confirm]]
[status-im.chats-list.screen :refer [chats-list]]
[status-im.new-group.screen :refer [new-group]]
[status-im.participants.views.add :refer [new-participants]]
[status-im.participants.views.remove :refer [remove-participants]]
[status-im.group-settings.screen :refer [group-settings]]
[status-im.profile.screen :refer [profile my-profile]]
[status-im.profile.photo-capture.screen :refer [profile-photo-capture]]
status-im.data-store.core
[taoensso.timbre :as log]
[status-im.components.status :as status]
[status-im.chat.styles.screen :as st]
[status-im.accounts.views.qr-code :refer [qr-code-view]]))
(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])]
(when (< 1 (count @stack))
(dispatch [:navigate-back])
true)))]
(add-event-listener "hardwareBackPress" new-listener)))
(defn orientation->keyword [o]
(keyword (.toLowerCase o)))
(defn validate-current-view
[current-view signed-up?]
(if (or (contains? #{:login :chat :recover :accounts} current-view)
signed-up?)
current-view
:chat))
(defn app-root []
(let [signed-up? (subscribe [:signed-up?])
view-id (subscribe [:get :view-id])
account-id (subscribe [:get :current-account-id])
keyboard-height (subscribe [:get :keyboard-height])
modal-view (subscribe [:get :modal])]
(log/debug "Current account: " @account-id)
(r/create-class
{:component-will-mount
(fn []
(let [o (orientation->keyword (.getInitialOrientation orientation))]
(dispatch [:set :orientation o]))
(.addOrientationListener
orientation
#(dispatch [:set :orientation (orientation->keyword %)]))
(.lockToPortrait orientation)
(.addListener keyboard
"keyboardDidShow"
(fn [e]
(let [h (.. e -endCoordinates -height)]
(when-not (= h @keyboard-height)
(dispatch [:set :keyboard-height h])))))
(.addListener keyboard
"keyboardDidHide"
#(when-not (= 0 @keyboard-height)
(dispatch [:set :keyboard-height 0])))
(.hide splash-screen))
:render
(fn []
(when @view-id
(let [current-view (validate-current-view @view-id @signed-up?)]
(let [component (case current-view
:discovery main-tabs
:discovery-search-results discovery-search-results
:add-participants new-participants
:remove-participants remove-participants
:chat-list main-tabs
:new-group new-group
:group-settings group-settings
:contact-list main-tabs
:group-contacts contact-list
:new-contact new-contact
:qr-scanner qr-scanner
:chat chat
:profile profile
:profile-photo-capture profile-photo-capture
:accounts accounts
:login login
:recover recover
:confirm confirm
:my-profile my-profile)]
[view
{:flex 1}
[component]
(when @modal-view
[view
st/chat-modal
[modal {:animation-type :slide
:transparent false
:on-request-close #(dispatch [:navigate-back])}
(let [component (case @modal-view
:qr-scanner qr-scanner
:qr-code-view qr-code-view
:confirm confirm
:contact-list-modal contact-list)]
[component])]])]))))})))
(defn init [& [env]]
(dispatch-sync [:reset-app])
(.registerComponent app-registry "StatusIm" #(r/reactify-component app-root))
(dispatch [:listen-to-network-status!])
(dispatch [:initialize-crypt])
(dispatch [:initialize-geth])
(status/set-soft-input-mode status/adjust-resize)
(dispatch [:load-user-phone-number])
(init-back-button-handler!))