import React, { forwardRef, useState } from 'react'; import { View, TouchableWithoutFeedback } from 'react-native'; import Icon, { IconNames } from '@pingtou/rn-vant-icons'; import { useThemeFactory } from '../Theme'; import { createStyle } from './style'; import Marquee from './Marquee'; import type { NoticeBarInstance, NoticeBarProps } from './interface'; const NoticeBar = forwardRef((props, ref) => { const { style, wrapable, background, color, mode, onClose, leftIcon, rightIcon, onPress, ...rest } = props; const [show, setShow] = useState(true); const { styles, theme } = useThemeFactory(createStyle); const iconSize = theme.notice_bar_icon_size; const iconColor = color || theme.notice_bar_text_color; const getRightIconName = (): IconNames | undefined => { if (mode === 'closeable') { return 'cross'; } if (mode === 'link') { return 'arrow'; } return undefined; }; const onPressRightIcon = () => { if (mode === 'closeable') { setShow(false); onClose?.(); } }; const renderLeftIcon = () => { if (typeof leftIcon !== 'string' && React.isValidElement(leftIcon)) { return leftIcon; } if (leftIcon) { return ( ); } return null; }; // 右侧图标 const renderRightIcon = () => { if (rightIcon) { return rightIcon; } const name = getRightIconName(); if (name) { return ( ); } return null; }; if (!show) { return null; } return ( {renderLeftIcon()} {renderRightIcon()} ); }); export default NoticeBar;