react-native-navigation的迁移库

TextScreen.js 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. class TextScreen extends Component {
  6. render() {
  7. return (
  8. <View style={styles.root}>
  9. <Text style={styles.h1}>{this.props.text || 'Text Screen'}</Text>
  10. {this.renderTextFromFunctionInProps()}
  11. <Text style={styles.footer}>{`this.props.containerId = ${this.props.containerId}`}</Text>
  12. <Button title={'Set Tab Badge'} onPress={() => this.onButtonPress()} />
  13. </View>
  14. );
  15. }
  16. renderTextFromFunctionInProps() {
  17. if (!this.props.myFunction) {
  18. return undefined;
  19. }
  20. return (
  21. <Text style={styles.h1}>{this.props.myFunction()}</Text>
  22. );
  23. }
  24. onButtonPress() {
  25. Navigation.setOptions(this.props.containerId, {
  26. tabBadge: `EnCyClOpEdIa`
  27. });
  28. }
  29. }
  30. module.exports = TextScreen;
  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. h2: {
  44. fontSize: 12,
  45. textAlign: 'center',
  46. margin: 10
  47. },
  48. footer: {
  49. fontSize: 10,
  50. color: '#888',
  51. marginTop: 10
  52. }
  53. };