Skip to content

Instantly share code, notes, and snippets.

@siwananda
Last active June 3, 2017 11:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save siwananda/01df08dcf8e7845af0463654e90fda5b to your computer and use it in GitHub Desktop.
Save siwananda/01df08dcf8e7845af0463654e90fda5b to your computer and use it in GitHub Desktop.
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