@@ -10,12 +10,23 @@ export let toYear = newDates.getFullYear();
10
10
export let toMonth = newDates . getMonth ( ) ;
11
11
export let toDays = newDates . getDate ( ) ;
12
12
13
+ interface barState {
14
+ title ?: string ;
15
+ barRightText ?: string ;
16
+ barLeftText ?: string ;
17
+ onPressBarLeft ?: ( ) => void ;
18
+ render ?: React . ReactNode ;
19
+ }
13
20
export interface CalendarProps extends ViewProps {
14
21
// 日历颜色
15
- color : string ;
22
+ color ?: string ;
23
+ bar : barState ;
16
24
}
17
25
const Calendar = ( props : CalendarProps ) => {
18
- const { color = '#329BCB' } = props ;
26
+ const {
27
+ color = '#329BCB' ,
28
+ bar : { render = null , barRightText = '返回' , title = '日历' , barLeftText = '今天' , onPressBarLeft = null } ,
29
+ } = props ;
19
30
20
31
const [ currentYear , setCurrentYear ] = useState < number > ( toYear ) ;
21
32
const [ currentMonth , setCurrentMonth ] = useState < number > ( toMonth ) ;
@@ -31,6 +42,33 @@ const Calendar = (props: CalendarProps) => {
31
42
setNextData ( toMonths [ 2 ] ) ;
32
43
} , [ currentYear , currentMonth ] ) ;
33
44
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
+
34
72
const renderWeekDays = ( ) => {
35
73
let weekdays = [ '日' , '一' , '二' , '三' , '四' , '五' , '六' ] ;
36
74
return weekdays . map ( ( day ) => {
@@ -140,21 +178,7 @@ const Calendar = (props: CalendarProps) => {
140
178
141
179
return (
142
180
< 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 }
158
182
< View style = { styles . calendarHeader } >
159
183
< View style = { styles . calendarHeaderItem } >
160
184
< TouchableOpacity onPress = { ( ) => getCurrentYear ( 'last' ) } >
0 commit comments