@@ -10,12 +10,23 @@ export let toYear = newDates.getFullYear();
1010export let toMonth = newDates . getMonth ( ) ;
1111export let toDays = newDates . getDate ( ) ;
1212
13+ interface barState {
14+ title ?: string ;
15+ barRightText ?: string ;
16+ barLeftText ?: string ;
17+ onPressBarLeft ?: ( ) => void ;
18+ render ?: React . ReactNode ;
19+ }
1320export interface CalendarProps extends ViewProps {
1421 // 日历颜色
15- color : string ;
22+ color ?: string ;
23+ bar : barState ;
1624}
1725const Calendar = ( props : CalendarProps ) => {
18- const { color = '#329BCB' } = props ;
26+ const {
27+ color = '#329BCB' ,
28+ bar : { render = null , barRightText = '返回' , title = '日历' , barLeftText = '今天' , onPressBarLeft = null } ,
29+ } = props ;
1930
2031 const [ currentYear , setCurrentYear ] = useState < number > ( toYear ) ;
2132 const [ currentMonth , setCurrentMonth ] = useState < number > ( toMonth ) ;
@@ -31,6 +42,33 @@ const Calendar = (props: CalendarProps) => {
3142 setNextData ( toMonths [ 2 ] ) ;
3243 } , [ currentYear , currentMonth ] ) ;
3344
45+ /**
46+ * 头部导航栏
47+ * barRightText 左侧文字
48+ * title 标题
49+ * barLeftText 右侧文字
50+ * onPressBarLeft 左侧点击事件
51+ * render 自定义导航栏
52+ */
53+ const renderBar = render ? (
54+ render
55+ ) : (
56+ < View style = { [ styles . header , { backgroundColor : color } ] } >
57+ < TouchableOpacity onPress = { ( ) => onPressBarLeft && onPressBarLeft ( ) } >
58+ < View style = { styles . headerBtn } >
59+ < Icon name = "left" size = { 20 } color = { '#fff' } />
60+ < Text style = { styles . headerText } > { barRightText } </ Text >
61+ </ View >
62+ </ TouchableOpacity >
63+ < View >
64+ < Text style = { styles . headerText } > { title } </ Text >
65+ </ View >
66+ < TouchableOpacity onPress = { ( ) => goToday ( ) } >
67+ < Text style = { styles . headerText } > { barLeftText } </ Text >
68+ </ TouchableOpacity >
69+ </ View >
70+ ) ;
71+
3472 const renderWeekDays = ( ) => {
3573 let weekdays = [ '日' , '一' , '二' , '三' , '四' , '五' , '六' ] ;
3674 return weekdays . map ( ( day ) => {
@@ -140,21 +178,7 @@ const Calendar = (props: CalendarProps) => {
140178
141179 return (
142180 < View style = { { flex : 1 , backgroundColor : '#fff' } } >
143- < View style = { [ styles . header , { backgroundColor : color } ] } >
144- < TouchableOpacity >
145- < View style = { styles . headerBtn } >
146- < Icon name = "left" size = { 20 } color = { '#fff' } />
147- < Text style = { styles . headerText } > Menu</ Text >
148- </ View >
149- </ TouchableOpacity >
150- < View >
151- < Text style = { styles . headerText } > Calendar</ Text >
152- </ View >
153- < TouchableOpacity onPress = { ( ) => goToday ( ) } >
154- < Text style = { styles . headerText } > Today</ Text >
155- </ TouchableOpacity >
156- </ View >
157-
181+ { renderBar }
158182 < View style = { styles . calendarHeader } >
159183 < View style = { styles . calendarHeaderItem } >
160184 < TouchableOpacity onPress = { ( ) => getCurrentYear ( 'last' ) } >
0 commit comments