import React from 'react'; import { StyleProp, Text, TouchableWithoutFeedback, View, ViewStyle } from 'react-native'; import Icon from '../icon'; import { WithTheme, WithThemeStyles } from '../style'; import Marquee, { MarqueeProps } from './Marquee'; import { NoticeBarPropsType } from './PropsType'; import NoticeStyles, { NoticeBarStyle } from './style'; export interface NoticeNativeProps extends NoticeBarPropsType, WithThemeStyles { marqueeProps?: MarqueeProps; style?: StyleProp; } export default class NoticeBar extends React.Component { static defaultProps = { mode: '', onPress() {}, }; constructor(props: NoticeNativeProps) { super(props); this.state = { show: true, }; } onPress = () => { const { mode, onPress } = this.props; if (onPress) { onPress(); } if (mode === 'closable') { this.setState({ show: false, }); } }; render() { let { children, mode, icon, style, action, marqueeProps } = this.props; return ( {(styles, theme) => { let operationDom: any = null; icon = typeof icon === 'undefined' ? ( // @ts-ignore ) : ( icon ); if (mode === 'closable') { operationDom = ( {action ? action : ×} ); } else if (mode === 'link') { operationDom = ( {action ? action : } ); } const main = ( {icon && {icon}} {operationDom} ); return this.state.show ? ( mode === 'closable' ? ( main ) : ( {main} ) ) : null; }} ); } }