Advertisement
Felanpro

React Native (Detecting Orientation Changes)

May 14th, 2023
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. import { StatusBar } from 'expo-status-bar';
  2. import { Dimensions, useWindowDimensions, StyleSheet, Text, View, TouchableWithoutFeedback, TouchableOpacity, TouchableHighlight, Alert, Image, SafeAreaView, Button } from 'react-native';
  3. import { useDeviceOrientation } from '@react-native-community/hooks';
  4.  
  5. export default function App() {
  6. const orientation = useDeviceOrientation();
  7.  
  8. return (
  9. <SafeAreaView style={styles.container}>
  10.  
  11. <View
  12. style = {{
  13.  
  14. backgroundColor: 'dodgerblue',
  15. width: '100%',
  16. height: orientation === 'landscape' ? "100%" : "30%",
  17.  
  18. }}
  19. ></View>
  20.  
  21. <StatusBar style="auto" />
  22.  
  23. </SafeAreaView>
  24. );
  25. }
  26.  
  27. const containerStyle = {backgroundColor: "orange"};
  28.  
  29. const styles = StyleSheet.create({
  30. container: {
  31. flex: 1,
  32. backgroundColor: 'orange'
  33. },
  34. });
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement