import React, { ComponentProps } from 'react'; import { Pressable, StyleProp, StyleSheet, View, ViewStyle } from 'react-native'; import { Icon, Typo } from '../../foundation'; import { isNotNil } from '../../internal/utils/functions'; import { formatNumber } from '../../internal/utils/numberUtils'; import { Tabs } from './Tabs'; import { TabItem } from './types'; import { NotificationDot } from '../notificationDot/NotificationDot'; type TabsProps = ComponentProps; type TypoProps = ComponentProps; /** * Tabs 컴포넌트에서 사용하는 탭 아이템 컴포넌트 */ export function TabItemView({ size, item, isActive, onLayout, index, style, }: { size: TabsProps['size']; item: TabItem; isActive: boolean; onLayout?: (x: number, width: number) => void; index: number; style?: StyleProp; }) { function getTypoColor() { if (item.disabled) return 'text_quaternary'; return isActive ? 'text_primary' : 'text_tertiary'; } return ( { onLayout?.(nativeEvent.layout.x, nativeEvent.layout.width); }} key={item.label} disabled={item.disabled} onPress={() => item.onPress?.(index)} style={[tabItemStyles.flexRow, style]}> {size === 'large' ? ( ) : ( )} ); } const tabItemStyles = StyleSheet.create({ flexRow: { flexDirection: 'row' }, flexGrow: { flexGrow: 1, flexShrink: 0 }, labelContainer: { flex: 1, flexDirection: 'row', justifyContent: 'center', alignItems: 'center', paddingHorizontal: 4, }, }); // 라벨영역 오른쪽에 추가로 표시할 수 있는 뷰 function LabelRightView({ item, size, typoColor, }: { item: TabItem; size: TabsProps['size']; typoColor?: TypoProps['color']; }): React.JSX.Element | null { if (!item.rightSlot && !item.redDot && !item.iconName) return null; return ( <> {item.iconName ? ( ) : null} {item.rightSlot ? ( {item.rightSlot} ) : null} ); } const labelRightStyles = StyleSheet.create({ iconContainer: { justifyContent: 'center', marginLeft: 4 }, rightSlotContainer: { height: '100%', flexDirection: 'row' }, }); // 카운트를 포함하여 탭 아이템의 라벨을 표현하는 컴포넌트 function LabelWithCount({ label, count, typoType, typoColor, redDot, }: { label: string; count: number | undefined; typoType: TypoProps['type']; typoColor?: TypoProps['color']; redDot?: boolean; }): React.JSX.Element { return ( {label} {isNotNil(count) ? ( <> {formatNumber(count)} ) : null} {redDot ? : null} ); }