seantempesta / cljs-react-navigation Goto Github PK
View Code? Open in Web Editor NEWCLJS wrappers for react-navigation
License: MIT License
CLJS wrappers for react-navigation
License: MIT License
I've noticed that the DrawerNavigator
isn't properly wrapped like StackNavigator
.
Is there any special reason for not doing so? Is there anybody working on it as of today?
If not, I could happily add that. Would you be interested in it?
By the way, thanks for the library :)
I recently decided to instrument my entire project to check against possible errors. To my surprise, the project started to crash due to screen
fdef instrumentation.
After some checking I found out the problem: fdef screen
uses s/tuple
to define the arguments; tuple
however requires a vector but the arguments to a function are passed as a list which are not the same.
See this Clojure ticket for more information: https://dev.clojure.org/jira/browse/CLJ-2071
I think the correct way should be:
(s/fdef screen
:args (s/cat :component :react/component
:options :react-navigation/navigationOptions)
:ret #(ric/react-class? %))
I made sure to have the latest commits, switched to the uiexplorer folder, then I run re-natal use-figwheel && lein figwheel ios
in one terminal and react-native run-ios
in another. I wait for the application to appear then go to the search bar, click a few times on search. Then I change in the uiexplorer.routing
ns the “Modal Me!” button title to something else, and then the app re-renders but always displays the login scene and that’s it.
When upgrading react-navigation to 2.0, I'm getting a lot of "The StackNavigator
function name is deprecated, please use createStackNavigator instead", which is
fixed easily enough by something like this.
(src/clsjs_react_navigation/base.cljs)
;; Navigators
(defonce createNavigator (gobj/get ReactNavigation #js ["createNavigator"]))
-(defonce StackNavigator (gobj/get ReactNavigation #js ["StackNavigator"]))
+(defonce StackNavigator (gobj/get ReactNavigation #js ["createStackNavigator"]))
(defonce TabNavigator (gobj/get ReactNavigation #js ["TabNavigator"]))
+(defonce BottomTabNavigator (gobj/get ReactNavigation #js ["createBottomTabNavigator"]))
+(defonce MaterialTabNavigator (gobj/get ReactNavigation #js ["createMaterialTabNavigator"]))
-(defonce DrawerNavigator (gobj/get ReactNavigation #js ["DrawerNavigator"]))
-(defonce SwitchNavigator (gobj/get ReactNavigation #js ["SwitchNavigator"]))
+(defonce DrawerNavigator (gobj/get ReactNavigation #js ["createDrawerNavigator"]))
+(defonce SwitchNavigator (gobj/get ReactNavigation #js ["createSwitchNavigator"]))
;; Routers
-(defonce StackRouter (gobj/get ReactNavigation #js ["StackRouter"]))
-(defonce TabRouter (gobj/get ReactNavigation #js ["TabRouter"]))
+(defonce StackRouter (gobj/get ReactNavigation #js ["createStackRouter"]))
+(defonce TabRouter (gobj/get ReactNavigation #js ["createTabRouter"]))
TabNavigator
has actually been split into createBottomTabNavigator
and
createMaterialTopTabNavigator
, so it probably makes sense to add these as
seperate bindings.
TabView
has been moved to
https://github.com/react-navigation/react-navigation-tabs, which I guess makes
sense to require instead of having it be an optional dependency.
(defonce React (js/require "react"))
(defonce ReactNavigation (js/require "react-navigation"))
+(defonce ReactNavigationTabs (js/require "react-navigation-tabs"))
(defonce isValidElement (gobj/get React #js ["isValidElement"]))
;; Views
(defonce Transitioner (gobj/get ReactNavigation #js ["Transitioner"]))
(defonce CardStack (gobj/get ReactNavigation #js ["CardStack"]))
(defonce DrawerView (gobj/get ReactNavigation #js ["DrawerView"]))
-(defonce TabView (gobj/get ReactNavigation #js ["TabView"]))
+(defonce TabView (gobj/get ReactNavigationTabs #js ["TabView"]))
-(assert (and React ReactNavigation) "React and React Navigation must be installed. Maybe NPM install them and restart the packager?")
+(assert (and React ReactNavigation ReactNavigationTabs) "React, React Navigation and React Navigation Tabs must be installed. Maybe NPM install them and restart the packager?")
I'm not sure if there are any other changes required, I haven't actually tested
most of the functions, but it builds in my project without warnings (which only
uses StackNavigator
/StackRouter
). I can prepare a PR for that if you want me
to.
Hi, I have attached a gif and the relevant code for the same.
router.cljs
(ns my-app.router
(:require [my-app.screens :refer [sign-in-screen second-screen ]]
[cljs-react-navigation.re-frame :refer [stack-navigator
stack-screen]]))
(def MyStack (stack-navigator
{:sign-in
{:screen (stack-screen sign-in-screen
{:title "1"})}
:second
{:screen (stack-screen second-screen
{:headerTitle "2"})}}))
screens.cljs
(ns my-app.screens
(:require [reagent.core :as r :refer [atom]]
[re-frame.core :refer [subscribe dispatch dispatch-sync]]
[my-app.handlers]
[my-app.ui :refer [text view image text-input
dimensions gifted-chat alert
flat-list activity-indicator
touchable-highlight]]
[my-app.subs]))
(defn sign-in-screen [{:keys [navigation screenProps] :as props}]
(let [{:keys [navigate]} navigation
state (r/atom {:username ""})
get-text #(-> % .-nativeEvent .-text)
on-input-change (fn [value]
(swap! state assoc :username (get-text value)))
on-press (fn []
(navigate "second"))]
(fn [props]
[container
[view {:width "70%"
:flex-direction "column"
:align-items "center"}
[text-input {:style {:height 40
:width "100%"}
:placeholder "Enter username"
:borderWidth 1
:margin-bottom 20
:textAlign "center"
:value (:username @state)
:on-change on-input-change}]
[touchable-highlight {:on-press on-press}
[text "Go"]]]])))
(defn second-screen [{:keys [navigation] :as props}]
(fn [props]
[container [view [text "hello"]]]))
db.cljs
(ns my-app.db)
(defonce default-routes (clj->js {:index 0
:routes [{:key "1"
:routeName "sign-in"}
{:key "2"
:routeName "second"}]}))
;; initial state of app-db
(defonce app-db {:greeting "Hello Clojurescript in Expo!"
:routing default-routes})
this would avoid importing it when it is not needed.
The readme already specifies that the developer needs to include it so having it in this lib dependencies will most likely lead to conflicts.
In the following example of react navigation intro https://reactnavigation.org/docs/intro/, you can pass down the screen's props to navigationOptions
.
// Nav options can be defined as a function of the screen's props:
static navigationOptions = ({ navigation }) => ({
title: `Chat with ${navigation.state.params.user}`,
});
Is it supported yet in this CLJS wrappers for react-navigation? If yes, how do we do the same?
I think it's considered bad practice to use aget for objects. It works due to the generated javascript code but should be reserved for array access.
The alternative is goog.object/get.
Fix would be a search and replace for aget in the base ns, replacing with gobj/get.
Note: I'm no expert on the matter.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.