const allElement = { id: 'All', title: 'All', }; const TabFilter: React.FC<TabFilterProps> = memo(({ data, onChange, isNeedAll }) => { const [itemsList, setItemsList] = useState(data); const [selectItem, setSelectItem] = useState(isNeedAll ? allElement.id : data[0].id); useEffect(() => { if (isNeedAll && data) { const newData = [allElement, ...data]; setItemsList(newData); } }, [isNeedAll, data]); const Item: React.FC<ItemProps> = memo(({ item }) => { const isselectId = selectItem === item.id; const selectHandler = useCallback(() => { setSelectItem(item.id); onChange(item.id); }, [item.id]); return ( <TouchableOpacity style={styles.item} onPress={selectHandler}> <View style={styles.itemContainer}> <Text size="middle" type="medium" style={{ ...styles.selectText, color: isselectId ? COLORS.primary : COLORS.lightGray, }} numberOfLines={1} > {item.title} </Text> {item.num ? ( <View style={styles.numContainer}> <Text style={styles.number} numberOfLines={1} ellipsizeMode="tail"> {item.num} </Text> </View> ) : null} </View> <View style={{ ...styles.underline, backgroundColor: isselectId ? COLORS.backgroundDark : COLORS.white, }} /> </TouchableOpacity> ); }); return ( <View style={styles.container}> <FlatList data={itemsList} showsHorizontalScrollIndicator={false} // eslint-disable-next-line react-perf/jsx-no-new-function-as-prop keyExtractor={item => item.id} // eslint-disable-next-line react-perf/jsx-no-new-function-as-prop renderItem={({ item }) => <Item item={item} />} horizontal contentContainerStyle={styles.scrollContainer} /> </View> ); });
Зачем? это же просто навигация
Нам она не подошла, пришлось писать самому
Обсуждают сегодня