import React, { useContext } from 'react'; import { Animated, Dimensions, StyleSheet, TouchableOpacity, View, } from 'react-native'; import { ApplicationContext, MiniAppContext } from '../../Context'; import { exportFontFamily, Text, useScaleSize } from '../../Text'; import { Colors, Radius, Spacing, Styles } from '../../Consts'; import { TitleJourneyProps, TitleLocationProps, TitleUserProps, } from '../types'; import { Image } from '../../Image'; import { Icon } from '../../Icon'; import { Skeleton } from '../../Skeleton'; /** * default header title used for nav */ const HeaderTitle: React.FC = props => { const context = useContext(MiniAppContext); const showBaseLineDebug = context?.features?.showBaseLineDebug ?? false; const opacity = props.animatedValue?.interpolate( props.interpolate ?? { inputRange: [0, 200], outputRange: [0, 1], extrapolate: 'clamp', }, ); return ( ); }; /** * Title custom for header * @constructor */ const TitleCustom: React.FC = ({ type, data, ...props }) => { switch (type) { case 'user': return ; case 'location': return ; case 'journey': return ; default: return ; } }; /** * Header user title * @constructor */ const TitleUser: React.FC = ({ title, subTitle, image: image, tintColor, dotColor, onPress, verify, icons, isLoading, }) => { const { theme } = useContext(ApplicationContext); const maxWidth = Dimensions.get('window').width - 172; const getShortName = (name: string) => { const words = name.split(' '); const lastTwoWords = words.slice(-2); return lastTwoWords.map(word => word.charAt(0).toUpperCase()).join(''); }; const renderImage = () => { const avatarWidth = Spacing.XXL; if (Array.isArray(image) && image.length > 0) { switch (image.length) { case 1: { return image.map((i: string) => ( )); } case 2: { return ( ); } case 3: { return ( ); } case 4: { return ( ); } default: { return ( {`+${image.length - 3}`} ); } } } if (typeof image === 'string' && image) { return ; } return ( {getShortName(title)} ); }; const renderVerifyIcon = () => { if (icons && icons.length > 0) { return ( {icons.map(icon => ( ))} ); } }; const renderShimmer = () => { return ( ); }; if (verify) { console.warn(`Warning: The verify value "${verify}" is deprecated.`); } if (isLoading) { return renderShimmer(); } return ( {renderImage()} {!!dotColor && ( )} {title} {renderVerifyIcon()} {!!subTitle && ( {subTitle} )} ); }; /** * Header user title * @constructor */ const TitleLocation: React.FC = ({ tintColor, location, description, onPress, isLoading, }) => { const maxWidth = Dimensions.get('window').width - 172; const renderShimmer = () => { return ( ); }; if (isLoading) { return renderShimmer(); } return ( {!!description && ( {description} )} {location} ); }; /** * Header user title * @constructor */ const TitleJourney: React.FC = ({ start, end, description, icon, iconColor, tintColor, onPress, isLoading, }) => { const { width } = Dimensions.get('screen'); const maxWidth = Dimensions.get('window').width - 172; const startWidth = width * 0.25; const endWidth = width * 0.75 - 212; const renderShimmer = () => { return ( ); }; if (isLoading) { return renderShimmer(); } return ( {start} {!!end && ( {end} )} {!!description && ( {description} )} ); }; const styles = StyleSheet.create({ rowJourney: { flexDirection: 'row', width: '100%', alignItems: 'flex-start' }, verifiedDot: { width: 4, height: 4, borderRadius: 2, backgroundColor: Colors.green_03, position: 'absolute', alignSelf: 'center', }, circle: { width: 32, height: 32, borderRadius: 16, borderWidth: 0.5, borderColor: Colors.black_04, }, circleMedium: { width: 24, height: 24, borderRadius: 16, borderWidth: 0.5, borderColor: Colors.black_04, }, circleSmall: { width: 16, height: 16, borderRadius: 16, borderWidth: 0.5, borderColor: Colors.black_04, }, groupAvtContainer: { width: Spacing.XXL, height: Spacing.XXL, position: 'relative', }, imageContainer: { width: 32, height: 32, borderRadius: 16, backgroundColor: Colors.pink_09, borderWidth: 0.5, justifyContent: 'center', alignItems: 'center', overflow: 'hidden', }, dotAvatar: { position: 'absolute', width: 12, height: 12, borderRadius: 6, bottom: -2, right: -2, borderWidth: 2, borderColor: Colors.black_01, }, verifiedIcon: { width: 16, height: 16, marginLeft: Spacing.XS }, shimmerTitle: { height: 18, width: 120, borderRadius: Radius.XS, overflow: 'hidden', }, shimmerDescription: { height: 12, width: 120, borderRadius: Radius.XS, overflow: 'hidden', }, debugBaseLine: { borderWidth: 1, borderColor: Colors.green_06 }, }); export { HeaderTitle, TitleCustom };