react-native-navigation的迁移库

OrientationDetectScreen.js 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 OrientationDetectScreen extends Component {
  7. constructor(props) {
  8. super(props);
  9. this.detectHorizontal = this.detectHorizontal.bind(this);
  10. this.state = { horizontal: false };
  11. Navigation.mergeOptions(this.props.componentId, {
  12. orientation: props.orientation
  13. });
  14. }
  15. render() {
  16. return (
  17. <View style={styles.root} onLayout={this.detectHorizontal}>
  18. <Text style={styles.h1}>{`Orientation Screen`}</Text>
  19. <Button title='Dismiss' testID={testIDs.DISMISS_BUTTON} onPress={() => Navigation.dismissModal(this.props.componentId)} />
  20. <Text style={styles.footer}>{`this.props.componentId = ${this.props.componentId}`}</Text>
  21. {this.state.horizontal ?
  22. <Text style={styles.footer} testID={testIDs.LANDSCAPE_ELEMENT}>Landscape</Text> :
  23. <Text style={styles.footer} testID={testIDs.PORTRAIT_ELEMENT}>Portrait</Text>}
  24. </View>
  25. );
  26. }
  27. detectHorizontal({ nativeEvent: { layout: { width, height } } }) {
  28. this.setState({
  29. horizontal: width > height
  30. });
  31. }
  32. }
  33. const styles = {
  34. root: {
  35. flexGrow: 1,
  36. justifyContent: 'center',
  37. alignItems: 'center',
  38. backgroundColor: 'white'
  39. },
  40. h1: {
  41. fontSize: 24,
  42. textAlign: 'center',
  43. margin: 10
  44. },
  45. h2: {
  46. fontSize: 12,
  47. textAlign: 'center',
  48. margin: 10
  49. },
  50. footer: {
  51. fontSize: 10,
  52. color: '#888',
  53. marginTop: 10
  54. }
  55. };
  56. module.exports = OrientationDetectScreen;