11import React , { useEffect , useState } from 'react' ;
2- import { View , Text , ViewProps , TextProps , StyleSheet , TouchableOpacity , Dimensions , Platform } from 'react-native' ;
2+ import { View , Text , ViewProps , StyleSheet , TouchableOpacity , Dimensions , Platform } from 'react-native' ;
33import Icon from '../Icon' ;
44import Ellipsis from '../Ellipsis' ;
55import { getMonths , getWeeksArray , daysArrProps , getType , getNameLen } from './utils' ;
@@ -22,11 +22,14 @@ interface BarState {
2222export interface CalendarProps extends ViewProps {
2323 // 日历颜色
2424 color : string ;
25- //是否显示农历及假日
25+ // 是否显示农历及假日
2626 lunarHoliday : boolean ;
2727 bar ?: BarState ;
28- //农历详情
28+ // 是否显示农历详情
2929 showLunar : boolean ;
30+ onChange ?: ( value : string ) => void ;
31+ // 是否显示头部导航栏
32+ showBar ?: boolean ;
3033}
3134
3235const Calendar = ( props : CalendarProps ) => {
@@ -37,7 +40,7 @@ const Calendar = (props: CalendarProps) => {
3740 onPressBarLeft : undefined ,
3841 render : undefined ,
3942 } ;
40- const { color = '#329BCB' , lunarHoliday = false , bar = bars , showLunar = false } = props ;
43+ const { color = '#329BCB' , lunarHoliday = false , bar = bars , showLunar = false , onChange , showBar = true } = props ;
4144 const { barRightText, title, barLeftText, onPressBarLeft, render } = bar ;
4245 const [ currentYear , setCurrentYear ] = useState < number > ( toYear ) ;
4346 const [ currentMonth , setCurrentMonth ] = useState < number > ( toMonth ) ;
@@ -52,7 +55,9 @@ const Calendar = (props: CalendarProps) => {
5255 setLastData ( toMonths [ 0 ] ) ;
5356 setDayData ( toMonths [ 1 ] ) ;
5457 setNextData ( toMonths [ 2 ] ) ;
55- } , [ currentYear , currentMonth ] ) ;
58+ const date = currentYear + '-' + ( currentMonth + 1 ) + '-' + currentDays ;
59+ onChange ?.( date ) ;
60+ } , [ currentYear , currentMonth , currentDays ] ) ;
5661
5762 /**
5863 * 头部导航栏
@@ -127,10 +132,10 @@ const Calendar = (props: CalendarProps) => {
127132 lunarAll . type === 1
128133 ? [ styles . dateBase , styles . otherMonth ]
129134 : lunarAll . type === 2
130- ? [ styles . currentMonth , styles . dateBase , { backgroundColor : color } ]
131- : lunarAll . type === 3
132- ? [ styles . selectMonth , styles . dateBase , { borderColor : color } ]
133- : styles . dateBase
135+ ? [ styles . currentMonth , styles . dateBase , { backgroundColor : color } ]
136+ : lunarAll . type === 3
137+ ? [ styles . selectMonth , styles . dateBase , { borderColor : color } ]
138+ : styles . dateBase
134139 }
135140 onPress = { ( ) => goSelectDay ( day ) }
136141 >
@@ -218,7 +223,7 @@ const Calendar = (props: CalendarProps) => {
218223 return (
219224 < View style = { { flex : 1 , position : 'relative' } } >
220225 < View style = { { flex : 1 , backgroundColor : '#fff' } } >
221- { renderBar }
226+ { showBar && renderBar }
222227 < View style = { styles . calendarHeader } >
223228 < View style = { styles . calendarHeaderItem } >
224229 < TouchableOpacity onPress = { ( ) => getCurrentYear ( 'last' ) } >
0 commit comments