Guest User

Untitled

a guest
Nov 18th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. import React from 'react'
  2. import { StyleSheet, Text, View,Dimensions } from 'react-native'
  3. const dim = Dimensions.get('screen')
  4.  
  5. export default class App extends React.Component {
  6. state = {
  7. screenWidth:dim.width,
  8. screenHeight:dim.height,
  9. orientation:this._getOrientation(dim.width,dim.height)
  10. }
  11.  
  12. _getOrientation(width,height){
  13. if (width < height) return 'Potrait'
  14. return 'Landscape'
  15. }
  16.  
  17. _updateLayout(event){
  18. const {width,height}=event.nativeEvent.layout
  19. let orientation =this._getOrientation(width,height)
  20. this.setState({
  21. screenWidth:width,
  22. screenHeight:height,
  23. orientation:this._getOrientation(width,height)
  24. })
  25. }
  26.  
  27. render() {
  28. return (
  29. <View style={styles.container} onLayout={ (event) => this._updateLayout(event)}>
  30. <Text>Orientation : {this.state.orientation}</Text>
  31. <Text>Width : {this.state.screenWidth}</Text>
  32. <Text>Height : {this.state.screenHeight}</Text>
  33. </View>
  34. )
  35. }
  36. }
  37.  
  38. const styles = StyleSheet.create({
  39. container: {
  40. flex: 1,
  41. backgroundColor: '#fff',
  42. alignItems: 'center',
  43. justifyContent: 'center',
  44. },
  45. });
Add Comment
Please, Sign In to add comment