2022-04-07 17:07:16 +00:00
|
|
|
import React from 'react';
|
|
|
|
import { Pressable, Text, View } from 'react-native';
|
2022-05-31 16:08:18 +00:00
|
|
|
import FastImage from 'react-native-fast-image';
|
2022-04-07 17:07:16 +00:00
|
|
|
|
|
|
|
import Check from '../Check';
|
|
|
|
import styles, { ROW_HEIGHT } from './styles';
|
|
|
|
import { themes } from '../../lib/constants';
|
2022-06-06 14:17:51 +00:00
|
|
|
import { isIOS } from '../../lib/methods/helpers';
|
2022-04-07 17:07:16 +00:00
|
|
|
import { useTheme } from '../../theme';
|
|
|
|
|
|
|
|
export { ROW_HEIGHT };
|
|
|
|
|
2022-08-19 19:53:40 +00:00
|
|
|
export interface IServerItem {
|
2023-10-19 13:38:57 +00:00
|
|
|
item: {
|
|
|
|
id: string;
|
|
|
|
iconURL: string;
|
|
|
|
name: string;
|
|
|
|
useRealName?: boolean;
|
|
|
|
};
|
2022-04-07 17:07:16 +00:00
|
|
|
onPress(): void;
|
|
|
|
onLongPress?(): void;
|
|
|
|
hasCheck?: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
const defaultLogo = require('../../static/images/logo.png');
|
|
|
|
|
|
|
|
const ServerItem = React.memo(({ item, onPress, onLongPress, hasCheck }: IServerItem) => {
|
|
|
|
const { theme } = useTheme();
|
|
|
|
return (
|
|
|
|
<Pressable
|
|
|
|
onPress={onPress}
|
|
|
|
onLongPress={() => onLongPress?.()}
|
|
|
|
testID={`rooms-list-header-server-${item.id}`}
|
|
|
|
android_ripple={{ color: themes[theme].bannerBackground }}
|
|
|
|
style={({ pressed }: { pressed: boolean }) => ({
|
|
|
|
backgroundColor: isIOS && pressed ? themes[theme].bannerBackground : themes[theme].backgroundColor
|
2022-08-08 21:02:08 +00:00
|
|
|
})}
|
|
|
|
>
|
2022-04-07 17:07:16 +00:00
|
|
|
<View style={styles.serverItemContainer}>
|
|
|
|
{item.iconURL ? (
|
|
|
|
<FastImage
|
|
|
|
source={{
|
|
|
|
uri: item.iconURL,
|
|
|
|
priority: FastImage.priority.high
|
|
|
|
}}
|
|
|
|
// @ts-ignore TODO: Remove when updating FastImage
|
|
|
|
defaultSource={defaultLogo}
|
|
|
|
style={styles.serverIcon}
|
|
|
|
onError={() => console.log('err_loading_server_icon')}
|
|
|
|
/>
|
|
|
|
) : (
|
|
|
|
<FastImage source={defaultLogo} 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>
|
|
|
|
</View>
|
|
|
|
{hasCheck ? <Check /> : null}
|
|
|
|
</View>
|
|
|
|
</Pressable>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
export default ServerItem;
|