2016-05-19 18:31:56 +02:00
|
|
|
(ns status-im.ios.core
|
2016-03-23 16:48:26 +02:00
|
|
|
(:require [reagent.core :as r :refer [atom]]
|
2016-07-22 11:53:12 +03:00
|
|
|
[re-frame.core :refer [subscribe dispatch dispatch-sync]]
|
|
|
|
[status-im.handlers]
|
|
|
|
[status-im.subs]
|
2016-10-20 16:51:37 +03:00
|
|
|
[status-im.components.react :refer [view
|
|
|
|
modal
|
|
|
|
app-registry
|
2016-07-22 11:53:12 +03:00
|
|
|
keyboard
|
2016-11-15 13:43:48 +02:00
|
|
|
orientation
|
|
|
|
splash-screen]]
|
2016-07-22 11:53:12 +03:00
|
|
|
[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]]
|
2016-11-23 00:07:33 +08:00
|
|
|
[status-im.discover.search-results :refer [discover-search-results]]
|
2016-07-22 11:53:12 +03:00
|
|
|
[status-im.chat.screen :refer [chat]]
|
|
|
|
[status-im.accounts.login.screen :refer [login]]
|
2016-11-29 11:56:56 +02:00
|
|
|
[status-im.accounts.recover.screen :refer [recover]]
|
2016-07-22 11:53:12 +03:00
|
|
|
[status-im.accounts.screen :refer [accounts]]
|
2016-10-11 17:24:52 +03:00
|
|
|
[status-im.transactions.screen :refer [confirm]]
|
2016-07-22 11:53:12 +03:00
|
|
|
[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]]
|
2016-08-01 13:29:10 +03:00
|
|
|
[status-im.profile.photo-capture.screen :refer [profile-photo-capture]]
|
2016-10-04 14:49:59 +03:00
|
|
|
status-im.data-store.core
|
2016-10-20 16:51:37 +03:00
|
|
|
[taoensso.timbre :as log]
|
|
|
|
[status-im.chat.styles.screen :as st]
|
2016-12-08 11:55:21 +02:00
|
|
|
[status-im.accounts.views.qr-code :refer [qr-code-view]]
|
|
|
|
[status-im.components.status :as status]))
|
2016-03-23 16:48:26 +02:00
|
|
|
|
2016-07-22 11:53:12 +03:00
|
|
|
(defn orientation->keyword [o]
|
|
|
|
(keyword (.toLowerCase o)))
|
2016-03-23 16:48:26 +02:00
|
|
|
|
2016-10-17 14:51:33 +03:00
|
|
|
(defn validate-current-view
|
|
|
|
[current-view signed-up?]
|
|
|
|
(if (or (contains? #{:login :chat :recover :accounts} current-view)
|
|
|
|
signed-up?)
|
|
|
|
current-view
|
|
|
|
:chat))
|
|
|
|
|
2016-03-23 16:48:26 +02:00
|
|
|
(defn app-root []
|
2016-10-17 14:51:33 +03:00
|
|
|
(let [signed-up? (subscribe [:signed-up?])
|
2016-10-20 16:51:37 +03:00
|
|
|
modal-view (subscribe [:get :modal])
|
2016-07-22 11:53:12 +03:00
|
|
|
view-id (subscribe [:get :view-id])
|
2016-08-01 13:29:10 +03:00
|
|
|
account-id (subscribe [:get :current-account-id])
|
2016-07-22 11:53:12 +03:00
|
|
|
keyboard-height (subscribe [:get :keyboard-height])]
|
2016-08-01 13:29:10 +03:00
|
|
|
(log/debug "Current account: " @account-id)
|
2016-07-22 11:53:12 +03:00
|
|
|
(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
|
2016-09-16 18:30:19 +03:00
|
|
|
"keyboardWillShow"
|
2016-07-22 11:53:12 +03:00
|
|
|
(fn [e]
|
|
|
|
(let [h (.. e -endCoordinates -height)]
|
|
|
|
(when-not (= h @keyboard-height)
|
|
|
|
(dispatch [:set :keyboard-height h])))))
|
|
|
|
(.addListener keyboard
|
2016-09-16 18:30:19 +03:00
|
|
|
"keyboardWillHide"
|
2016-11-09 12:40:17 +02:00
|
|
|
#(when-not (= 0 @keyboard-height)
|
|
|
|
(dispatch [:set :keyboard-height 0])))
|
2016-11-15 13:43:48 +02:00
|
|
|
(.hide splash-screen))
|
2016-07-22 11:53:12 +03:00
|
|
|
:render
|
|
|
|
(fn []
|
2016-10-17 14:51:33 +03:00
|
|
|
(when @view-id
|
|
|
|
(let [current-view (validate-current-view @view-id @signed-up?)]
|
|
|
|
(let [component (case current-view
|
2016-11-23 00:07:33 +08:00
|
|
|
:discover main-tabs
|
|
|
|
:discover-search-results discover-search-results
|
2016-10-17 14:51:33 +03:00
|
|
|
: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
|
2016-11-29 11:56:56 +02:00
|
|
|
:recover recover
|
2016-10-17 14:51:33 +03:00
|
|
|
:my-profile my-profile)]
|
2016-10-20 16:51:37 +03:00
|
|
|
[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
|
2016-11-17 15:02:55 +03:00
|
|
|
:qr-code-view qr-code-view
|
2016-10-20 16:51:37 +03:00
|
|
|
:confirm confirm
|
|
|
|
:contact-list-modal contact-list)]
|
|
|
|
[component])]])]))))})))
|
2016-03-23 16:48:26 +02:00
|
|
|
|
|
|
|
(defn init []
|
2016-12-08 11:55:21 +02:00
|
|
|
(status/call-module status/init-jail)
|
2016-07-22 11:53:12 +03:00
|
|
|
(dispatch-sync [:reset-app])
|
2016-11-30 19:44:39 +02:00
|
|
|
(dispatch [:listen-to-network-status!])
|
2016-07-22 11:53:12 +03:00
|
|
|
(dispatch [:initialize-crypt])
|
|
|
|
(dispatch [:initialize-geth])
|
|
|
|
(dispatch [:load-user-phone-number])
|
|
|
|
(.registerComponent app-registry "StatusIm" #(r/reactify-component app-root)))
|