Skip to content

Instantly share code, notes, and snippets.

@abhiaiyer91
Forked from GollyJer/rn-button.js
Last active April 4, 2017 19:40
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/c7aa20751668349e21e55808c9396333 to your computer and use it in GitHub Desktop.
Save abhiaiyer91/c7aa20751668349e21e55808c9396333 to your computer and use it in GitHub Desktop.
React Native Button
import React from 'react';
import { withProps } from 'recompose';
import { Text, TouchableNativeFeedback, TouchableOpacity, View, Platform } from 'react-native';
import styles from './styles.js';
function Button({ Component, buttonStyle, textStyle, onPress, title, disabled }) {
return (
<Component disabled={disabled} onPress={onPress}>
<View style={buttonStyle}>
<Text style={textStyle}>{title}</Text>
</View>
</Component>
);
};
export default withProps(({ title, color }) => {
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 {
Component: Touchable,
buttonStyle,
textStyle,
};
})(Button);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment