From 59cf02194b0f3b06384c86bd8e528edcc1aa2e15 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Sun, 29 May 2016 10:30:46 +0300 Subject: [PATCH] js/window Former-commit-id: 043d28c44d8c62496627e39fd0cb21d4a70fb27e --- src/status_im/android/core.cljs | 3 +- .../components/carousel/carousel.cljs | 5 ++- src/status_im/components/drawer/view.cljs | 5 ++- .../components/invertible_scroll_view.cljs | 5 ++- src/status_im/components/react.cljs | 45 ++++++++++--------- src/status_im/discovery/views/popular.cljs | 6 +-- src/status_im/persistence/realm.cljs | 6 +-- 7 files changed, 41 insertions(+), 34 deletions(-) diff --git a/src/status_im/android/core.cljs b/src/status_im/android/core.cljs index 080a91fa54..cf3c7d48e1 100644 --- a/src/status_im/android/core.cljs +++ b/src/status_im/android/core.cljs @@ -60,4 +60,5 @@ (dispatch [:init-console-chat]) (dispatch [:init-chat]) (init-back-button-handler!) - (.registerComponent app-registry "StatusIm" #(r/reactify-component app-root))) + ;(.registerComponent app-registry "StatusIm" #(r/reactify-component app-root)) + ) diff --git a/src/status_im/components/carousel/carousel.cljs b/src/status_im/components/carousel/carousel.cljs index c3181df6ce..8c61cb114e 100644 --- a/src/status_im/components/carousel/carousel.cljs +++ b/src/status_im/components/carousel/carousel.cljs @@ -5,11 +5,12 @@ touchable-without-feedback text]] [status-im.components.carousel.styles :as st] - [status-im.utils.logging :as log])) + [status-im.utils.logging :as log] + [status-im.components.react :as r])) (defn window-page-width [] - (.-width (.get (.. js/React -Dimensions) "window"))) + (.-width (.get (.. r/react -Dimensions) "window"))) (def defaults {:gap 10 :sneak 10 diff --git a/src/status_im/components/drawer/view.cljs b/src/status_im/components/drawer/view.cljs index 1cd4ae43e8..0ac23a7dbb 100644 --- a/src/status_im/components/drawer/view.cljs +++ b/src/status_im/components/drawer/view.cljs @@ -12,7 +12,8 @@ touchable-opacity]] [status-im.resources :as res] [status-im.components.drawer.styles :as st] - [status-im.i18n :refer [label]])) + [status-im.i18n :refer [label]] + [status-im.components.react :refer [react]])) (defonce drawer-atom (atom)) @@ -72,7 +73,7 @@ (defn drawer-view [items] [drawer-layout-android {:drawerWidth 260 - :drawerPosition js/React.DrawerLayoutAndroid.positions.Left + :drawerPosition react.DrawerLayoutAndroid.positions.Left :render-navigation-view #(r/as-element [drawer-menu]) :ref (fn [drawer] (reset! drawer-atom drawer))} diff --git a/src/status_im/components/invertible_scroll_view.cljs b/src/status_im/components/invertible_scroll_view.cljs index ba4a1d546a..429d66d6ed 100644 --- a/src/status_im/components/invertible_scroll_view.cljs +++ b/src/status_im/components/invertible_scroll_view.cljs @@ -1,7 +1,8 @@ -(ns status-im.components.invertible-scroll-view) +(ns status-im.components.invertible-scroll-view + (:require [reagent.core :as r])) (def class (js/require "react-native-invertible-scroll-view")) (defn invertible-scroll-view [props] - (js/React.createElement class (clj->js (merge {:inverted true} props)))) + (r/create-element class (clj->js (merge {:inverted true} props)))) diff --git a/src/status_im/components/react.cljs b/src/status_im/components/react.cljs index 930f6deedf..d79d7d4fa9 100644 --- a/src/status_im/components/react.cljs +++ b/src/status_im/components/react.cljs @@ -2,25 +2,28 @@ (:require [reagent.core :as r] [status-im.components.styles :as st])) -(set! js/window.React (js/require "react-native")) +(when (exists? js/window) + (set! js/window.React (js/require "react-native"))) -(def app-registry (.-AppRegistry js/React)) -(def navigator (r/adapt-react-class (.-Navigator js/React))) -(def text (r/adapt-react-class (.-Text js/React))) -(def view (r/adapt-react-class (.-View js/React))) -(def image (r/adapt-react-class (.-Image js/React))) -(def touchable-highlight-class (r/adapt-react-class (.-TouchableHighlight js/React))) +(def react (js/require "react-native")) + +(def app-registry (.-AppRegistry react)) +(def navigator (r/adapt-react-class (.-Navigator react))) +(def text (r/adapt-react-class (.-Text react))) +(def view (r/adapt-react-class (.-View react))) +(def image (r/adapt-react-class (.-Image react))) +(def touchable-highlight-class (r/adapt-react-class (.-TouchableHighlight react))) (defn touchable-highlight [props content] [touchable-highlight-class (merge {:underlay-color :transparent} props) content]) -(def toolbar-android (r/adapt-react-class (.-ToolbarAndroid js/React))) -(def list-view-class (r/adapt-react-class (.-ListView js/React))) +(def toolbar-android (r/adapt-react-class (.-ToolbarAndroid react))) +(def list-view-class (r/adapt-react-class (.-ListView react))) (defn list-view [props] [list-view-class (merge {:enableEmptySections true} props)]) -(def scroll-view (r/adapt-react-class (.-ScrollView js/React))) -(def touchable-without-feedback (r/adapt-react-class (.-TouchableWithoutFeedback js/React))) -(def text-input-class (r/adapt-react-class (.-TextInput js/React))) +(def scroll-view (r/adapt-react-class (.-ScrollView react))) +(def touchable-without-feedback (r/adapt-react-class (.-TouchableWithoutFeedback react))) +(def text-input-class (r/adapt-react-class (.-TextInput react))) (defn text-input [props text] [text-input-class (merge {:underlineColorAndroid :transparent @@ -28,11 +31,11 @@ :placeholder "Type"} props) text]) -(def drawer-layout-android (r/adapt-react-class (.-DrawerLayoutAndroid js/React))) -(def touchable-opacity (r/adapt-react-class (.-TouchableOpacity js/React))) -(def modal (r/adapt-react-class (.-Modal js/React))) -(def picker (r/adapt-react-class (.-Picker js/React))) -(def picker-item (r/adapt-react-class (.-Item (.-Picker js/React)))) +(def drawer-layout-android (r/adapt-react-class (.-DrawerLayoutAndroid react))) +(def touchable-opacity (r/adapt-react-class (.-TouchableOpacity react))) +(def modal (r/adapt-react-class (.-Modal react))) +(def picker (r/adapt-react-class (.-Picker react))) +(def picker-item (r/adapt-react-class (.-Item (.-Picker react)))) (defn icon @@ -44,13 +47,13 @@ ;(def react-linear-gradient (.-default (js/require "react-native-linear-gradient"))) ;(def linear-gradient (r/adapt-react-class react-linear-gradient)) -(set! js/window.LinearGradient (js/require "react-native-linear-gradient")) +(def linear-gradient-class (js/require "react-native-linear-gradient")) (defn linear-gradient [props] - (js/React.createElement js/LinearGradient - (clj->js (merge {:inverted true} props)))) + (r/creacteElement linear-gradient-class + (clj->js (merge {:inverted true} props)))) -(def platform (.. js/React -Platform -OS)) +(def platform (.. react -Platform -OS)) (def android? (= platform "android")) diff --git a/src/status_im/discovery/views/popular.cljs b/src/status_im/discovery/views/popular.cljs index 9fbeb4f9fb..b91b233603 100644 --- a/src/status_im/discovery/views/popular.cljs +++ b/src/status_im/discovery/views/popular.cljs @@ -2,16 +2,16 @@ (:require-macros [status-im.utils.views :refer [defview]]) (:require [re-frame.core :refer [subscribe]] - [status-im.utils.logging :as log] [status-im.components.react :refer [android? text]] [status-im.components.carousel.carousel :refer [carousel]] [status-im.discovery.styles :as st] [status-im.discovery.views.popular-list :refer [discovery-popular-list]] - [status-im.i18n :refer [label]])) + [status-im.i18n :refer [label]] + [status-im.components.react :as r])) (defn page-width [] - (.-width (.get (.. js/React -Dimensions) "window"))) + (.-width (.get (.. r/react -Dimensions) "window"))) (defview popular [] [popular-tags [:get-popular-tags 3]] diff --git a/src/status_im/persistence/realm.cljs b/src/status_im/persistence/realm.cljs index a7d564f143..7056c11e9d 100644 --- a/src/status_im/persistence/realm.cljs +++ b/src/status_im/persistence/realm.cljs @@ -5,8 +5,6 @@ [status-im.utils.types :refer [to-string]]) (:refer-clojure :exclude [exists?])) -(set! js/window.Realm (js/require "realm")) - (def opts {:schema [{:name :contacts :primaryKey :whisper-identity :properties {:phone-number {:type "string" @@ -70,7 +68,9 @@ :objectType "tag"} :last-updated "date"}}]}) -(def realm (js/Realm. (clj->js opts))) +(def realm-class (js/require "realm")) + +(def realm (realm-class. (clj->js opts))) (def schema-by-name (->> (:schema opts) (mapv (fn [{:keys [name] :as schema}]