Created
September 19, 2017 10:48
-
-
Save tiensonqin/8bf43569c528f7ce0dc6e066a1c68a1d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns spurs.core | |
(:require [re-natal.support :as support] | |
[rum.core :as rum :refer-macros [defc defcc defcs]] | |
[cljs-exponent.components :refer [text view element] :as rn] | |
[clojure.string :as str] | |
[clojure.walk :as w] | |
[clojure.set :refer [rename-keys]])) | |
(def ExNavigation (js/require "@expo/ex-navigation")) | |
(def create-router (aget ExNavigation "createRouter")) | |
(def NavigationProvider (aget ExNavigation "NavigationProvider")) | |
(def navigation-provider (partial element NavigationProvider)) | |
(def StackNavigation (aget ExNavigation "StackNavigation")) | |
(def stack-navigation (partial element StackNavigation)) | |
(when (exists? js/Symbol) | |
(extend-protocol IPrintWithWriter | |
js/Symbol | |
(-pr-writer [sym writer _] | |
(-write writer (str "\"" (.toString sym) "\""))))) | |
(defn ->react-comp | |
"Convert a rum component to a react component." | |
[rum-component] | |
(:rum/class (meta rum-component))) | |
(defn wrap-route | |
[rum-comp route-opts] | |
(let [react-comp (->react-comp rum-comp)] | |
(aset react-comp "route" (clj->js route-opts)) | |
react-comp)) | |
(defc home [] | |
(view {:style {:alignItems "center" :justifyContent "center" :flex 1}} | |
(text "Home Screen!"))) | |
(def Router (create-router | |
(fn [] | |
#js {:home #(wrap-route home {:navigationBar {:title "Coming Soon"}})}))) | |
(defc App [] | |
(navigation-provider {:router Router} | |
(stack-navigation {:initialRoute (.getRoute Router "home")}))) | |
(defonce root-component-factory (support/make-root-component-factory)) | |
(defn mount-app [] (support/mount (App))) | |
(defn init [] | |
(mount-app) | |
(.registerComponent rn/app-registry "main" (fn [] root-component-factory))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment