react-native-navigation的迁移库

ContextScreen.js 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. const React = require('react');
  2. const { View, Text } = require('react-native');
  3. const testIDs = require('../testIDs');
  4. const { TitleContext, Context } = require('../context');
  5. class ContextScreen extends React.Component {
  6. static contextType = Context;
  7. static options() {
  8. return {
  9. topBar: {
  10. title: {
  11. text: 'My Screen'
  12. },
  13. background: {
  14. color: 'red'
  15. }
  16. }
  17. };
  18. }
  19. render() {
  20. return (
  21. <View style={styles.root}>
  22. <View style={{ flexDirection: 'row', alignItems: 'center', marginBottom: 10 }}>
  23. <Text style={styles.h2}>Default value: </Text>
  24. <Text style={styles.h2} testID={testIDs.CENTERED_TEXT_HEADER}>{this.context}</Text>
  25. </View>
  26. <View style={{ flexDirection: 'row', alignItems: 'center' }}>
  27. <Text style={styles.h2}>Provider value: </Text>
  28. <TitleContext.Consumer>
  29. {title => (
  30. <Text style={styles.h2} testID={testIDs.CENTERED_TEXT_HEADER}>{title}</Text>
  31. )}
  32. </TitleContext.Consumer>
  33. </View>
  34. </View>
  35. );
  36. }
  37. }
  38. module.exports = ContextScreen;
  39. const styles = {
  40. root: {
  41. flexGrow: 1,
  42. justifyContent: 'center',
  43. alignItems: 'center',
  44. backgroundColor: '#f5fcff'
  45. },
  46. h1: {
  47. fontSize: 24,
  48. textAlign: 'center'
  49. },
  50. h2: {
  51. fontSize: 12,
  52. textAlign: 'center',
  53. },
  54. };