Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import React from 'react';
- import {Platform, StyleSheet, Text, TouchableNativeFeedback, TouchableOpacity, View} from 'react-native';
- class Button extends React.Component{
- render() {
- const {
- accessibilityLabel,
- color,
- backgroundColor,
- onPress,
- touchSoundDisabled,
- title,
- hasTVPreferredFocus,
- nextFocusDown,
- nextFocusForward,
- nextFocusLeft,
- nextFocusRight,
- nextFocusUp,
- disabled,
- testID,
- } = this.props;
- const buttonStyles = [styles.button];
- const textStyles = [styles.text];
- if (color) textStyles.push({color: color});
- const accessibilityState = {};
- if (disabled) {
- buttonStyles.push(styles.buttonDisabled);
- textStyles.push(styles.textDisabled);
- accessibilityState.disabled = true;
- }
- if(backgroundColor) buttonStyles.push({backgroundColor: backgroundColor})
- const formattedTitle =
- Platform.OS === 'android' ? title.toUpperCase() : title;
- const Touchable =
- Platform.OS === 'android' ? TouchableNativeFeedback : TouchableOpacity;
- return (
- <Touchable
- accessibilityLabel={accessibilityLabel}
- accessibilityRole="button"
- accessibilityState={accessibilityState}
- hasTVPreferredFocus={hasTVPreferredFocus}
- nextFocusDown={nextFocusDown}
- nextFocusForward={nextFocusForward}
- nextFocusLeft={nextFocusLeft}
- nextFocusRight={nextFocusRight}
- nextFocusUp={nextFocusUp}
- testID={testID}
- disabled={disabled}
- onPress={onPress}
- touchSoundDisabled={touchSoundDisabled}>
- <View style={buttonStyles}>
- <Text style={textStyles} disabled={disabled}>
- {formattedTitle}
- </Text>
- </View>
- </Touchable>
- );
- }
- }
- const styles = StyleSheet.create({
- button: Platform.select({
- ios: {},
- android: {
- elevation: 4,
- backgroundColor: '#2196F3',
- borderRadius: 2,
- },
- }),
- text: {
- textAlign: 'center',
- margin: 8,
- ...Platform.select({
- ios: {
- color: '#007AFF',
- fontSize: 18,
- },
- android: {
- color: 'white',
- fontWeight: '500',
- },
- }),
- },
- buttonDisabled: Platform.select({
- ios: {},
- android: {
- elevation: 0,
- backgroundColor: '#dfdfdf',
- },
- }),
- textDisabled: Platform.select({
- ios: {
- color: '#cdcdcd',
- },
- android: {
- color: '#a1a1a1',
- },
- }),
- });
- export default Button
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement