Skip to content

Commit 19d9291

Browse files
authored
Merge pull request react-navigation#211 from slorber/navigation-events-doc
Add <NavigationEvents/> to doc
2 parents 2c6492d + 2d5dad3 commit 19d9291

File tree

4 files changed

+48
-2
lines changed

4 files changed

+48
-2
lines changed

docs/navigation-events.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
id: navigation-events
3+
title: NavigationEvents reference
4+
sidebar_label: NavigationEvents
5+
---
6+
7+
`NavigationEvents` is a React component providing a declarative API to subscribe to navigation events. It will subscribe to navigation events on mount, and unsubscribe on unmount.
8+
9+
### Component props
10+
11+
* `navigation` - navigation props (optional, defaults to reading from React context)
12+
* `onWillFocus` - event listener
13+
* `onDidFocus` - event listener
14+
* `onWillBlur` - event listener
15+
* `onDidBlur` - event listener
16+
17+
The event listener is the same as the imperative [`navigation.addListener(...)`](navigation-prop.html#addlistener-subscribe-to-updates-to-navigation-lifecycle) API.
18+
19+
### Example
20+
21+
```jsx harmony
22+
import React from 'react';
23+
import { View } from 'react-native';
24+
import { NavigationEvents } from 'react-navigation';
25+
26+
const MyScreen = () => (
27+
<View>
28+
<NavigationEvents
29+
onWillFocus={payload => console.log('will focus',payload)}
30+
onDidFocus={payload => console.log('did focus',payload)}
31+
onWillBlur={payload => console.log('will blur',payload)}
32+
onDidBlur={payload => console.log('did blur',payload)}
33+
/>
34+
{/*
35+
Your view code
36+
*/}
37+
</View>
38+
);
39+
40+
export default MyScreen;
41+
```

docs/navigation-prop.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ The JSON payload:
138138
};
139139
```
140140

141+
You can also subscribe to navigation events declaratively with the [`<NavigationEvents/>`](navigation-events.html) component.
142+
141143
### `isFocused` - Query the focused state of the screen
142144

143145
Returns `true` if the screen is focused and `false` otherwise.

website/i18n/en.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@
7373
"Moving between screens": "Moving between screens",
7474
"navigation-actions": "NavigationActions reference",
7575
"NavigationActions": "NavigationActions",
76+
"navigation-events": "NavigationEvents reference",
77+
"NavigationEvents": "NavigationEvents",
7678
"navigation-key": "Using the navigation key",
7779
"Using the navigation key": "Using the navigation key",
7880
"navigation-options-resolution": "Navigation options resolution",

website/sidebars.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"navigation-views",
3838
"transitioner"
3939
],
40-
"Community Navigators": [
40+
"Community Navigators": [
4141
"community-fluidtransitions"
4242
],
4343
"Meta": ["pitch", "alternatives", "contributing"]
@@ -56,7 +56,8 @@
5656
"material-bottom-tab-navigator",
5757
"material-top-tab-navigator",
5858
"with-navigation",
59-
"with-navigation-focus"
59+
"with-navigation-focus",
60+
"navigation-events"
6061
]
6162
}
6263
}

0 commit comments

Comments
 (0)