2019-06-11 14:01:40 +00:00
|
|
|
import React from 'react';
|
|
|
|
import { View, Text, StyleSheet } from 'react-native';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
|
2019-12-04 16:39:53 +00:00
|
|
|
import Touch from '../utils/touch';
|
|
|
|
import { themes } from '../constants/colors';
|
2019-06-11 14:01:40 +00:00
|
|
|
import sharedStyles from '../views/Styles';
|
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
container: {
|
|
|
|
flex: 1,
|
|
|
|
flexDirection: 'row',
|
|
|
|
alignItems: 'center',
|
|
|
|
justifyContent: 'center',
|
2019-12-04 16:39:53 +00:00
|
|
|
height: 46,
|
2019-06-11 14:01:40 +00:00
|
|
|
paddingHorizontal: 15
|
|
|
|
},
|
|
|
|
disabled: {
|
|
|
|
opacity: 0.3
|
|
|
|
},
|
|
|
|
textContainer: {
|
|
|
|
flex: 1,
|
|
|
|
justifyContent: 'center'
|
|
|
|
},
|
|
|
|
title: {
|
|
|
|
fontSize: 16,
|
|
|
|
...sharedStyles.textRegular
|
|
|
|
},
|
|
|
|
subtitle: {
|
|
|
|
fontSize: 14,
|
|
|
|
...sharedStyles.textRegular
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
const Content = React.memo(({
|
2019-12-04 16:39:53 +00:00
|
|
|
title, subtitle, disabled, testID, right, color, theme
|
2019-06-11 14:01:40 +00:00
|
|
|
}) => (
|
|
|
|
<View style={[styles.container, disabled && styles.disabled]} testID={testID}>
|
|
|
|
<View style={styles.textContainer}>
|
2019-12-04 16:39:53 +00:00
|
|
|
<Text style={[styles.title, { color: color || themes[theme].titleText }]}>{title}</Text>
|
2019-06-11 14:01:40 +00:00
|
|
|
{subtitle
|
2019-12-04 16:39:53 +00:00
|
|
|
? <Text style={[styles.subtitle, { color: themes[theme].bodyText }]}>{subtitle}</Text>
|
2019-06-11 14:01:40 +00:00
|
|
|
: null
|
|
|
|
}
|
|
|
|
</View>
|
|
|
|
{right ? right() : null}
|
|
|
|
</View>
|
|
|
|
));
|
|
|
|
|
|
|
|
const Button = React.memo(({
|
|
|
|
onPress, ...props
|
|
|
|
}) => (
|
2019-12-04 16:39:53 +00:00
|
|
|
<Touch
|
2019-06-11 14:01:40 +00:00
|
|
|
onPress={onPress}
|
2019-12-04 16:39:53 +00:00
|
|
|
style={{ backgroundColor: themes[props.theme].backgroundColor }}
|
2019-06-11 14:01:40 +00:00
|
|
|
enabled={!props.disabled}
|
2019-12-04 16:39:53 +00:00
|
|
|
theme={props.theme}
|
2019-06-11 14:01:40 +00:00
|
|
|
>
|
|
|
|
<Content {...props} />
|
2019-12-04 16:39:53 +00:00
|
|
|
</Touch>
|
2019-06-11 14:01:40 +00:00
|
|
|
));
|
|
|
|
|
|
|
|
const Item = React.memo(({ ...props }) => {
|
|
|
|
if (props.onPress) {
|
|
|
|
return <Button {...props} />;
|
|
|
|
}
|
2019-12-04 16:39:53 +00:00
|
|
|
return (
|
|
|
|
<View style={{ backgroundColor: themes[props.theme].backgroundColor }}>
|
|
|
|
<Content {...props} />
|
|
|
|
</View>
|
|
|
|
);
|
2019-06-11 14:01:40 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
Item.propTypes = {
|
2019-12-04 16:39:53 +00:00
|
|
|
onPress: PropTypes.func,
|
|
|
|
theme: PropTypes.string
|
2019-06-11 14:01:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Content.propTypes = {
|
|
|
|
title: PropTypes.string.isRequired,
|
|
|
|
subtitle: PropTypes.string,
|
|
|
|
right: PropTypes.func,
|
|
|
|
disabled: PropTypes.bool,
|
2019-12-04 16:39:53 +00:00
|
|
|
testID: PropTypes.string,
|
|
|
|
theme: PropTypes.string,
|
|
|
|
color: PropTypes.string
|
2019-06-11 14:01:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Button.propTypes = {
|
|
|
|
onPress: PropTypes.func,
|
2019-12-04 16:39:53 +00:00
|
|
|
disabled: PropTypes.bool,
|
|
|
|
theme: PropTypes.string
|
2019-06-11 14:01:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Button.defaultProps = {
|
|
|
|
disabled: false
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Item;
|