@@ -16,10 +16,10 @@ const updateSources = commons.UpdateSources;
1616const TOP_POSITION = 65 ;
1717
1818interface Props {
19- /** Initial date in 'yyyy-MM-dd' format. Default = Date() */
20- date : Date ;
19+ /** Initial date in 'yyyy-MM-dd' format. Default = now */
20+ date : XDate ;
2121 /** Callback for date change event */
22- onDateChanged ?: ( ) => Date ;
22+ onDateChanged ?: ( ) => XDate ;
2323 /** Callback for month change event */
2424 onMonthChange ?: ( ) => DateData ;
2525 /** Whether to show the today button */
@@ -43,7 +43,7 @@ class CalendarProvider extends Component<Props> {
4343 static displayName = 'CalendarProvider' ;
4444
4545 static propTypes = {
46- /** Initial date in 'yyyy-MM-dd' format. Default = Date() */
46+ /** Initial date in 'yyyy-MM-dd' format. Default = now */
4747 date : PropTypes . any . isRequired ,
4848 /** Callback for date change event */
4949 onDateChanged : PropTypes . func ,
@@ -62,22 +62,27 @@ class CalendarProvider extends Component<Props> {
6262 style = styleConstructor ( this . props . theme ) ;
6363 presenter = new Presenter ( ) ;
6464
65+
6566 state = {
66- prevDate : this . props . date || toMarkingFormat ( new XDate ( ) ) ,
67- date : this . props . date || toMarkingFormat ( new XDate ( ) ) ,
67+ prevDate : this . getDate ( this . props . date ) ,
68+ date : this . getDate ( this . props . date ) ,
6869 updateSource : updateSources . CALENDAR_INIT ,
6970 buttonY : new Animated . Value ( this . props . todayBottomMargin ? - this . props . todayBottomMargin : - TOP_POSITION ) ,
70- buttonIcon : this . presenter . getButtonIcon ( this . props . date , this . props . showTodayButton ) ,
71+ buttonIcon : this . presenter . getButtonIcon ( this . getDate ( this . props . date ) , this . props . showTodayButton ) ,
7172 disabled : false ,
7273 opacity : new Animated . Value ( 1 )
7374 } ;
7475
7576 componentDidUpdate ( prevProps : Props ) {
76- if ( prevProps . date !== this . props . date ) {
77- this . setDate ( toMarkingFormat ( new XDate ( this . props . date ) ) , updateSources . PROP_UPDATE ) ;
77+ if ( this . props . date && prevProps . date !== this . props . date ) {
78+ this . setDate ( toMarkingFormat ( this . props . date ) , updateSources . PROP_UPDATE ) ;
7879 }
7980 }
8081
82+ getDate ( date : XDate ) {
83+ return toMarkingFormat ( date || new XDate ( ) ) ;
84+ }
85+
8186 getProviderContextValue = ( ) => {
8287 return {
8388 setDate : this . setDate ,
0 commit comments