Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import React, { Component } from "react";
import { View, Platform } from "react-native";
import Icon from 'react-native-vector-icons/Ionicons';
const getTypedIcon = name => {
return Platform.OS === "ios" ? `ios-${name}` : `md-${name}`;
};
export default class App extends Component {
render(){
return (
<View style={{ flex: 1 }}>
<Icon name={getTypedIcon("unlock")} />
</View>
)
}
}
Several ways to differentiate platform in react-native
import React, { Component } from "react";
import { View } from "react-native";
import Navigator from "./Navigator";
export default class App extends Component {
render(){
return (
<View style={{ flex: 1 }}>
<Navigator />
</View>
)
}
}
import React, { Component } from "react";
import { View, Text, Platform, StyleSheet } from "react-native";
export default class App extends Component {
render(){
return (
<View style={{ flex: 1 }}>
<Text style={[style.platformBasedText]}>
I am different
</Text>
</View>
)
}
}
const style = StyleSheet.create(
{
platformBasedText: {
...Platform.select({
ios: {
color: "blue",
},
android: {
color: "red",
},
})
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment