|
@@ -39,7 +39,7 @@ Navigation.events().registerAppLaunchedListener(() => {
|
39
|
39
|
|
40
|
40
|
## Screen Lifecycle
|
41
|
41
|
|
42
|
|
-The `componentDidAppear` and `componentDidDisappear` functions are special React Native Navigation lifecycle callbacks that are called on the component when it appears and disappears.
|
|
42
|
+The `componentDidAppear` and `componentDidDisappear` functions are special React Native Navigation lifecycle callbacks that are called on the component when it appears and disappears (after it was bounded using `Navigation.events().bindComponent(this)`).
|
43
|
43
|
|
44
|
44
|
Similar to React's `componentDidMount` and `componentWillUnmount`, what's different is that they represent whether the user can actually see the component in question -- and not just whether it's been mounted or not. Because of the way React Native Navigation optimizes performance, a component is actually `mounted` as soon as it's part of a layout -- but it is not always `visible` (for example, when another screen is `pushed` on top of it).
|
45
|
45
|
|
|
@@ -47,12 +47,13 @@ There are lots of use cases for these. For example: starting and stopping an ani
|
47
|
47
|
|
48
|
48
|
> They are implemented by iOS's viewDidAppear/viewDidDisappear and Android's ViewTreeObserver visibility detection
|
49
|
49
|
|
50
|
|
-To use them, simply implement them in your component like any other React lifecycle function:
|
|
50
|
+To use them, simply implement them in your component like any other React lifecycle function, and bind the screen to the Navigation events module which will call all functions automatically:
|
51
|
51
|
|
52
|
52
|
```js
|
53
|
53
|
class LifecycleScreenExample extends Component {
|
54
|
54
|
constructor(props) {
|
55
|
55
|
super(props);
|
|
56
|
+ Navigation.events().bindComponent(this);
|
56
|
57
|
this.state = {
|
57
|
58
|
text: 'nothing yet'
|
58
|
59
|
};
|
|
@@ -66,6 +67,10 @@ class LifecycleScreenExample extends Component {
|
66
|
67
|
alert('componentDidDisappear');
|
67
|
68
|
}
|
68
|
69
|
|
|
70
|
+ navigationButtonPressed({buttonId}) {
|
|
71
|
+ // a navigation-based button (for example in the topBar) was clicked. See section on buttons.
|
|
72
|
+ }
|
|
73
|
+
|
69
|
74
|
componentWillUnmount() {
|
70
|
75
|
alert('componentWillUnmount');
|
71
|
76
|
}
|