1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- const React = require('react');
- const { Component } = require('react');
-
- const { View, Text, Button, Platform } = require('react-native');
-
- const Navigation = require('react-native-navigation');
-
- class LifecycleScreen extends Component {
- constructor(props) {
- super(props);
- this.onClickPush = this.onClickPush.bind(this);
- this.state = {
- text: 'nothing yet'
- };
- }
-
- didAppear() {
- this.setState({ text: 'didAppear' });
- }
-
- didDisappear() {
- if (Platform.OS === 'ios') {
- alert('didDisappear'); // eslint-disable-line no-alert
- } else {
- Navigation.showOverlay('alert', {
- text: 'didDisappear',
- positiveButton: {
- text: 'OK'
- }
- });
- }
- }
-
- componentWillUnmount() {
- if (Platform.OS === 'ios') {
- alert('componentWillUnmount'); // eslint-disable-line no-alert
- } else {
- Navigation.showOverlay('alert', {
- text: 'componentWillUnmount',
- positiveButton: {
- text: 'OK'
- }
- });
- }
- }
-
- onNavigationButtonPressed(id) {
- alert(`onNavigationButtonPressed: ${id}`); // eslint-disable-line no-alert
- }
-
- render() {
- return (
- <View style={styles.root}>
- <Text style={styles.h1}>{`Lifecycle Screen`}</Text>
- <Text style={styles.h1}>{this.state.text}</Text>
- <Button title="Push to test didDisappear" onPress={this.onClickPush} />
- <Text style={styles.footer}>{`this.props.containerId = ${this.props.containerId}`}</Text>
- </View>
- );
- }
-
- onClickPush() {
- Navigation.push(this.props.containerId, { name: 'navigation.playground.TextScreen' });
- }
- }
- module.exports = LifecycleScreen;
-
- const styles = {
- root: {
- flexGrow: 1,
- justifyContent: 'center',
- alignItems: 'center',
- backgroundColor: '#f5fcff'
- },
- h1: {
- fontSize: 24,
- textAlign: 'center',
- margin: 10
- },
- footer: {
- fontSize: 10,
- color: '#888',
- marginTop: 10
- }
- };
|