@@ -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 ( 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 ,
@@ -88,17 +93,16 @@ class CalendarProvider extends Component<Props> {
8893 } ;
8994 } ;
9095
91- setDate = ( date : Date | string , updateSource : UpdateSource ) => {
96+ setDate = ( date : string , updateSource : UpdateSource ) => {
9297 const { setDate} = this . presenter ;
93- const d = date instanceof Date ? date : new Date ( date ) ;
9498
95- const updateState = ( buttonIcon : any ) => {
99+ const updateState = ( buttonIcon : number ) => {
96100 this . setState ( { date, prevDate : this . state . date , updateSource, buttonIcon} , ( ) => {
97- this . animateTodayButton ( d ) ;
101+ this . animateTodayButton ( date ) ;
98102 } ) ;
99103 } ;
100104
101- setDate ( this . props , d , this . state . date , updateState , updateSource ) ;
105+ setDate ( this . props , date , this . state . date , updateState , updateSource ) ;
102106 } ;
103107
104108 setDisabled = ( disabled : boolean ) => {
@@ -113,7 +117,7 @@ class CalendarProvider extends Component<Props> {
113117 setDisabled ( showTodayButton , disabled , this . state . disabled , updateState ) ;
114118 } ;
115119
116- animateTodayButton ( date : Date ) {
120+ animateTodayButton ( date : string ) {
117121 const { shouldAnimateTodayButton, getPositionAnimation} = this . presenter ;
118122
119123 if ( shouldAnimateTodayButton ( this . props ) ) {
0 commit comments