const React = require('react'); const { Component } = require('react'); const PropTypes = require('prop-types'); const { Platform, ColorPropType, StyleSheet, TouchableNativeFeedback, TouchableOpacity, View, Text } = require('react-native'); class Button extends Component { static propTypes = { title: PropTypes.string.isRequired, accessibilityLabel: PropTypes.string, color: ColorPropType, disabled: PropTypes.bool, hasTVPreferredFocus: PropTypes.bool, onPress: PropTypes.func, onPressIn: PropTypes.func, testID: PropTypes.string, }; render() { const { accessibilityLabel, color, onPress, onPressIn, title, hasTVPreferredFocus, disabled, testID, } = this.props; const buttonStyles = [styles.button]; const textStyles = [styles.text]; if (color) { if (Platform.OS === 'ios') { textStyles.push({color: color}); } else { buttonStyles.push({backgroundColor: color}); } } const accessibilityTraits = ['button']; if (disabled) { buttonStyles.push(styles.buttonDisabled); textStyles.push(styles.textDisabled); accessibilityTraits.push('disabled'); } const formattedTitle = Platform.OS === 'android' ? title.toUpperCase() : title; const Touchable = Platform.OS === 'android' ? TouchableNativeFeedback : TouchableOpacity; return ( {formattedTitle} ); } } const styles = StyleSheet.create({ button: Platform.select({ ios: {}, android: { elevation: 4, backgroundColor: '#2196F3', borderRadius: 2, }, }), text: Platform.select({ ios: { color: '#007AFF', textAlign: 'center', padding: 8, fontSize: 18, }, android: { color: 'white', textAlign: 'center', padding: 8, fontWeight: '500', }, }), buttonDisabled: Platform.select({ ios: {}, android: { elevation: 0, backgroundColor: '#dfdfdf', }, }), textDisabled: Platform.select({ ios: { color: '#cdcdcd', }, android: { color: '#a1a1a1', }, }), }); module.exports = Button;