2021-09-13 20:41:05 +00:00
|
|
|
import React from 'react';
|
|
|
|
// @ts-ignore
|
|
|
|
import { Pressable, Text, View } from 'react-native';
|
|
|
|
import FastImage from '@rocket.chat/react-native-fast-image';
|
|
|
|
|
|
|
|
import Check from '../../containers/Check';
|
|
|
|
import styles, { ROW_HEIGHT } from './styles';
|
|
|
|
import { themes } from '../../constants/colors';
|
|
|
|
import { isIOS } from '../../utils/deviceInfo';
|
|
|
|
import { withTheme } from '../../theme';
|
|
|
|
|
|
|
|
export { ROW_HEIGHT };
|
|
|
|
|
|
|
|
interface IServerItem {
|
|
|
|
item: {
|
|
|
|
id: string;
|
|
|
|
iconURL: string;
|
|
|
|
name: string;
|
|
|
|
};
|
|
|
|
onPress(): void;
|
2022-01-17 16:10:39 +00:00
|
|
|
onLongPress?(): void;
|
|
|
|
hasCheck?: boolean;
|
|
|
|
theme?: string;
|
2021-09-13 20:41:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const defaultLogo = require('../../static/images/logo.png');
|
|
|
|
|
|
|
|
const ServerItem = React.memo(({ item, onPress, onLongPress, hasCheck, theme }: IServerItem) => (
|
|
|
|
<Pressable
|
|
|
|
onPress={onPress}
|
|
|
|
onLongPress={() => onLongPress?.()}
|
|
|
|
testID={`rooms-list-header-server-${item.id}`}
|
|
|
|
android_ripple={{
|
2022-01-17 16:10:39 +00:00
|
|
|
color: themes[theme!].bannerBackground
|
2021-09-13 20:41:05 +00:00
|
|
|
}}
|
|
|
|
style={({ pressed }: any) => ({
|
2022-01-17 16:10:39 +00:00
|
|
|
backgroundColor: isIOS && pressed ? themes[theme!].bannerBackground : themes[theme!].backgroundColor
|
2021-09-13 20:41:05 +00:00
|
|
|
})}>
|
|
|
|
<View style={styles.serverItemContainer}>
|
|
|
|
{item.iconURL ? (
|
|
|
|
<FastImage
|
|
|
|
source={{
|
|
|
|
uri: item.iconURL,
|
|
|
|
priority: FastImage.priority.high
|
|
|
|
}}
|
|
|
|
// @ts-ignore
|
|
|
|
defaultSource={defaultLogo}
|
|
|
|
style={styles.serverIcon}
|
|
|
|
onError={() => console.log('err_loading_server_icon')}
|
|
|
|
/>
|
|
|
|
) : (
|
|
|
|
<FastImage source={defaultLogo} style={styles.serverIcon} />
|
|
|
|
)}
|
|
|
|
<View style={styles.serverTextContainer}>
|
2022-01-17 16:10:39 +00:00
|
|
|
<Text numberOfLines={1} style={[styles.serverName, { color: themes[theme!].titleText }]}>
|
2021-09-13 20:41:05 +00:00
|
|
|
{item.name || item.id}
|
|
|
|
</Text>
|
2022-01-17 16:10:39 +00:00
|
|
|
<Text numberOfLines={1} style={[styles.serverUrl, { color: themes[theme!].auxiliaryText }]}>
|
2021-09-13 20:41:05 +00:00
|
|
|
{item.id}
|
|
|
|
</Text>
|
|
|
|
</View>
|
2022-03-22 13:53:09 +00:00
|
|
|
{hasCheck ? <Check /> : null}
|
2021-09-13 20:41:05 +00:00
|
|
|
</View>
|
|
|
|
</Pressable>
|
|
|
|
));
|
|
|
|
|
|
|
|
export default withTheme(ServerItem);
|