2018-04-24 19:34:03 +00:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2019-12-04 16:39:53 +00:00
|
|
|
import { StyleSheet, Text } from 'react-native';
|
2020-02-11 14:01:35 +00:00
|
|
|
import Touchable from 'react-native-platform-touchable';
|
2018-04-24 19:34:03 +00:00
|
|
|
|
2019-12-04 16:39:53 +00:00
|
|
|
import { themes } from '../../constants/colors';
|
2018-11-14 21:42:03 +00:00
|
|
|
import sharedStyles from '../../views/Styles';
|
2019-12-04 16:39:53 +00:00
|
|
|
import ActivityIndicator from '../ActivityIndicator';
|
2018-04-24 19:34:03 +00:00
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
container: {
|
2018-11-14 21:42:03 +00:00
|
|
|
paddingHorizontal: 15,
|
2018-08-10 17:26:36 +00:00
|
|
|
justifyContent: 'center',
|
2018-11-14 21:42:03 +00:00
|
|
|
height: 48,
|
|
|
|
borderRadius: 2,
|
|
|
|
marginBottom: 10
|
2018-04-24 19:34:03 +00:00
|
|
|
},
|
|
|
|
text: {
|
2018-11-14 21:42:03 +00:00
|
|
|
fontSize: 18,
|
2018-11-19 18:18:15 +00:00
|
|
|
textAlign: 'center'
|
2018-04-24 19:34:03 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
export default class Button extends React.PureComponent {
|
|
|
|
static propTypes = {
|
2018-11-14 21:42:03 +00:00
|
|
|
title: PropTypes.oneOfType([PropTypes.string, PropTypes.element]),
|
2018-04-24 19:34:03 +00:00
|
|
|
type: PropTypes.string,
|
|
|
|
onPress: PropTypes.func,
|
2018-07-17 19:10:27 +00:00
|
|
|
disabled: PropTypes.bool,
|
2018-08-10 17:26:36 +00:00
|
|
|
backgroundColor: PropTypes.string,
|
2018-11-19 18:18:15 +00:00
|
|
|
loading: PropTypes.bool,
|
2019-12-04 16:39:53 +00:00
|
|
|
theme: PropTypes.string,
|
2018-11-19 18:18:15 +00:00
|
|
|
style: PropTypes.any
|
2018-04-24 19:34:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static defaultProps = {
|
|
|
|
title: 'Press me!',
|
|
|
|
type: 'primary',
|
|
|
|
onPress: () => alert('It works!'),
|
2018-08-10 17:26:36 +00:00
|
|
|
disabled: false,
|
|
|
|
loading: false
|
2018-04-24 19:34:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const {
|
2019-12-04 16:39:53 +00:00
|
|
|
title, type, onPress, disabled, backgroundColor, loading, style, theme, ...otherProps
|
2018-04-24 19:34:03 +00:00
|
|
|
} = this.props;
|
2019-12-04 16:39:53 +00:00
|
|
|
const isPrimary = type === 'primary';
|
2018-04-24 19:34:03 +00:00
|
|
|
return (
|
2020-02-11 14:01:35 +00:00
|
|
|
<Touchable
|
2018-04-24 19:34:03 +00:00
|
|
|
onPress={onPress}
|
2020-02-11 14:01:35 +00:00
|
|
|
disabled={disabled || loading}
|
2018-11-14 21:42:03 +00:00
|
|
|
style={[
|
|
|
|
styles.container,
|
2019-12-04 16:39:53 +00:00
|
|
|
backgroundColor
|
|
|
|
? { backgroundColor }
|
|
|
|
: { backgroundColor: isPrimary ? themes[theme].actionTintColor : themes[theme].backgroundColor },
|
|
|
|
disabled && { backgroundColor: themes[theme].borderColor },
|
2018-11-19 18:18:15 +00:00
|
|
|
style
|
2018-11-14 21:42:03 +00:00
|
|
|
]}
|
2018-05-23 13:39:18 +00:00
|
|
|
{...otherProps}
|
2018-04-24 19:34:03 +00:00
|
|
|
>
|
2018-11-14 21:42:03 +00:00
|
|
|
{
|
|
|
|
loading
|
2019-12-04 16:39:53 +00:00
|
|
|
? <ActivityIndicator color={isPrimary ? themes[theme].buttonText : themes[theme].actionTintColor} />
|
|
|
|
: (
|
|
|
|
<Text
|
|
|
|
style={[
|
|
|
|
styles.text,
|
|
|
|
isPrimary ? sharedStyles.textMedium : sharedStyles.textBold,
|
|
|
|
{ color: isPrimary ? themes[theme].buttonText : themes[theme].actionTintColor }
|
|
|
|
]}
|
|
|
|
>
|
|
|
|
{title}
|
|
|
|
</Text>
|
|
|
|
)
|
2018-11-14 21:42:03 +00:00
|
|
|
}
|
2020-02-11 14:01:35 +00:00
|
|
|
</Touchable>
|
2018-04-24 19:34:03 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|