react-native-navigation的迁移库

SimpleScreen.js 1.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import React, { Component } from 'react';
  2. import { View, Text, Button } from 'react-native';
  3. import Navigation from 'react-native-navigation';
  4. class SimpleScreen extends Component {
  5. constructor(props) {
  6. super(props);
  7. this.onClickPop = this.onClickPop.bind(this);
  8. }
  9. render() {
  10. return (
  11. <View style={styles.root}>
  12. <Text style={styles.h1}>{this.props.text || 'Simple Screen'}</Text>
  13. {this.renderTextFromFunctionInProps()}
  14. <Button title="Pop" onPress={this.onClickPop} />
  15. </View>
  16. );
  17. }
  18. renderTextFromFunctionInProps() {
  19. if (!this.props.myFunction) {
  20. return undefined;
  21. }
  22. return (
  23. <Text style={styles.h1}>{this.props.myFunction()}</Text>
  24. );
  25. }
  26. onClickPop() {
  27. Navigation.on(this.props.id).pop();
  28. }
  29. }
  30. export default SimpleScreen;
  31. const styles = {
  32. root: {
  33. flexGrow: 1,
  34. justifyContent: 'center',
  35. alignItems: 'center',
  36. backgroundColor: '#f5fcff'
  37. },
  38. h1: {
  39. fontSize: 24,
  40. textAlign: 'center',
  41. margin: 10
  42. }
  43. };