|
@@ -6,6 +6,7 @@ const Screens = require('./Screens');
|
6
|
6
|
const {
|
7
|
7
|
PUSH_TO_TEST_DID_DISAPPEAR_BTN,
|
8
|
8
|
DISMISS_MODAL_BTN,
|
|
9
|
+ SCREEN_POPPED_BTN,
|
9
|
10
|
POP_BTN
|
10
|
11
|
} = require('../testIDs');
|
11
|
12
|
|
|
@@ -25,6 +26,7 @@ class LifecycleScreen extends React.Component {
|
25
|
26
|
|
26
|
27
|
constructor(props) {
|
27
|
28
|
super(props);
|
|
29
|
+ this.showUnmountAndDisappearAlerts = true;
|
28
|
30
|
Navigation.events().bindComponent(this);
|
29
|
31
|
}
|
30
|
32
|
|
|
@@ -33,12 +35,12 @@ class LifecycleScreen extends React.Component {
|
33
|
35
|
}
|
34
|
36
|
|
35
|
37
|
componentDidDisappear() {
|
36
|
|
- alert('didDisappear'); // eslint-disable-line no-alert
|
|
38
|
+ this.showUnmountAndDisappearAlerts && alert('didDisappear'); // eslint-disable-line no-alert
|
37
|
39
|
}
|
38
|
40
|
|
39
|
41
|
componentWillUnmount() {
|
40
|
42
|
setTimeout(() => {
|
41
|
|
- alert('componentWillUnmount'); // eslint-disable-line no-alert
|
|
43
|
+ this.showUnmountAndDisappearAlerts && alert('componentWillUnmount'); // eslint-disable-line no-alert
|
42
|
44
|
}, 100);
|
43
|
45
|
}
|
44
|
46
|
|
|
@@ -50,6 +52,7 @@ class LifecycleScreen extends React.Component {
|
50
|
52
|
return (
|
51
|
53
|
<Root componentId={this.props.componentId} footer={this.state.text}>
|
52
|
54
|
<Button label='Push to test didDisappear' testID={PUSH_TO_TEST_DID_DISAPPEAR_BTN} onPress={this.push} />
|
|
55
|
+ {!this.props.isModal && <Button label='Screen popped events' testID={SCREEN_POPPED_BTN} onPress={this.screenPoppedEvent} />}
|
53
|
56
|
{this.renderCloseButton()}
|
54
|
57
|
</Root>
|
55
|
58
|
);
|
|
@@ -60,6 +63,14 @@ class LifecycleScreen extends React.Component {
|
60
|
63
|
<Button label='Pop' testID={POP_BTN} onPress={this.pop} />;
|
61
|
64
|
|
62
|
65
|
push = () => Navigation.push(this, Screens.Pushed);
|
|
66
|
+ screenPoppedEvent = async () => {
|
|
67
|
+ this.showUnmountAndDisappearAlerts = false;
|
|
68
|
+ const unregister = Navigation.events().registerScreenPoppedListener((event) => {
|
|
69
|
+ alert('Screen popped event')
|
|
70
|
+ unregister.remove();
|
|
71
|
+ });
|
|
72
|
+ await Navigation.pop(this);
|
|
73
|
+ }
|
63
|
74
|
pop = () => Navigation.pop(this);
|
64
|
75
|
dismiss = () => Navigation.dismissModal(this);
|
65
|
76
|
}
|