2019-07-18 17:44:02 +00:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2021-01-20 20:43:59 +00:00
|
|
|
import { View, Text, Pressable } from 'react-native';
|
2020-07-17 17:39:06 +00:00
|
|
|
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';
|
2021-01-20 20:43:59 +00:00
|
|
|
import { isIOS } from '../../utils/deviceInfo';
|
|
|
|
import { withTheme } from '../../theme';
|
2019-07-18 17:44:02 +00:00
|
|
|
|
|
|
|
export { ROW_HEIGHT };
|
|
|
|
|
2021-01-20 20:43:59 +00:00
|
|
|
const defaultLogo = require('../../static/images/logo.png');
|
|
|
|
|
2019-07-18 17:44:02 +00:00
|
|
|
const ServerItem = React.memo(({
|
2021-01-20 20:43:59 +00:00
|
|
|
item, onPress, onLongPress, hasCheck, theme
|
2019-07-18 17:44:02 +00:00
|
|
|
}) => (
|
2021-01-20 20:43:59 +00:00
|
|
|
<Pressable
|
2019-12-04 16:39:53 +00:00
|
|
|
onPress={onPress}
|
2021-01-20 20:43:59 +00:00
|
|
|
onLongPress={() => onLongPress?.()}
|
2019-12-04 16:39:53 +00:00
|
|
|
testID={`rooms-list-header-server-${ item.id }`}
|
2021-01-20 20:43:59 +00:00
|
|
|
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
|
|
|
|
}}
|
2021-01-20 20:43:59 +00:00
|
|
|
defaultSource={defaultLogo}
|
2019-07-18 17:44:02 +00:00
|
|
|
style={styles.serverIcon}
|
2019-08-30 12:43:23 +00:00
|
|
|
onError={() => console.log('err_loading_server_icon')}
|
2019-07-18 17:44:02 +00:00
|
|
|
/>
|
|
|
|
)
|
|
|
|
: (
|
|
|
|
<FastImage
|
2021-01-20 20:43:59 +00:00
|
|
|
source={defaultLogo}
|
2019-07-18 17:44:02 +00:00
|
|
|
style={styles.serverIcon}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
<View style={styles.serverTextContainer}>
|
2021-01-20 20:43:59 +00:00
|
|
|
<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>
|
2021-01-20 20:43:59 +00:00
|
|
|
{hasCheck ? <Check theme={theme} /> : null}
|
2019-07-18 17:44:02 +00:00
|
|
|
</View>
|
2021-01-20 20:43:59 +00:00
|
|
|
</Pressable>
|
2019-07-18 17:44:02 +00:00
|
|
|
));
|
|
|
|
|
|
|
|
ServerItem.propTypes = {
|
|
|
|
item: PropTypes.object.isRequired,
|
2021-01-20 20:43:59 +00:00
|
|
|
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
|
|
|
};
|
|
|
|
|
2021-01-20 20:43:59 +00:00
|
|
|
export default withTheme(ServerItem);
|