Skip to content
This repository was archived by the owner on Oct 2, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
db8929a
bumped dependency versions
MikaelCarpenter Jul 31, 2015
27ee26a
allows passing of props as well as an update to README to document th…
MikaelCarpenter Jul 31, 2015
402987a
added fixed width and handling for long titles
MikaelCarpenter Aug 18, 2015
987126a
Update package.json
MikaelCarpenter Aug 31, 2015
2409ebd
Update index.js
MikaelCarpenter Aug 31, 2015
53e76d0
Update NavBarContent.js
MikaelCarpenter Aug 31, 2015
4d44ef7
Update README.md
MikaelCarpenter Sep 2, 2015
4242d0c
added 'trans' after talking to @rwoverdijk
Sep 2, 2015
1b71608
touchups for the trans property
Sep 2, 2015
28a3009
Update package.json
MikaelCarpenter Sep 2, 2015
3550f6c
added right/left corner props
Sep 3, 2015
014e76c
Merge branch 'master' of https://github.com/MikaelCarpenter/gb-native…
Sep 3, 2015
1c7f0ef
README
Sep 3, 2015
1903c28
adding setRightProps and setLeftProps so you can talk to your navbar …
Sep 4, 2015
ba2cf5e
Update README.md
MikaelCarpenter Sep 4, 2015
1632c68
Update README.md
MikaelCarpenter Sep 4, 2015
130500f
Update README.md
MikaelCarpenter Sep 4, 2015
62af97b
added replaceRoute() to be used instead of toRoute() for certain cases
Sep 8, 2015
df59f0d
Merge pull request #2 from MikaelCarpenter/replaceRoute
MikaelCarpenter Sep 8, 2015
8db9c05
Update README.md
MikaelCarpenter Sep 8, 2015
31f22d2
quick fix for dynamically adding border to nav
MikaelCarpenter Sep 11, 2015
208401d
Merge pull request #3 from MikaelCarpenter/borderQuickFix
MikaelCarpenter Sep 11, 2015
1d56cc0
added proper margin if hiding nav bar
Sep 11, 2015
1fcefe8
Merge pull request #6 from MikaelCarpenter/fix/hideNavBar
MikaelCarpenter Sep 11, 2015
1212c1d
added noStatusBar to <Router />
Sep 11, 2015
974f6fe
Merge pull request #7 from MikaelCarpenter/fix/noStatusBar
MikaelCarpenter Sep 11, 2015
4c5c232
getting ready for publish
Sep 11, 2015
0a09e39
updating example image
Sep 11, 2015
d54bfce
making Android compatible for react-native 0.11.0
Sep 16, 2015
348fc98
0.4.2
Sep 16, 2015
02e1f01
require Platform
Sep 16, 2015
9239e1b
fix for long titles
MikaelCarpenter Sep 30, 2015
40c5fba
Merge pull request #13 from MikaelCarpenter/longTitles
MikaelCarpenter Sep 30, 2015
0bf0c2b
Add replaceRoute method
webwelten Oct 13, 2015
1ae3bb0
Merge pull request #14 from webwelten/patch-1
MikaelCarpenter Oct 13, 2015
4bcb083
React-native version up to 0.12.0
Olegas Oct 24, 2015
7e0aaf8
added setTitleProps to send props to custom components
Oct 24, 2015
0ced1e2
Merge pull request #19 from Olegas/react-version-up
MikaelCarpenter Oct 24, 2015
5661e79
Merge pull request #20 from davodesign84/titleProps
MikaelCarpenter Oct 24, 2015
61ee668
Made animations coherent as per iOS spec. Went from Tweening to Anima…
AlexGustafsson Oct 28, 2015
4712743
Corrected error when initializing new animated value
AlexGustafsson Oct 28, 2015
7df1ef0
Edited animation duration to depict iOS and not dev animations
AlexGustafsson Oct 28, 2015
829c05d
Removed react-tween-state from dependencies
AlexGustafsson Oct 28, 2015
d66de28
Merge pull request #21 from AlexGustafsson/coherent-animation
MikaelCarpenter Oct 28, 2015
051a8de
Merge branch 'MikaelCarpenter/master'
AlexGustafsson Nov 5, 2015
acdc02a
Exposed scene config to route
AlexGustafsson Nov 5, 2015
7460b95
Added sceneConfig to documentation. Consistent letter-casing
AlexGustafsson Nov 6, 2015
d275c30
Merge pull request #24 from AlexGustafsson/exposed-sceneConfig
MikaelCarpenter Nov 6, 2015
b1ccf09
Removed unecessary gesture handler
AlexGustafsson Nov 6, 2015
b32fc76
Merge pull request #26 from AlexGustafsson/navigator-gesture-cleanup
MikaelCarpenter Nov 6, 2015
5b325f9
Adding resetToRoute API
davidLeonardi Nov 15, 2015
553c44e
Update index.js
davidLeonardi Nov 15, 2015
61fa3c4
Merge pull request #2 from sethx/sethx-patch-1
davidLeonardi Nov 15, 2015
74a5a20
React-native dependency version bump
davidLeonardi Nov 15, 2015
67731de
Merge pull request #28 from sethx/patch-1
MikaelCarpenter Nov 15, 2015
1d234e5
Update README.md
davidLeonardi Nov 15, 2015
6dbde9f
Update index.js
davidLeonardi Nov 16, 2015
584f8b5
Merge pull request #27 from sethx/resetToRoute
MikaelCarpenter Nov 17, 2015
0c9d26c
Merge pull request #29 from sethx/patch-2
MikaelCarpenter Nov 17, 2015
4e99be8
Update index.js
davidLeonardi Nov 17, 2015
fc7bd48
Update NavBarContainer.js
davidLeonardi Nov 17, 2015
7dc146f
Update NavBarContent.js
davidLeonardi Nov 17, 2015
1a36141
Update NavButton.js
davidLeonardi Nov 17, 2015
c331057
Update README.md
davidLeonardi Nov 17, 2015
9b3845c
Merge pull request #33 from sethx/patch-5
MikaelCarpenter Nov 17, 2015
b80354d
Merge pull request #35 from sethx/patch-7
MikaelCarpenter Nov 17, 2015
f5a92b6
Merge pull request #36 from sethx/patch-8
MikaelCarpenter Nov 17, 2015
d83f25d
Merge pull request #37 from sethx/patch-9
MikaelCarpenter Nov 17, 2015
1424722
Update NavBarContainer.js
davidLeonardi Nov 17, 2015
a1db68f
Update NavBarContainer.js
davidLeonardi Nov 17, 2015
dbf6e03
Merge pull request #34 from sethx/patch-6
MikaelCarpenter Nov 17, 2015
f9d773c
0.5.0
MikaelCarpenter Nov 19, 2015
3af3be4
adding lost code.. :(
davidLeonardi Nov 23, 2015
4c4b601
Update index.js
davidLeonardi Nov 23, 2015
38e7dac
Switching to facebook emitter
davidLeonardi Nov 29, 2015
ef22e0e
Add RC versions to RN dependencies
davidLeonardi Nov 29, 2015
2cf7fbf
Merge pull request #40 from sethx/patch-10
MikaelCarpenter Dec 7, 2015
4f5d394
Merge pull request #45 from sethx/patch-13
MikaelCarpenter Dec 7, 2015
01760b4
Merge pull request #43 from sethx/patch-11
MikaelCarpenter Dec 7, 2015
1404635
adding fbemitter to peer dependencies
MikaelCarpenter Dec 7, 2015
40daf49
0.6.0
MikaelCarpenter Dec 7, 2015
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2015 Tristan Edwards
Copyright (c) 2015 Mikael Carpenter

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
93 changes: 61 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
React Native Router
GB Native Router
===================

Awesome navigation for your React Native app.

![Twitter navigation](http://tristanedwards.me/u/react-native-router/native-router.gif)
![NavBar Example](http://i.imgur.com/h5jUDC8.png)

Install
-------

Make sure that you are in your React Native project directory and run:

```npm install react-native-router --save```

```$ npm install gb-native-router --save```

Usage
-----

```javascript
var Router = require('react-native-router');
var Router = require('gb-native-router');
```

The basics:
Expand Down Expand Up @@ -75,53 +77,80 @@ var HelloPage = React.createClass({

Now, when you click on "Next page please!", it will go to the next page (which in this case is still HelloPage but with a new title). Keep in mind that ```this.props.toRoute()``` needs to be called from one of the top-level routes, therefore, if your link is deeply nested within multiple components, you need to make sure that the action "bubbles up" until it reaches the parent route, which in turn calls ```this.props.toRoute()```.


A more advanced example: Twitter app
------------------------------------

To see more of the router in action, you can check out the Twitter example app that comes with the package. Just make sure that you first drag all the images from ```node_modules/react-native-router/twitter-example/images``` to your project's Images.xcassets:

![Drag the assets to xcassets](http://tristanedwards.me/u/react-native-router/drag-assets.gif)

After that, don't forget to rebuild the app in XCode before you launch the simulator. Then test the app by requiring the TwitterApp component:

```javascript
var TwitterApp = require('./node_modules/react-native-router/twitter-example');

var {
AppRegistry
} = React;

AppRegistry.registerComponent('routerTest', () => TwitterApp);
```

Configurations
--------------

The **`<Router \>`** object used to initialize the navigation can take the following props:
- `firstRoute` (required): A React class corresponding to the first page of your navigation
- `headerStyle`: Apply a StyleSheet to the navigation bar. You'll probably want to change the backgroundColor for example.
- `titleStyle`: Apply a StyleSheet to the navigation bar titles. Useful for changing the font or text color.
- `borderBottomWidth`: Apply a bottom border to your navbar.
- `borderColor`: Apply a border color to your bottom border.
- `backButtonComponent`: By default, the navigation bar will display a simple "Back" text for the back button. To change this, you can specify your own backButton component (like in the Twitter app).
- `rightCorner`: If you have the same occuring action buttons on the right side of your navigation bar (like the Twitter "Compose"-button), you can specify a component for that view.
- `customAction`: A special callback prop for your action buttons (this can be handy for triggering a side menu for example). The action gets triggered from your custom `leftCorner` or `rightCorner` components by calling `this.props.customAction("someActionName")` from them. It is then picked up like this: `<Router customAction={this.doSomething} />`.
- `hideNavigationBar`: Hide the navigation bar, always

The **`this.props.toRoute()`** callback prop takes one parameter (a JavaScript object) which can have the following keys:
- `name`: The name of your route, which will be shown as the title of the navigation bar unless it is changed.
- `component` (required): The React class corresponding to the view you want to render.
- `leftCorner`: Specify a component to render on the left side of the navigation bar (like the "Add people"-button on the first page of the Twitter app)
- `rightCorner`: Specify a component to render on the right side of the navigation bar
- `titleComponent`: Specify a component to replace the title. This could for example be your logo (as in the first page of the Instagram app)
- `headerStyle`: change the style of your header for the new route. You could for example specify a new backgroundColor and the router will automatically make a nice transition from one color to the other!
- `data`: Send custom data to your route.
- `headerStyle`: Change the style of your header for the new route. You could for example specify a new backgroundColor and the router will automatically make a nice transition from one color to the other!
- `passProps`: Takes in an object. Passes each `key: value` pair to your component as a prop. i.e. <Component key={value} />
- `trans`: If set to a truthy value it will make the navbar transparent and move your component content so that it sits behind the nav.
- `hideNavigationBar`: If set to a truthy value will hide the navigationbar out of view, and move the component so that it is at the top of the screen.
- `leftCornerProps`: If you set a `leftCorner` component you can use this property to pass props to that component.
- `rightCornerProps`: If you set a `rightCorner` component you can use this property to pass props to that component.
- `sceneConfig`: Control the animation of the route being switched. Possible values are:
- Navigator.SceneConfigs.FadeAndroid
- Navigator.SceneConfigs.FloatFromBottom
- Navigator.SceneConfigs.FloatFromBottomAndroid
- Navigator.SceneConfigs.FloatFromLeft
- Navigator.SceneConfigs.FloatFromRight
- Navigator.SceneConfigs.HorizontalSwipeJump
- Navigator.SceneConfigs.PushFromRight
- Navigator.SceneConfigs.VerticalDownSwipeJump
- Navigator.SceneConfigs.VerticalUpSwipeJump

The **`this.props.replaceRoute`** takes in an object that can contain the same keys as `toRoute()`. The difference is that instead of adding a route to your stack, it replaces the route
that you're on with the new route that you pass it.
- This is useful for login or signup screens. If you don't want your user to be able to navigate back to it, then use `replaceRoute()` rather than `toRoute()`.

The **`this.props.resetToRoute`** takes in an object that can contain the same keys as `toRoute()`. The difference is that instead of adding a route to your stack, it replaces the route
that you're on with the new route that you pass it, and empties the navigation stack as well.
- This is useful for going to an application after a login or signup screens. If you don't want your user to be able to navigate back to it, then use `resetToRoute()` rather than `replaceRoute()`.

The **`this.props.setRightProps`** and **`this.props.setLeftProps`** take in an object of props and sends that to your navbar's `RightComponent` and `LeftComponent`.
- This allows you to talk directly to your navbar, because previously you could only talk to it when navigating forward or backward.


Events emitted by the router:
`didFocus`, emits route name
You can add a listener to a component as such:

```javascript
this.props.routeEmitter.addListener('didFocus', (name) => {
//Check if name is the current component, and if it is, act on this focus event.
});
```

Todos
-----
When swiping from left to right to go back, it would be nice if the navigation bar's opacity gradually changed with the user's finger position. (See [Issue #1](https://github.com/t4t5/react-native-router/issues/1))

Questions?
---------

If something is unclear or if you just want to say hi, feel free to [follow me on Twitter](https://twitter.com/t4t5)!
A more advanced example: Twitter app
------------------------------------

To see more of the router in action, you can check out the Twitter example app that comes with the package. Just make sure that you first drag all the images from ```node_modules/react-native-router/twitter-example/images``` to your project's Images.xcassets

After that, don't forget to rebuild the app in XCode before you launch the simulator. Then test the app by requiring the TwitterApp component:

```javascript
var TwitterApp = require('./node_modules/react-native-router/twitter-example');

var {
AppRegistry
} = React;

AppRegistry.registerComponent('routerTest', () => TwitterApp);
```
81 changes: 65 additions & 16 deletions components/NavBarContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ var {
View
} = React;


var NavBarContainer = React.createClass({

getInitialState: function() {
Expand Down Expand Up @@ -41,40 +40,90 @@ var NavBarContainer = React.createClass({

// We render both the current and the previous navbar (for animation)
render: function() {
return (
<View style={[styles.navbarContainer, this.props.style]}>
<NavBarContent
route={this.state.previousRoute}
var trans,
navbarStyle,
navbarContent;

if (this.props.currentRoute.trans) {
trans = {backgroundColor: 'transparent'};
} else {
trans = {};
}

if (this.props.currentRoute.hideNavigationBar) {
navbarStyle = styles.navbarContainerHidden;
} else {
navbarStyle = styles.navbarContainer;
}

if(this.props.currentRoute.trans) {
navbarContent = (
<NavBarContent
route={this.state.previousRoute}
backButtonComponent={this.props.backButtonComponent}
rightCorner={this.props.rightCorner}
titleStyle={this.props.titleStyle}
willDisappear="true"></NavBarContent>
);
} else if (this.props.currentRoute.hideNavigationBar) {
navbarContent = (
<NavBarContent
route={this.props.currentRoute}
backButtonComponent={this.props.backButtonComponent}
rightCorner={this.props.rightCorner}
titleStyle={this.props.titleStyle}
willDisappear="true"
/>
<NavBarContent
route={this.props.currentRoute}
borderBottomWidth={this.props.borderBottomWidth}
borderColor={this.props.borderColor}
goBack={this.goBack}
goForward={this.goForward}
leftProps={this.props.leftProps}
rightProps={this.props.rightProps}
titleProps={this.props.titleProps}
customAction={this.customAction}>
</NavBarContent>
);
} else {
navbarContent = (
<NavBarContent
route={this.props.currentRoute}
backButtonComponent={this.props.backButtonComponent}
rightCorner={this.props.rightCorner}
titleStyle={this.props.titleStyle}
borderBottomWidth={this.props.borderBottomWidth}
borderColor={this.props.borderColor}
goBack={this.goBack}
goForward={this.goForward}
customAction={this.customAction}
/>
leftProps={this.props.leftProps}
rightProps={this.props.rightProps}
titleProps={this.props.titleProps}
customAction={this.customAction}>
</NavBarContent>
);
}

return (
<View style={[navbarStyle, this.props.style, trans]}>
{navbarContent}
</View>
)
);
}
});


var styles = StyleSheet.create({
navbarContainer: {
position: 'absolute',
top: 0,
left: 0,
right: 0,
height: 64,
backgroundColor: '#5589B7'
height: 64
},
navbarContainerHidden: {
position: 'absolute',
top: -64,
left: 0,
right: 0,
height: 64
}
});


module.exports = NavBarContainer;
Loading