Rocket.Chat.ReactNative/app/containers/ListItem.js

100 lines
2.0 KiB
JavaScript
Raw Normal View History

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';
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,
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
}) => (
<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>
{subtitle
2019-12-04 16:39:53 +00:00
? <Text style={[styles.subtitle, { color: themes[theme].bodyText }]}>{subtitle}</Text>
: null
}
</View>
{right ? right() : null}
</View>
));
const Button = React.memo(({
onPress, ...props
}) => (
2019-12-04 16:39:53 +00:00
<Touch
onPress={onPress}
2019-12-04 16:39:53 +00:00
style={{ backgroundColor: themes[props.theme].backgroundColor }}
enabled={!props.disabled}
2019-12-04 16:39:53 +00:00
theme={props.theme}
>
<Content {...props} />
2019-12-04 16:39:53 +00:00
</Touch>
));
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>
);
});
Item.propTypes = {
2019-12-04 16:39:53 +00:00
onPress: PropTypes.func,
theme: PropTypes.string
};
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
};
Button.propTypes = {
onPress: PropTypes.func,
2019-12-04 16:39:53 +00:00
disabled: PropTypes.bool,
theme: PropTypes.string
};
Button.defaultProps = {
disabled: false
};
export default Item;