Advertisement
Felanpro

React Native (Relative and Absolute Positioning)

May 15th, 2023
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 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.  
  7. return (
  8. <View
  9. style={{
  10. backgroundColor: "#fff",
  11. flex: 1,
  12. flexDirection: "row", // horizontal
  13. justifyContent: "center", // primary axis
  14. alignItems: "center", // secondary axis
  15. alignContent: "center",
  16.  
  17. /**
  18. * Press Ctrl + Space to see for example what values flexDirection can be assigned
  19. */
  20. }}
  21. >
  22.  
  23. <View
  24. style={{
  25. backgroundColor: "dodgerblue",
  26. width: 100,
  27. height: 100,
  28. }}
  29. />
  30.  
  31. <View
  32. style={{
  33. backgroundColor: "gold",
  34. width: 100,
  35. height: 100,
  36. top: 20, //or do bottom: -20
  37. left: 20, //or do right: -20 basically using top or left etc.. you can move components without effecting other components position because by default position is "relative"
  38. position: "absolute", // but you can change to "absolute" so components move around relative to its parent view and the layout around it will be affected
  39. }}
  40. />
  41.  
  42. <View
  43. style={{
  44. backgroundColor: "tomato",
  45. width: 100,
  46. height: 100
  47. }}
  48. />
  49.  
  50. </View>
  51. );
  52. }
  53.  
  54. const containerStyle = {backgroundColor: "orange"};
  55.  
  56. const styles = StyleSheet.create({
  57. container: {
  58. flex: 1,
  59. backgroundColor: 'orange'
  60. },
  61. });
  62.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement