react-native-navigation的迁移库

OrientationDetectScreen.js 1.7KB

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