1- import React , { Component } from 'react' ;
1+ import React , { useState } from 'react' ;
22import { StyleProp , Text , TouchableWithoutFeedback , View , ViewStyle , StyleSheet } from 'react-native' ;
33import Icon from '../Icon' ;
44import Marquee , { MarqueeProps } from './Marquee'
@@ -14,32 +14,24 @@ export type NoticeBarProps = {
1414 marqueeProps ?: MarqueeProps
1515} ;
1616
17- export default class NoticeBar extends Component < NoticeBarProps > {
18- constructor ( props :any ) {
19- super ( props )
20- this . state = {
21- show : true ,
22- }
23- }
17+ export default ( props : NoticeBarProps ) => {
18+ const [ show , setShow ] = useState ( true ) ;
2419
25- onPress = ( ) => {
26- const { mode, onPress } = this . props
20+ const onPress = ( ) => {
21+ const { mode, onPress } = props
2722 if ( onPress ) {
28- onPress ( )
23+ onPress ( ) ;
2924 }
3025 if ( mode === 'closable' ) {
31- this . setState ( {
32- show : false ,
33- } )
26+ setShow ( false )
3427 }
3528 }
36- render ( ) {
37- let { children, mode, icon, style, action, marqueeProps } = this . props ;
29+ let { children, mode, icon, style, action, marqueeProps } = props ;
3830 let operationDom : any = null ;
39- icon = typeof icon === 'undefined' ? ( < Icon fill = "notification" color = "#f4333c" /> ) : ( icon ) ;
31+ icon = typeof icon === 'undefined' ? ( < Icon name = "notification" color = "#f4333c" size = { 15 } /> ) : ( icon ) ;
4032 if ( mode === 'closable' ) {
4133 operationDom = (
42- < TouchableWithoutFeedback onPress = { this . onPress } >
34+ < TouchableWithoutFeedback onPress = { onPress } >
4335 < View style = { styles . actionWrap } >
4436 { action ? action : < Text style = { [ styles . close ] } > ×</ Text > }
4537 </ View >
@@ -65,15 +57,14 @@ export default class NoticeBar extends Component<NoticeBarProps>{
6557 </ View >
6658 { operationDom }
6759 </ View >
68- )
69- return (
70- < View >
71- { mode === 'closable' ? ( main ) : (
72- < TouchableWithoutFeedback onPress = { this . onPress } > { main } </ TouchableWithoutFeedback >
73- ) }
74- </ View >
7560 )
76- }
61+ return (
62+ < View >
63+ { show ? ( mode === 'closable' ? ( main ) : (
64+ < TouchableWithoutFeedback onPress = { onPress } > { main } </ TouchableWithoutFeedback >
65+ ) ) : null }
66+ </ View >
67+ )
7768}
7869
7970const styles = StyleSheet . create ( {
@@ -83,6 +74,7 @@ const styles = StyleSheet.create({
8374 overflow : 'hidden' ,
8475 flexDirection : 'row' ,
8576 alignItems : 'center' ,
77+ color : '#f4333c' ,
8678 } ,
8779 container : {
8880 flex : 1 ,
@@ -98,7 +90,7 @@ const styles = StyleSheet.create({
9890 marginLeft : 5 ,
9991 } ,
10092 left15 : {
101- // marginLeft: 15,
93+ marginLeft : 15 ,
10294 } ,
10395 actionWrap : {
10496 marginRight : 15 ,
0 commit comments