verdnatura-chat/app/presentation/ServerItem/index.js

70 lines
1.9 KiB
JavaScript
Raw Permalink Normal View History

2019-07-18 17:44:02 +00:00
import React from 'react';
import PropTypes from 'prop-types';
import { View, Text, Pressable } from 'react-native';
import FastImage from '@rocket.chat/react-native-fast-image';
2019-07-18 17:44:02 +00:00
import Check from '../../containers/Check';
import styles, { ROW_HEIGHT } from './styles';
2019-12-04 16:39:53 +00:00
import { themes } from '../../constants/colors';
import { isIOS } from '../../utils/deviceInfo';
import { withTheme } from '../../theme';
2019-07-18 17:44:02 +00:00
export { ROW_HEIGHT };
const defaultLogo = require('../../static/images/logo.png');
2019-07-18 17:44:02 +00:00
const ServerItem = React.memo(({
item, onPress, onLongPress, hasCheck, theme
2019-07-18 17:44:02 +00:00
}) => (
<Pressable
2019-12-04 16:39:53 +00:00
onPress={onPress}
onLongPress={() => onLongPress?.()}
2019-12-04 16:39:53 +00:00
testID={`rooms-list-header-server-${ item.id }`}
android_ripple={{
color: themes[theme].bannerBackground
}}
style={({ pressed }) => ({
backgroundColor: isIOS && pressed
? themes[theme].bannerBackground
: themes[theme].backgroundColor
})}
2019-12-04 16:39:53 +00:00
>
2019-07-18 17:44:02 +00:00
<View style={styles.serverItemContainer}>
{item.iconURL
? (
<FastImage
source={{
uri: item.iconURL,
priority: FastImage.priority.high
}}
defaultSource={defaultLogo}
2019-07-18 17:44:02 +00:00
style={styles.serverIcon}
onError={() => console.log('err_loading_server_icon')}
2019-07-18 17:44:02 +00:00
/>
)
: (
<FastImage
source={defaultLogo}
2019-07-18 17:44:02 +00:00
style={styles.serverIcon}
/>
)
}
<View style={styles.serverTextContainer}>
<Text numberOfLines={1} style={[styles.serverName, { color: themes[theme].titleText }]}>{item.name || item.id}</Text>
<Text numberOfLines={1} style={[styles.serverUrl, { color: themes[theme].auxiliaryText }]}>{item.id}</Text>
2019-07-18 17:44:02 +00:00
</View>
{hasCheck ? <Check theme={theme} /> : null}
2019-07-18 17:44:02 +00:00
</View>
</Pressable>
2019-07-18 17:44:02 +00:00
));
ServerItem.propTypes = {
item: PropTypes.object.isRequired,
onPress: PropTypes.func.isRequired,
onLongPress: PropTypes.func,
2019-07-18 17:44:02 +00:00
hasCheck: PropTypes.bool,
2019-12-04 16:39:53 +00:00
theme: PropTypes.string
2019-07-18 17:44:02 +00:00
};
export default withTheme(ServerItem);