import React from 'react';
import { View, Text, StyleSheet, Platform } from 'react-native';
export default function PlatformStyleDemo() {
return (
<View style={styles.container}>
<View style={styles.box} />
<Text style={styles.platformText}>Platform: {Platform.OS}</Text>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#fff'
},
box: {
width: 150,
height: 150,
backgroundColor: Platform.select({
ios: 'blue',
android: 'green',
default: 'gray'
}),
borderRadius: 10
},
platformText: {
marginTop: 20,
fontSize: 18,
color: '#333'
}
});We use React Native's Platform API to apply different background colors depending on the device OS. The Platform.select method helps us write platform-specific styles cleanly inside the StyleSheet. The box is centered with fixed size and rounded corners. Below it, a Text component shows the current platform name dynamically using Platform.OS.
This approach keeps the UI consistent but visually distinct on iOS and Android, demonstrating platform-specific styling in React Native.