diff --git a/resources/core-android.cljs b/resources/core-android.cljs new file mode 100644 index 0000000..6cce09b --- /dev/null +++ b/resources/core-android.cljs @@ -0,0 +1,29 @@ +(ns $PROJECT_NAME_HYPHENATED$.android.core + (:require [reagent.core :as r :refer [atom]] + [re-frame.core :refer [subscribe dispatch dispatch-sync]] + [commutewise-app.handlers] + [commutewise-app.subs])) + +(set! js/React (js/require "react-native")) + +(def app-registry (.-AppRegistry 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 (r/adapt-react-class (.-TouchableHighlight js/React))) + +(defn widget [] + (let [greeting (subscribe [:get-greeting])] + (fn [] + [view {:style {:flexDirection "column" :margin 40 :alignItems "center"}} + [text {:style {:fontSize 30 :fontWeight "100" :marginBottom 20 :textAlign "center"}} @greeting] + [image {:source {:uri "https://raw.githubusercontent.com/cljsinfo/logo.cljs/master/cljs.png"} + :style {:width 80 :height 80 :marginBottom 30}}] + [touchable-highlight {:style {:backgroundColor "#999" :padding 10 :borderRadius 5}} + [text {:style {:color "white" :textAlign "center" :fontWeight "bold"}} "press me"]]]))) + + +(.registerRunnable app-registry "$PROJECT_NAME$" + (fn [params] + (dispatch-sync [:initialize-db]) + (r/render [widget] (.-rootTag params)))) diff --git a/resources/core-ios.cljs b/resources/core-ios.cljs new file mode 100644 index 0000000..bddf149 --- /dev/null +++ b/resources/core-ios.cljs @@ -0,0 +1,29 @@ +(ns $PROJECT_NAME_HYPHENATED$.ios.core + (:require [reagent.core :as r :refer [atom]] + [re-frame.core :refer [subscribe dispatch dispatch-sync]] + [commutewise-app.handlers] + [commutewise-app.subs])) + +(set! js/React (js/require "react-native")) + +(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 (r/adapt-react-class (.-TouchableHighlight js/React))) + +(defn widget [] + (let [greeting (subscribe [:get-greeting])] + (fn [] + [view {:style {:flexDirection "column" :margin 40 :alignItems "center"}} + [text {:style {:fontSize 30 :fontWeight "100" :marginBottom 20 :textAlign "center"}} @greeting] + [image {:source {:uri "https://raw.githubusercontent.com/cljsinfo/logo.cljs/master/cljs.png"} + :style {:width 80 :height 80 :marginBottom 30}}] + [touchable-highlight {:style {:backgroundColor "#999" :padding 10 :borderRadius 5}} + [text {:style {:color "white" :textAlign "center" :fontWeight "bold"}} "press me"]]]))) + +(r/render [widget] 1) + +(defn ^:export init [] + (dispatch-sync [:initialize-db]) + ((fn render [] + (.requestAnimationFrame js/window render)))) diff --git a/resources/handlers.cljs b/resources/handlers.cljs new file mode 100644 index 0000000..6573729 --- /dev/null +++ b/resources/handlers.cljs @@ -0,0 +1,15 @@ +(ns $PROJECT_NAME_HYPHENATED$.handlers + (:require + [re-frame.core :refer [register-handler path trim-v after dispatch]])) + +(def app-db {:greeting "Hello Clojure in iOS and Android!"}) + +(register-handler + :initialize-db + (fn [_ _] + app-db)) + +(register-handler + :set-greeting + (fn [db [_ value]] + (assoc db :greeting value))) \ No newline at end of file diff --git a/resources/subs.cljs b/resources/subs.cljs new file mode 100644 index 0000000..dc76928 --- /dev/null +++ b/resources/subs.cljs @@ -0,0 +1,9 @@ +(ns $PROJECT_NAME_HYPHENATED$.subs + (:require-macros [reagent.ratom :refer [reaction]]) + (:require [re-frame.core :refer [register-sub]])) + +(register-sub + :get-greeting + (fn [db _] + (reaction + (get @db :greeting)))) \ No newline at end of file