Skip to content

Commit

Permalink
Merge branch 'master' into multi-transitions
Browse files Browse the repository at this point in the history
* master:
  Docs: Update md links from coodoo's fork to react-community (react-navigation#750)
  Navigation Actions Doc (react-navigation#338)
  Update documentation regarding `DrawerNavigator` customisation (react-navigation#646)
  Fix flow in Navigation Playground (react-navigation#735)
  Adds documentation about forking and syncing repo (react-navigation#765)
  fix(docs): Fix incorrect style in TabNavigator sample (react-navigation#734)
  correction of a few documentation typo (react-navigation#563)
  Fix typo in docs for getComponentForRouteName (react-navigation#714)
  Drawer sidebar description (react-navigation#617)
  Remove 2nd return statement (react-navigation#661)
  Resolve gesture issues in CardStack
  Update dependencies
  Bump version number (react-navigation#650)
  Update react-native-tab-view. Fixes react-navigation#476 (react-navigation#641)
  Remove top margin from drawer view (react-navigation#642)
  Pass `transitionProps`, `prevTransitionProps` and `isModal` to custom `TransitionConfig` (react-navigation#565)
  Fix issue where initialRouteParams were not set (react-navigation#150)
  • Loading branch information
lintonye committed Mar 25, 2017
2 parents 96c2920 + 65e7104 commit 8574fbf
Show file tree
Hide file tree
Showing 18 changed files with 997 additions and 587 deletions.
24 changes: 21 additions & 3 deletions docs/api/navigators/DrawerNavigator.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,14 @@ DrawerNavigator(RouteConfigs, DrawerNavigatorConfig)

### RouteConfigs

The route configs object is a mapping from route name to a route config, which tells the navigator what to present for that route, see [example](https://github.com/coodoo/react-navigation/blob/master/docs/api/navigators/StackNavigator.md#routeconfigs) from `StackNavigator`.
The route configs object is a mapping from route name to a route config, which tells the navigator what to present for that route, see [example](/docs/api/navigators/StackNavigator.md#routeconfigs) from `StackNavigator`.


### DrawerNavigatorConfig

- `drawerWidth` - Width of the drawer
- `drawerPosition` - Options are `left` or `right`. Default is `left` position.
- `contentComponent` - Component to use to render the navigation items. Receives the `navigation` prop for the drawer. Defaults to `DrawerView.Items`.
- `contentComponent` - Component used to render the content of the drawer, for example, navigation items. Receives the `navigation` prop for the drawer. Defaults to `DrawerView.Items`. For more information, see below.
- `contentOptions` - Configure the drawer content, see below.

Several options get passed to the underlying router to modify navigation logic:
Expand All @@ -98,6 +98,24 @@ Several options get passed to the underlying router to modify navigation logic:
- `paths` - Provide a mapping of routeName to path config, which overrides the paths set in the routeConfigs.
- `backBehavior` - Should the back button cause switch to the initial route? If yes, set to `initialRoute`, otherwise `none`. Defaults to `initialRoute` behavior.

### Providing a custom `contentComponent`

You can easily override the default component used by `react-navigation`:

```js
const CustomDrawerContentComponent = (props) => (
<View style={style.container}>
<DrawerView.Items {...props} />
</View>
);

const styles = StyleSheet.create({
container : {
flex : 1,
},
});
```

### `contentOptions` for `DrawerView.Items`

- `activeTintColor` - label and icon color of the active label
Expand Down Expand Up @@ -156,7 +174,7 @@ The navigator component created by `DrawerNavigator(...)` takes the following pr
const DrawerNav = DrawerNavigator({
// config
});

<DrawerNav
screenProps={/* this prop will get passed to the screen components as this.props.screenProps */}
/>
Expand Down
4 changes: 2 additions & 2 deletions docs/api/navigators/TabNavigator.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class MyNotificationsScreen extends React.Component {
icon: ({ tintColor }) => (
<Image
source={require('./notif-icon.png')}
style={[styles.tabIcon, {tintColor: tintColor}]}
style={[styles.icon, {tintColor: tintColor}]}
/>
),
},
Expand Down Expand Up @@ -79,7 +79,7 @@ TabNavigator(RouteConfigs, TabNavigatorConfig)

### RouteConfigs

The route configs object is a mapping from route name to a route config, which tells the navigator what to present for that route, see [example](https://github.com/coodoo/react-navigation/blob/master/docs/api/navigators/StackNavigator.md#routeconfigs) from `StackNavigator`.
The route configs object is a mapping from route name to a route config, which tells the navigator what to present for that route, see [example](/docs/api/navigators/StackNavigator.md#routeconfigs) from `StackNavigator`.

### TabNavigatorConfig

Expand Down
7 changes: 3 additions & 4 deletions docs/api/routers/Routers.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ const MyApp = StackNavigator({
}, {
initialRouteName: 'Home',
})
MyApp.router = {
...MyApp.router,
const previousGetActionForPathAndParams = MyApp.router.getActionForPathAndParams
Object.assign(MyApp.router, {
getActionForPathAndParams(path, params) {
if (
path === 'my/custom/path' &&
Expand All @@ -122,9 +122,8 @@ MyApp.router = {
routeName: 'Friends',
}),
});
return null;
}
return MyApp.router.getStateForAction(action, state);
return previousGetActionForPathAndParams(path, params);
},
};
```
6 changes: 3 additions & 3 deletions docs/api/routers/RoutersAPI.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ You can make your own router by building an object with the following functions:

```js
const MyRouter = {
getStateForAction: (action) => ({}),
getStateForAction: (action, state) => ({}),
getActionForPathAndParams: (path, params) => null,
getPathAndParamsForState: (state) => null,
getComponentForState: (state) => MyScreen,
Expand Down Expand Up @@ -51,7 +51,7 @@ Typically this should return a navigation state, with the following form:

If the router has handled the action externally, or wants to swallow it without changing the navigation state, this function will return `null`.

### `getComponentRouteName(routeName)`
### `getComponentForRouteName(routeName)`

Returns the child component or navigator for the given route name.

Expand All @@ -66,7 +66,7 @@ Say a router `getStateForAction` outputs a state like this:
}
```

Based on the routeNames in the state, the router is responsible for returning valid components when calling `router.getComponentRouteName('Foo')` or `router.getComponentRouteName('Bar')`.
Based on the routeNames in the state, the router is responsible for returning valid components when calling `router.getComponentForRouteName('Foo')` or `router.getComponentForRouteName('Bar')`.

### `getComponentForState(state)`

Expand Down
15 changes: 13 additions & 2 deletions docs/guides/Contributors.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,20 @@ React navigation was initially developed on macOS 10.12, with node 7+, and react

## Development

### 0. Basic Install
### 0. Fork the repo

- Fork [`react-navigation`](https://github.com/react-community/react-navigation) on GitHub

- Run these commands in the terminal:

```
git clone git@github.com:react-community/react-navigation.git
git clone https://github.com/<USERNAME>/react-navigation.git`
cd react-navigation
git remote add upstream https://github.com/react-community/react-navigation.git
npm install
```


### 1. Run the native playground

```
Expand Down Expand Up @@ -77,3 +83,8 @@ Before embarking on any major changes, please file an issue describing the sugge
### Minor Bugfixes

Simple bug fixes are welcomed in pull requests! Please check for duplicate PRs before posting.

#### Make sure to sync up with the state of upstream before submitting a PR:

- `git fetch upstream/master`
- `git rebase upstream/master master`
108 changes: 108 additions & 0 deletions docs/guides/Navigation-Actions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# Navigation Actions

All Navigation Actions return an object that can be sent to the router using `navigation.dispatch()` method.

Note that if you want to dispatch react-navigation actions you should use the action creators provided in this library.

The following actions are supported:
* [Navigate](#navigate) - Navigate to another route
* [Reset](#reset) - Replace current state with a new state
* [Back](#back) - Go back to previous state
* [Set Params](#setparams) - Set Params for given route
* [Init](#init) - Used to initialize first state if state is undefined

### Navigate
The `Navigate` action will update the current state with the result of a `Navigate` action.

- `routeName` - *String* - Required - A destination routeName that has been registered somewhere in the app's router
- `params` - *Object* - Optional - Params to merge into the destination route
- `action` - *Object* - Optional - (advanced) The sub-action to run in the child router, if the screen is a navigator. Any one of the actions described in this doc can be set as a sub-action.

```js
import { NavigationActions } from 'react-navigation'

const navigateAction = NavigationActions.navigate({

routeName: 'Profile',

params: {},

action: NavigationActions.navigate({ routeName: 'SubProfileRoute'})
})

this.props.navigation.dispatch(navigateAction)

```


### Reset

The `Reset` action wipes the whole navigation state and replaces it with the result of several actions.

- `index` - *number* - required - Index of the active route on `routes` array in navigation `state`.
- `actions` - *array* - required - Array of Navigation Actions that will replace the navigation state.

```js
import { NavigationActions } from 'react-navigation'

const resetAction = NavigationActions.reset({
index: 0,
actions: [
NavigationActions.navigate({ routeName: 'Profile'})
]
})
this.props.navigation.dispatch(resetAction)

```
#### How to use the `index` parameter
The `index` param is used to specify the current active route.

eg: given a basic stack navigation with two routes `Profile` and `Settings`.
To reset the state to a point where the active screen was `Settings` but have it stacked on top of a `Profile` screen, you would do the following:

```js
import { NavigationActions } from 'react-navigation'

const resetAction = NavigationActions.reset({
index: 1,
actions: [
NavigationActions.navigate({ routeName: 'Profile'}),
NavigationActions.navigate({ routeName: 'Settings'})
]
})
this.props.navigation.dispatch(resetAction)

```

### Back

Go back to previous screen and close current screen. `back` action creator takes in one optional parameter:
- `key` - *string or null* - optional - If set, navigation will go back from the given key. If null, navigation will go back anywhere.

```js
import { NavigationActions } from 'react-navigation'

const backAction = NavigationActions.back({
key: 'Profile'
})
this.props.navigation.dispatch(backAction)

```

### SetParams

When dispatching `SetParams`, the router will produce a new state that has changed the params of a particular route, as identified by the key

- `params` - *object* - required - New params to be merged into existing route params
- `key` - *string* - required - Route key that should get the new params

```js
import { NavigationActions } from 'react-navigation'

const setParamsAction = NavigationActions.setParams({
params: { title: 'Hello' },
key: 'screen-123',
})
this.props.navigation.dispatch(setParamsAction)

```
Loading

0 comments on commit 8574fbf

Please sign in to comment.