react-native-navigation的迁移库

LifecycleScreen.js 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. const React = require('react');
  2. const { Component } = require('react');
  3. const { View, Text, Button, Platform } = require('react-native');
  4. const Navigation = require('react-native-navigation');
  5. class LifecycleScreen extends Component {
  6. constructor(props) {
  7. super(props);
  8. this.onClickPush = this.onClickPush.bind(this);
  9. this.state = {
  10. text: 'nothing yet'
  11. };
  12. }
  13. didAppear() {
  14. this.setState({ text: 'didAppear' });
  15. }
  16. didDisappear() {
  17. if (Platform.OS === 'ios') {
  18. alert('didDisappear'); // eslint-disable-line no-alert
  19. } else {
  20. Navigation.showOverlay('alert', {
  21. text: 'didDisappear',
  22. positiveButton: {
  23. text: 'OK'
  24. }
  25. });
  26. }
  27. }
  28. componentWillUnmount() {
  29. if (Platform.OS === 'ios') {
  30. alert('componentWillUnmount'); // eslint-disable-line no-alert
  31. } else {
  32. Navigation.showOverlay('alert', {
  33. text: 'componentWillUnmount',
  34. positiveButton: {
  35. text: 'OK'
  36. }
  37. });
  38. }
  39. }
  40. onNavigationButtonPressed(id) {
  41. alert(`onNavigationButtonPressed: ${id}`); // eslint-disable-line no-alert
  42. }
  43. render() {
  44. return (
  45. <View style={styles.root}>
  46. <Text style={styles.h1}>{`Lifecycle Screen`}</Text>
  47. <Text style={styles.h1}>{this.state.text}</Text>
  48. <Button title="Push to test didDisappear" onPress={this.onClickPush} />
  49. <Text style={styles.footer}>{`this.props.containerId = ${this.props.containerId}`}</Text>
  50. </View>
  51. );
  52. }
  53. onClickPush() {
  54. Navigation.push(this.props.containerId, { name: 'navigation.playground.TextScreen' });
  55. }
  56. }
  57. module.exports = LifecycleScreen;
  58. const styles = {
  59. root: {
  60. flexGrow: 1,
  61. justifyContent: 'center',
  62. alignItems: 'center',
  63. backgroundColor: '#f5fcff'
  64. },
  65. h1: {
  66. fontSize: 24,
  67. textAlign: 'center',
  68. margin: 10
  69. },
  70. footer: {
  71. fontSize: 10,
  72. color: '#888',
  73. marginTop: 10
  74. }
  75. };