react-native-navigation的迁移库

LifecycleScreen.js 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import React, { Component } from 'react';
  2. import { View, Text, Button } from 'react-native';
  3. import Navigation from 'react-native-navigation';
  4. class LifecycleScreen extends Component {
  5. constructor(props) {
  6. super(props);
  7. this.onClickPush = this.onClickPush.bind(this);
  8. this.state = {
  9. text: 'nothing yet'
  10. };
  11. }
  12. onStart() {
  13. this.setState({ text: 'onStart!' });
  14. }
  15. onStop() {
  16. alert('onStop!'); //eslint-disable-line
  17. }
  18. render() {
  19. return (
  20. <View style={styles.root}>
  21. <Text style={styles.h1}>Lifecycle Screen</Text>
  22. <Text style={styles.h1}>{this.state.text}</Text>
  23. <Button title="Push to test onStop" onPress={this.onClickPush} />
  24. <Text style={styles.footer}>ContainerId: {this.props.id}</Text>
  25. </View>
  26. );
  27. }
  28. onClickPush() {
  29. Navigation.on(this.props.id).push({
  30. name: 'navigation.playground.TextScreen'
  31. });
  32. }
  33. }
  34. export default LifecycleScreen;
  35. const styles = {
  36. root: {
  37. flexGrow: 1,
  38. justifyContent: 'center',
  39. alignItems: 'center',
  40. backgroundColor: '#f5fcff'
  41. },
  42. h1: {
  43. fontSize: 24,
  44. textAlign: 'center',
  45. margin: 10
  46. },
  47. footer: {
  48. fontSize: 10,
  49. color: '#888',
  50. marginTop: 10
  51. }
  52. };