- Create Components folder under src folder
- Add GetDeviceHeightWidth.js file and add below Code
import React from "react";
import { StyleSheet, View, Button, Dimensions } from "react-native";
const GetDeviceHeightWidth = () => {
const GetHeightFunction = () => {
const Height_Holder = Dimensions.get("window").height;
alert("Device Height: " + Height_Holder);
};
const GetWidthFunction = () => {
const Width_Holder = Dimensions.get("window").width;
alert("Device Width: " + Width_Holder);
};
return (
<View style={styles.MainContainer}>
<View style={styles.ButtonStyle}>
<Button
title="Click Here To Show Device Height"
onPress={GetHeightFunction}
/>
</View>
<View style={styles.ButtonStyle}>
<Button
title="Click Here To Show Device Width"
onPress={GetWidthFunction}
/>
</View>
</View>
);
};
export default GetDeviceHeightWidth;
const styles = StyleSheet.create({
MainContainer: {
flex: 1,
justifyContent: "center",
backgroundColor: "#F5FCFF",
margin: 10
},
ButtonStyle: {
margin: 10
}
});
- Open App.js file and update code as below
import React from 'react';
import { View,StyleSheet } from 'react-native';
import GetDeviceHeightWidth from './src/Component/GetDeviceHeightWidth'
const App=()=> {
return (
<View style={styles.container}>
<GetDeviceHeightWidth/>
</View>
);
}
export default App;
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
paddingTop:80
},
});
No comments:
Post a Comment