dimensions react native

131

react native dimensions -

import React, { useState, useEffect } from "react";
 import { View, StyleSheet, Text, Dimensions } from "react-native";
 const window = Dimensions.get("window");
 const screen = Dimensions.get("screen");
 const App = () => {
 const [dimensions, setDimensions] = useState({ window, screen });
 const onChange = ({ window, screen }) => {
     setDimensions({ window, screen });
   };
 useEffect(() => {
     Dimensions.addEventListener("change", onChange);
     return () => {
       Dimensions.removeEventListener("change", onChange);
     };
   });
 return (
   {<code>Window Dimensions: height - ${dimensions.window.height}, width - ${dimensions.window.width}}
   {Screen Dimensions: height - ${dimensions.screen.height}, width - ${dimensions.screen.width}}     
   );
  }
  const styles = StyleSheet.create({
   container: {
     flex: 1,
     justifyContent: "center",
     alignItems: "center"
   }
  });
  export default App;

Comments

Submit
0 Comments