- Create Components folder under src folder
- Add DetectDeviceIsAndroidOrIOS.js file and add below Code
import React from "react";
import { StyleSheet, View, Text, Platform } from "react-native";
const DetectDeviceIsAndroidOrIOS = () => {
return (
<View style={styles.MainContainer}>
<Text>Detect Device is Android or iOS Load Different Component</Text>
{Platform.OS === "ios" ? (
<Text style={styles.TextStyle}> This is iOS Device. </Text>
) : (
<Text style={styles.TextStyle}> This is Android Device. </Text>
)}
</View>
);
};
export default DetectDeviceIsAndroidOrIOS;
const styles = StyleSheet.create({
MainContainer: {
justifyContent: "center",
flex: 1,
margin: 10
},
TextStyle: {
fontSize: 24,
textAlign: "center"
}
});
- Open App.js file and update code as below
import React from 'react';
import { Text,View,StyleSheet } from 'react-native';
import DetectDeviceIsAndroidOrIOS from './src/Component/DetectDeviceIsAndroidOrIOS'
const App=()=> {
return (
<View style={styles.container}>
<DetectDeviceIsAndroidOrIOS/>
</View>
);
}
export default App;
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
paddingTop:80
},
});
No comments:
Post a Comment