// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. import React, {useCallback} from 'react'; import {type StyleProp, Text, type TextStyle, TouchableHighlight, View, type ViewStyle} from 'react-native'; import FastImage, {type ImageStyle, type Source} from 'react-native-fast-image'; import CompassIcon from '@components/compass_icon'; import {useTheme} from '@context/theme'; import {preventDoubleTap} from '@utils/tap'; import {changeOpacity, makeStyleSheetFromTheme} from '@utils/theme'; import {typography} from '@utils/typography'; import {isValidUrl} from '@utils/url'; type SlideUpPanelProps = { destructive?: boolean; icon?: string | Source; rightIcon?: boolean; imageStyles?: StyleProp; iconStyles?: StyleProp; onPress: () => void; textStyles?: TextStyle; testID?: string; text: string; } export const ITEM_HEIGHT = 48; const getStyleSheet = makeStyleSheetFromTheme((theme: Theme) => { return { container: { height: ITEM_HEIGHT, marginHorizontal: -20, paddingHorizontal: 20, }, destructive: { color: theme.dndIndicator, }, row: { width: '100%', flexDirection: 'row', }, iconContainer: { height: ITEM_HEIGHT, justifyContent: 'center', marginRight: 10, }, noIconContainer: { height: ITEM_HEIGHT, width: 18, }, icon: { color: changeOpacity(theme.centerChannelColor, 0.56), }, textContainer: { justifyContent: 'center', flex: 1, height: ITEM_HEIGHT, marginRight: 5, }, text: { color: theme.centerChannelColor, ...typography('Body', 200, 'Regular'), }, }; }); const SlideUpPanelItem = ({destructive, icon, imageStyles, onPress, testID, text, textStyles, iconStyles, rightIcon = false}: SlideUpPanelProps) => { const theme = useTheme(); const handleOnPress = useCallback(preventDoubleTap(onPress, 500), []); const style = getStyleSheet(theme); let image; let iconStyle: StyleProp = [style.iconContainer]; if (icon) { if (typeof icon === 'object') { if (icon.uri && isValidUrl(icon.uri)) { const imageStyle: StyleProp = [imageStyles]; imageStyle.push({width: 24, height: 24}); image = ( ); } else { iconStyle = [style.noIconContainer]; } } else { const compassIconStyle = [style.icon, iconStyles]; if (destructive) { compassIconStyle.push(style.destructive); } image = ( ); } } return ( {Boolean(image) && !rightIcon && {image} } {text} {Boolean(image) && rightIcon && {image} } ); }; export default SlideUpPanelItem;