vn-verdnaturachat/app/views/OnboardingView/Button.js

62 lines
1.9 KiB
JavaScript
Raw Normal View History

import React from 'react';
import PropTypes from 'prop-types';
import { View, Text, TouchableWithoutFeedback } from 'react-native';
import styles from './styles';
2019-12-04 16:39:53 +00:00
import { themes } from '../../constants/colors';
import DisclosureIndicator from '../../containers/DisclosureIndicator';
export default class Button extends React.PureComponent {
static propTypes = {
title: PropTypes.string,
subtitle: PropTypes.string,
type: PropTypes.string,
2019-12-04 16:39:53 +00:00
theme: PropTypes.string,
icon: PropTypes.node.isRequired,
testID: PropTypes.string.isRequired,
onPress: PropTypes.func
}
static defaultProps = {
title: 'Press me!',
type: 'primary',
onPress: () => alert('It works!')
}
state = {
active: false
};
render() {
const {
2019-12-04 16:39:53 +00:00
title, subtitle, type, onPress, icon, testID, theme
} = this.props;
const { active } = this.state;
const activeStyle = active && styles.buttonActive;
2019-12-04 16:39:53 +00:00
const isPrimary = (type === 'primary');
const buttonContainerStyle = {
backgroundColor: isPrimary ? themes[theme].actionTintColor : themes[theme].focusedBackground,
borderColor: isPrimary ? themes[theme].actionTintColor : themes[theme].borderColor
};
return (
<TouchableWithoutFeedback
onPress={onPress}
onPressIn={() => this.setState({ active: true })}
onPressOut={() => this.setState({ active: false })}
testID={testID}
>
2019-12-04 16:39:53 +00:00
<View style={[styles.buttonContainer, buttonContainerStyle]}>
<View style={styles.buttonIconContainer}>
{icon}
</View>
<View style={styles.buttonCenter}>
2019-12-04 16:39:53 +00:00
<Text style={[styles.buttonTitle, { color: isPrimary ? themes[theme].buttonText : themes[theme].tintColor }, activeStyle]}>{title}</Text>
{subtitle ? <Text style={[styles.buttonSubtitle, activeStyle, { color: themes[theme].auxiliaryText }]}>{subtitle}</Text> : null}
</View>
2019-12-04 16:39:53 +00:00
{type === 'secondary' ? <DisclosureIndicator theme={theme} /> : null}
</View>
</TouchableWithoutFeedback>
);
}
}