Skip to content

Instantly share code, notes, and snippets.

@abhiaiyer91
Forked from GollyJer/rn-button.js
Created April 4, 2017 19:38
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 abhiaiyer91/2ad79c44e48924b1d83da281ba58bb17 to your computer and use it in GitHub Desktop.
Save abhiaiyer91/2ad79c44e48924b1d83da281ba58bb17 to your computer and use it in GitHub Desktop.
React Native Button
import React from 'react';
import { Text, TouchableNativeFeedback, TouchableOpacity, View, Platform } from 'react-native';
import styles from './styles.js';
const Button = ({ color, onPress, title, disabled }) => {
let Touchable;
const buttonStyle = [styles.button];
const textStyle = [styles.text];
switch (Platform.OS) {
case 'android':
Touchable = TouchableNativeFeedback;
color && buttonStyle.push({ backgroundColor: color });
title = title.toUpperCase();
break;
case 'ios':
Touchable = TouchableOpacity;
color && textStyle.push({ color: color });
break;
}
return (
<Touchable disabled={disabled} onPress={onPress}>
<View style={buttonStyle}>
<Text style={textStyle}>{title}</Text>
</View>
</Touchable>
);
};
export default Button;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment