react-native-navigation的迁移库

LifecycleScreen.js 1.6KB

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