@momo-kits/calendar 0.0.34-beta → 0.0.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -1 +1,4 @@
1
- var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.default=void 0;var _Calendar=_interopRequireDefault(require("./src/Calendar"));var _default=_Calendar.default;exports.default=_default;
1
+ import Calendar from './src/Calendar';
2
+ import CalendarPicker from './src/calendarPicker/index';
3
+
4
+ export { Calendar, CalendarPicker };
package/package.json CHANGED
@@ -1,23 +1,18 @@
1
1
  {
2
2
  "name": "@momo-kits/calendar",
3
- "version": "0.0.34-beta",
3
+ "version": "0.0.36",
4
4
  "private": false,
5
5
  "main": "index.js",
6
- "dependencies": {},
6
+ "dependencies": {
7
+ "@momo-kits/date-picker": "latest",
8
+ "moment": "^2.24.0"
9
+ },
7
10
  "peerDependencies": {
8
11
  "react": "16.9.0",
9
12
  "react-native": ">=0.55",
10
13
  "prop-types": "^15.7.2",
11
- "moment": "^2.24.0",
12
14
  "@momo-kits/core": ">=0.0.5-beta"
13
15
  },
14
- "devDependencies": {
15
- "metro-react-native-babel-preset": "^0.64.0",
16
- "@babel/core": "^7.12.9",
17
- "@babel/runtime": "^7.12.5"
18
- },
19
- "license": "MoMo",
20
- "jest": {
21
- "preset": "react-native"
22
- }
16
+ "devDependencies": {},
17
+ "license": "MoMo"
23
18
  }
package/publish.sh CHANGED
@@ -12,7 +12,7 @@ echo VERSION: $VERSION
12
12
  rsync -r --verbose --exclude '*.mdx' --exclude '*Demo.js' --exclude 'props-type.js' --exclude 'prop-types.js' ./* dist
13
13
 
14
14
  # #babel component to dist
15
- babel ./dist -d dist --copy-files
15
+ #babel ./dist -d dist --copy-files
16
16
 
17
17
  #copy option
18
18
  #cp -r ./src/ dist
@@ -26,4 +26,4 @@ cd ..
26
26
  rm -rf dist
27
27
 
28
28
 
29
- echo '{"text": "@momo-kits/calendar new version release: '*"$VERSION"*' https://www.npmjs.com/package/@momo-kits/calendar"}'
29
+ curl -X POST -H 'Content-Type: application/json' 'https://chat.googleapis.com/v1/spaces/AAAAbP8987c/messages?key=AIzaSyDdI0hCZtE6vySjMm-WEfRq3CPzqKqqsHI&token=UGSFRvk_oYb9uGsAgs31bVvMm6jDkmD8zihGm3eyaQA%3D&threadKey=JoaXTEYaNNkl' -d '{"text": "@momo-kits/calendar new version release: '*"$VERSION"*' https://www.npmjs.com/package/@momo-kits/calendar"}'
package/src/Calendar.js CHANGED
@@ -1 +1,394 @@
1
- var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.default=void 0;var _classCallCheck2=_interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));var _createClass2=_interopRequireDefault(require("@babel/runtime/helpers/createClass"));var _inherits2=_interopRequireDefault(require("@babel/runtime/helpers/inherits"));var _possibleConstructorReturn2=_interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));var _getPrototypeOf2=_interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));var _propTypes=_interopRequireDefault(require("prop-types"));var _react=_interopRequireWildcard(require("react"));var _reactNative=require("react-native");var _moment=_interopRequireDefault(require("moment"));var _core=require("@momo-kits/core");var _CalendarPro=_interopRequireDefault(require("./CalendarPro"));var _TabHeader=_interopRequireDefault(require("./TabHeader"));var _jsxFileName="/Users/trinh.ho2/momo-folk/kits/src/libs/calendar/dist/src/Calendar.js";function _getRequireWildcardCache(nodeInterop){if(typeof WeakMap!=="function")return null;var cacheBabelInterop=new WeakMap();var cacheNodeInterop=new WeakMap();return(_getRequireWildcardCache=function _getRequireWildcardCache(nodeInterop){return nodeInterop?cacheNodeInterop:cacheBabelInterop;})(nodeInterop);}function _interopRequireWildcard(obj,nodeInterop){if(!nodeInterop&&obj&&obj.__esModule){return obj;}if(obj===null||typeof obj!=="object"&&typeof obj!=="function"){return{default:obj};}var cache=_getRequireWildcardCache(nodeInterop);if(cache&&cache.has(obj)){return cache.get(obj);}var newObj={};var hasPropertyDescriptor=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var key in obj){if(key!=="default"&&Object.prototype.hasOwnProperty.call(obj,key)){var desc=hasPropertyDescriptor?Object.getOwnPropertyDescriptor(obj,key):null;if(desc&&(desc.get||desc.set)){Object.defineProperty(newObj,key,desc);}else{newObj[key]=obj[key];}}}newObj.default=obj;if(cache){cache.set(obj,newObj);}return newObj;}function _createSuper(Derived){var hasNativeReflectConstruct=_isNativeReflectConstruct();return function _createSuperInternal(){var Super=(0,_getPrototypeOf2.default)(Derived),result;if(hasNativeReflectConstruct){var NewTarget=(0,_getPrototypeOf2.default)(this).constructor;result=Reflect.construct(Super,arguments,NewTarget);}else{result=Super.apply(this,arguments);}return(0,_possibleConstructorReturn2.default)(this,result);};}function _isNativeReflectConstruct(){if(typeof Reflect==="undefined"||!Reflect.construct)return false;if(Reflect.construct.sham)return false;if(typeof Proxy==="function")return true;try{Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}));return true;}catch(e){return false;}}var DOUBLE='doubleDate';var Calendar=function(_Component){(0,_inherits2.default)(Calendar,_Component);var _super=_createSuper(Calendar);function Calendar(props){var _this;(0,_classCallCheck2.default)(this,Calendar);_this=_super.call(this,props);_this.onChangeTab=function(idTab){_this.tabSelected=idTab;if(_this.cellHeader1.current&&_this.cellHeader2.current){_this.cellHeader1.current.setActiveTab(idTab===0);_this.cellHeader2.current.setActiveTab(idTab===1);}_this.updateViewFlowPicker();};_this.onDateChange=function(date){_this.selectedDate=date;_this.updateView();};_this.updateHeaderView=function(){var _this$props=_this.props,onDateChange=_this$props.onDateChange,onCTAStateChange=_this$props.onCTAStateChange;var isDoubleDateMode=_this.state.isDoubleDateMode;if(isDoubleDateMode){if(_this.cellHeader1.current&&_this.cellHeader2.current){_this.cellHeader1.current.updateView(_this.selectedDate,true);_this.cellHeader2.current.updateView(null,false);_this.calendarPicker.current.setDoubleDateAndTabIndex(_this.selectedDate,null,_this.tabSelected);_this.doubleDate.first=(0,_moment.default)(_this.selectedDate);_this.doubleDate.second=null;_this.tabSelected=0;if(onCTAStateChange){onCTAStateChange(false);}if(onDateChange){onDateChange({first:_this.doubleDate.first?_this.doubleDate.first.toDate():null,second:_this.doubleDate.second?_this.doubleDate.second.toDate():null});}}}else{if(onCTAStateChange){onCTAStateChange(true);}if(_this.cellHeaderSingle.current){if(_this.doubleDate.first){_this.cellHeaderSingle.current.updateView(_this.doubleDate.first,true);_this.selectedDate=_this.doubleDate.first;}else{_this.cellHeaderSingle.current.updateView(_this.selectedDate,true);}if(onDateChange){onDateChange(_this.selectedDate.toDate());}}}};_this.toggleSelectionDateMode=function(){var onCallbackCalendar=_this.props.onCallbackCalendar;_this.setState(function(preState){return{isDoubleDateMode:!preState.isDoubleDateMode};},function(){var isDoubleDateMode=_this.state.isDoubleDateMode;_this.updateHeaderView();if(onCallbackCalendar&&typeof onCallbackCalendar==='function'){onCallbackCalendar('switch',isDoubleDateMode);}});};_this.renderSwitchReturnSelection=function(){var isDoubleDateMode=_this.state.isDoubleDateMode;return _react.default.createElement(_reactNative.View,{style:styles.viewSwitch,__source:{fileName:_jsxFileName,lineNumber:231,columnNumber:13}},_react.default.createElement(_core.Text.Caption,{style:styles.textSwitch,__source:{fileName:_jsxFileName,lineNumber:232,columnNumber:17}},_core.SwitchLanguage.chooseRoundtrip),_react.default.createElement(_reactNative.Switch,{value:isDoubleDateMode,onValueChange:_this.toggleSelectionDateMode,thumbColor:isDoubleDateMode?'#78ca32':'white',trackColor:{false:'#e5e7ec',true:'#e5e7ec'},style:[_reactNative.Platform.OS==='ios'&&{transform:[{scaleX:0.8},{scaleY:0.8}]}],__source:{fileName:_jsxFileName,lineNumber:235,columnNumber:17}}));};_this.renderHeaderPanel=function(){var isDoubleDateMode=_this.state.isDoubleDateMode;var _this$props2=_this.props,headerFrom=_this$props2.headerFrom,headerTo=_this$props2.headerTo;return isDoubleDateMode?_react.default.createElement(_reactNative.View,{style:styles.viewPanel,__source:{fileName:_jsxFileName,lineNumber:250,columnNumber:13}},_react.default.createElement(_TabHeader.default,{id:0,ref:_this.cellHeader1,onChangeTab:_this.onChangeTab,label:headerFrom||_core.SwitchLanguage.depart,activeTab:true,date:_this.doubleDate.first,__source:{fileName:_jsxFileName,lineNumber:251,columnNumber:17}}),_react.default.createElement(_TabHeader.default,{id:1,ref:_this.cellHeader2,onChangeTab:_this.onChangeTab,label:headerTo||_core.SwitchLanguage.return,activeTab:false,date:"",__source:{fileName:_jsxFileName,lineNumber:260,columnNumber:17}})):_react.default.createElement(_reactNative.View,{style:styles.viewPanel_2,__source:{fileName:_jsxFileName,lineNumber:270,columnNumber:13}},_react.default.createElement(_TabHeader.default,{id:1,disabled:true,ref:_this.cellHeaderSingle,label:headerFrom||_core.SwitchLanguage.depart,activeTab:true,date:_this.selectedDate,__source:{fileName:_jsxFileName,lineNumber:271,columnNumber:17}}));};_this.setDateRange=function(dateRange,isScrollToStartDate){var _this$props3=_this.props,mode=_this$props3.mode,_this$props3$doubleDa=_this$props3.doubleDate,doubleDate=_this$props3$doubleDa===void 0?{}:_this$props3$doubleDa;if(mode==='doubleDate'){var _this$calendarPicker,_this$calendarPicker$;_this.cellHeader1.current.updateView(dateRange.startDate,_this.tabSelected===0);_this.cellHeader2.current.updateView(dateRange.endDate,_this.tabSelected===1);(_this$calendarPicker=_this.calendarPicker)==null?void 0:(_this$calendarPicker$=_this$calendarPicker.current)==null?void 0:_this$calendarPicker$.setDateRange(dateRange,isScrollToStartDate);_this.doubleDate=doubleDate?{first:dateRange.startDate?(0,_moment.default)(dateRange.startDate):null,second:dateRange.endDate?(0,_moment.default)(dateRange.endDate):null}:{};}};_this.doubleDate=props.doubleDate?{first:props.doubleDate.first?(0,_moment.default)(props.doubleDate.first):null,second:props.doubleDate.second?(0,_moment.default)(props.doubleDate.second):null}:{};_this.tabSelected=0;_this.selectedDate=props.selectedDate?(0,_moment.default)(props.selectedDate):(0,_moment.default)();_this.state={isDoubleDateMode:props.mode===DOUBLE};_this.calendarPicker=_react.default.createRef();_this.cellHeader1=_react.default.createRef();_this.cellHeader2=_react.default.createRef();_this.cellHeaderSingle=_react.default.createRef();return _this;}(0,_createClass2.default)(Calendar,[{key:"componentDidMount",value:function componentDidMount(){var id=this.props.id;this.tabSelected=id||0;this.viewInit();}},{key:"viewInit",value:function viewInit(){var mode=this.props.mode;if(mode===DOUBLE){if(this.cellHeader1.current&&this.cellHeader2.current&&this.calendarPicker.current){var start=this.doubleDate.first?this.doubleDate.first:null;var end=this.doubleDate.second?this.doubleDate.second:null;this.cellHeader1.current.updateView(start,this.tabSelected===0);this.cellHeader2.current.updateView(end,this.tabSelected===1);this.calendarPicker.current.setDoubleDateAndTabIndex(this.doubleDate.first,this.doubleDate.second,this.tabSelected);}}else if(this.calendarPicker.current){this.calendarPicker.current.setDoubleDateAndTabIndex(this.selectedDate);}}},{key:"updateViewFlowPicker",value:function updateViewFlowPicker(){if(this.calendarPicker.current){this.calendarPicker.current.setDoubleDateAndTabIndex(this.doubleDate.first,this.doubleDate.second,this.tabSelected);}}},{key:"processDateFirst",value:function processDateFirst(){var _this$props4=this.props,onDateChange=_this$props4.onDateChange,onCTAStateChange=_this$props4.onCTAStateChange;if(this.cellHeader1.current&&this.cellHeader2.current&&this.calendarPicker.current){if(this.doubleDate.first&&this.doubleDate.second&&this.selectedDate<=this.doubleDate.second){this.doubleDate.first=this.selectedDate;this.tabSelected=1;this.cellHeader1.current.updateView(this.selectedDate,this.tabSelected===0);this.cellHeader2.current.setActiveTab(this.tabSelected===1);this.calendarPicker.current.setDoubleDateAndTabIndex(this.doubleDate.first,this.doubleDate.second,this.tabSelected);if(onDateChange){onDateChange({first:this.doubleDate.first?this.doubleDate.first.toDate():null,second:this.doubleDate.second?this.doubleDate.second.toDate():null});}}else{this.doubleDate.first=this.selectedDate;this.doubleDate.second=null;this.cellHeader1.current.updateView(this.selectedDate,false);this.cellHeader2.current.updateView(null,true);this.tabSelected=1;this.calendarPicker.current.setDoubleDateAndTabIndex(this.doubleDate.first,this.doubleDate.second,this.tabSelected);if(onDateChange){onDateChange({first:this.doubleDate.first?this.doubleDate.first.toDate():null,second:this.doubleDate.second?this.doubleDate.second.toDate():null});}}}if(onCTAStateChange){onCTAStateChange(!!this.doubleDate.second);}}},{key:"processDateSecond",value:function processDateSecond(){var _this$props5=this.props,onDateChange=_this$props5.onDateChange,onCTAStateChange=_this$props5.onCTAStateChange;if(this.cellHeader2.current){this.cellHeader2.current.updateView(this.selectedDate,false);this.cellHeader1.current.setActiveTab(true);this.doubleDate.second=this.selectedDate;this.tabSelected=0;this.calendarPicker.current.setDoubleDateAndTabIndex(this.doubleDate.first,this.doubleDate.second,this.tabSelected);if(onCTAStateChange){onCTAStateChange(!!this.doubleDate.second);}if(onDateChange){onDateChange({first:this.doubleDate.first?this.doubleDate.first.toDate():null,second:this.doubleDate.second?this.doubleDate.second.toDate():null});}}}},{key:"processDoubleDate",value:function processDoubleDate(){if(this.tabSelected===0){this.processDateFirst();}else{this.processDateSecond();}}},{key:"updateView",value:function updateView(){var onDateChange=this.props.onDateChange;var isDoubleDateMode=this.state.isDoubleDateMode;if(isDoubleDateMode){this.processDoubleDate();}else{if(this.cellHeaderSingle.current){this.cellHeaderSingle.current.updateView(this.selectedDate,true);}if(onDateChange){var date=new Date(this.selectedDate.toDate());onDateChange(date);}}}},{key:"render",value:function render(){var _this$props6=this.props,isOffLunar=_this$props6.isOffLunar,isHideHoliday=_this$props6.isHideHoliday,isHiddenSwitch=_this$props6.isHiddenSwitch,isShowLunar=_this$props6.isShowLunar,onCallbackCalendar=_this$props6.onCallbackCalendar,priceList=_this$props6.priceList,labelFrom=_this$props6.labelFrom,labelTo=_this$props6.labelTo,isHideLabel=_this$props6.isHideLabel,minDate=_this$props6.minDate,maxDate=_this$props6.maxDate,doubleDate=_this$props6.doubleDate,isHideHeaderPanel=_this$props6.isHideHeaderPanel;var isDoubleDateMode=this.state.isDoubleDateMode;return _react.default.createElement(_reactNative.ScrollView,{style:{flex:1,backgroundColor:'white'},__source:{fileName:_jsxFileName,lineNumber:303,columnNumber:13}},!isHiddenSwitch&&this.renderSwitchReturnSelection(),!isHideHeaderPanel&&this.renderHeaderPanel(),_react.default.createElement(_CalendarPro.default,{ref:this.calendarPicker,startDate:doubleDate==null?void 0:doubleDate.first,endDate:doubleDate==null?void 0:doubleDate.second,onDateChange:this.onDateChange,isDoubleDateMode:isDoubleDateMode,selectedDate:this.selectedDate,isShowLunar:isShowLunar,onCallbackCalendar:onCallbackCalendar,priceList:priceList,labelFrom:labelFrom,labelTo:labelTo,isHideLabel:isHideLabel,minDate:minDate,maxDate:maxDate,isHideHoliday:isHideHoliday,isOffLunar:isOffLunar,__source:{fileName:_jsxFileName,lineNumber:306,columnNumber:17}}));}}]);return Calendar;}(_react.Component);var _default=Calendar;exports.default=_default;Calendar.propTypes={doubleDate:_propTypes.default.shape({first:_propTypes.default.any,second:_propTypes.default.any}),id:_propTypes.default.any,isHiddenSwitch:_propTypes.default.bool,isShowLunar:_propTypes.default.bool,mode:_propTypes.default.string,onCTAStateChange:_propTypes.default.func,onCallbackCalendar:_propTypes.default.func,onDateChange:_propTypes.default.func,selectedDate:_propTypes.default.any,priceList:_propTypes.default.any,labelFrom:_propTypes.default.string,labelTo:_propTypes.default.string,headerFrom:_propTypes.default.string,headerTo:_propTypes.default.string,isHideLabel:_propTypes.default.bool,isHideHoliday:_propTypes.default.bool,minDate:_propTypes.default.oneOfType([_propTypes.default.string,_propTypes.default.instanceOf(Date)]),maxDate:_propTypes.default.oneOfType([_propTypes.default.string,_propTypes.default.instanceOf(Date)])};Calendar.defaultProps={mode:'single',isHiddenSwitch:false};var styles=_reactNative.StyleSheet.create({viewPanel_2:{height:46,paddingVertical:10,justifyContent:'center',alignItems:'center',backgroundColor:'white',borderRadius:8},viewPanel:{height:50,marginHorizontal:12,marginTop:6,marginBottom:25,padding:2,flexDirection:'row',backgroundColor:'#eeeeef',justifyContent:'space-around',borderRadius:8},textSwitch:{fontWeight:'bold',color:'#222222'},viewSwitch:{flexDirection:'row',justifyContent:'space-between',paddingHorizontal:12,alignItems:'center',backgroundColor:'#f2f3f5',paddingVertical:9,height:42}});
1
+ import PropTypes from 'prop-types';
2
+ import React, { Component, } from 'react';
3
+ import {
4
+ View, Switch, ScrollView, Platform, StyleSheet
5
+ } from 'react-native';
6
+ import moment from 'moment';
7
+ import { Text, SwitchLanguage } from '@momo-kits/core';
8
+ import CalendarPro from './CalendarPro';
9
+ import TabHeader from './TabHeader';
10
+
11
+ const DOUBLE = 'doubleDate';
12
+ // const SIGNLE = 'signleDate';
13
+ class Calendar extends Component {
14
+ constructor(props) {
15
+ super(props);
16
+ this.doubleDate = props.doubleDate ? {
17
+ first: props.doubleDate.first ? moment(props.doubleDate.first) : null,
18
+ second: props.doubleDate.second ? moment(props.doubleDate.second) : null
19
+ } : {};
20
+ this.tabSelected = 0;
21
+ this.selectedDate = props.selectedDate ? moment(props.selectedDate) : moment();
22
+
23
+ this.state = {
24
+ isDoubleDateMode: props.mode === DOUBLE
25
+ };
26
+ this.calendarPicker = React.createRef();
27
+ this.cellHeader1 = React.createRef();
28
+ this.cellHeader2 = React.createRef();
29
+ this.cellHeaderSingle = React.createRef();
30
+ }
31
+
32
+ componentDidMount() {
33
+ const { id } = this.props;
34
+ this.tabSelected = id || 0;
35
+ this.viewInit();
36
+ }
37
+
38
+ viewInit() {
39
+ const { mode } = this.props;
40
+ if (mode === DOUBLE) {
41
+ if (this.cellHeader1.current && this.cellHeader2.current && this.calendarPicker.current) {
42
+ const start = this.doubleDate.first ? this.doubleDate.first : null;
43
+ const end = this.doubleDate.second ? this.doubleDate.second : null;
44
+ this.cellHeader1.current.updateView(start, this.tabSelected === 0);
45
+ this.cellHeader2.current.updateView(end, this.tabSelected === 1);
46
+ this.calendarPicker.current.setDoubleDateAndTabIndex(this.doubleDate.first, this.doubleDate.second, this.tabSelected);
47
+ }
48
+ } else if (this.calendarPicker.current) {
49
+ this.calendarPicker.current.setDoubleDateAndTabIndex(this.selectedDate);
50
+ }
51
+ }
52
+
53
+ onChangeTab = (idTab) => {
54
+ this.tabSelected = idTab;
55
+ if (this.cellHeader1.current && this.cellHeader2.current) {
56
+ this.cellHeader1.current.setActiveTab(idTab === 0);
57
+ this.cellHeader2.current.setActiveTab(idTab === 1);
58
+ }
59
+ this.updateViewFlowPicker();
60
+ };
61
+
62
+ updateViewFlowPicker() {
63
+ if (this.calendarPicker.current) {
64
+ this.calendarPicker.current.setDoubleDateAndTabIndex(this.doubleDate.first, this.doubleDate.second, this.tabSelected);
65
+ }
66
+ }
67
+
68
+ processDateFirst() {
69
+ const { onDateChange, onCTAStateChange } = this.props;
70
+ if (this.cellHeader1.current && this.cellHeader2.current && this.calendarPicker.current) {
71
+ if (this.doubleDate.first && this.doubleDate.second && this.selectedDate <= this.doubleDate.second) {
72
+ this.doubleDate.first = this.selectedDate;
73
+ this.tabSelected = 1;
74
+ this.cellHeader1.current.updateView(this.selectedDate, this.tabSelected === 0);
75
+ this.cellHeader2.current.setActiveTab(this.tabSelected === 1);
76
+ this.calendarPicker.current.setDoubleDateAndTabIndex(this.doubleDate.first, this.doubleDate.second, this.tabSelected);
77
+ if (onDateChange) {
78
+ // const cloned = {
79
+ // first: this.doubleDate.first ? this.doubleDate.first.toDate() : null,
80
+ // this.doubleDate.first ? new Date(this.doubleDate.first.year(), this.doubleDate.first.month(), this.doubleDate.first.date()) : null,
81
+ // second: this.doubleDate.second ? this.doubleDate.second.toDate() : null
82
+ // this.doubleDate.second ? new Date(this.doubleDate.second.year(), this.doubleDate.second.month(), this.doubleDate.second.date()) : null
83
+ // };
84
+ onDateChange({
85
+ first: this.doubleDate.first ? this.doubleDate.first.toDate() : null,
86
+ second: this.doubleDate.second ? this.doubleDate.second.toDate() : null
87
+ });
88
+ }
89
+ } else {
90
+ this.doubleDate.first = this.selectedDate;
91
+ this.doubleDate.second = null;
92
+ this.cellHeader1.current.updateView(this.selectedDate, false);
93
+ this.cellHeader2.current.updateView(null, true);
94
+ this.tabSelected = 1;
95
+ this.calendarPicker.current.setDoubleDateAndTabIndex(this.doubleDate.first, this.doubleDate.second, this.tabSelected);
96
+ if (onDateChange) {
97
+ onDateChange({
98
+ first: this.doubleDate.first ? this.doubleDate.first.toDate() : null,
99
+ second: this.doubleDate.second ? this.doubleDate.second.toDate() : null
100
+ });
101
+ // const cloned = {
102
+ // first: this.doubleDate.first ? new Date(this.doubleDate.first.year(), this.doubleDate.first.month(), this.doubleDate.first.date()) : null,
103
+ // second: this.doubleDate.second ? new Date(this.doubleDate.second.year(), this.doubleDate.second.month(), this.doubleDate.second.date()) : null
104
+ // };
105
+ // onDateChange(cloned);
106
+ }
107
+ }
108
+ }
109
+ if (onCTAStateChange) {
110
+ onCTAStateChange(!!(this.doubleDate.second));
111
+ }
112
+ }
113
+
114
+ processDateSecond() {
115
+ const { onDateChange, onCTAStateChange } = this.props;
116
+ if (this.cellHeader2.current) {
117
+ this.cellHeader2.current.updateView(this.selectedDate, false);
118
+ this.cellHeader1.current.setActiveTab(true);
119
+ this.doubleDate.second = this.selectedDate;
120
+ this.tabSelected = 0;
121
+ this.calendarPicker.current.setDoubleDateAndTabIndex(this.doubleDate.first, this.doubleDate.second, this.tabSelected);
122
+ if (onCTAStateChange) {
123
+ onCTAStateChange(!!(this.doubleDate.second));
124
+ }
125
+ if (onDateChange) {
126
+ onDateChange({
127
+ first: this.doubleDate.first ? this.doubleDate.first.toDate() : null,
128
+ second: this.doubleDate.second ? this.doubleDate.second.toDate() : null
129
+ });
130
+ // const cloned = {
131
+ // first: this.doubleDate.first ? new Date(this.doubleDate.first.year(), this.doubleDate.first.month(), this.doubleDate.first.date()) : null,
132
+ // second: this.doubleDate.second ? new Date(this.doubleDate.second.year(), this.doubleDate.second.month(), this.doubleDate.second.date()) : null
133
+ // };
134
+ // onDateChange(cloned);
135
+ }
136
+ }
137
+ }
138
+
139
+ processDoubleDate() {
140
+ if (this.tabSelected === 0) {
141
+ this.processDateFirst();
142
+ } else {
143
+ this.processDateSecond();
144
+ }
145
+ }
146
+
147
+ updateView() {
148
+ const { onDateChange } = this.props;
149
+ const { isDoubleDateMode } = this.state;
150
+
151
+ if (isDoubleDateMode) {
152
+ this.processDoubleDate();
153
+ } else {
154
+ if (this.cellHeaderSingle.current) {
155
+ this.cellHeaderSingle.current.updateView(this.selectedDate, true);
156
+ }
157
+ if (onDateChange) {
158
+ const date = new Date(this.selectedDate.toDate());
159
+ onDateChange(date);
160
+ }
161
+ }
162
+ }
163
+
164
+ onDateChange = (date) => {
165
+ this.selectedDate = date;
166
+ this.updateView();
167
+ }
168
+
169
+ updateHeaderView = () => {
170
+ const { onDateChange, onCTAStateChange } = this.props;
171
+ const { isDoubleDateMode } = this.state;
172
+ if (isDoubleDateMode) {
173
+ if (this.cellHeader1.current && this.cellHeader2.current) {
174
+ this.cellHeader1.current.updateView(this.selectedDate, true);
175
+ this.cellHeader2.current.updateView(null, false);
176
+ this.calendarPicker.current.setDoubleDateAndTabIndex(this.selectedDate, null, this.tabSelected);
177
+ this.doubleDate.first = moment(this.selectedDate);
178
+ this.doubleDate.second = null;
179
+ this.tabSelected = 0;
180
+
181
+ if (onCTAStateChange) {
182
+ onCTAStateChange(false);
183
+ }
184
+ if (onDateChange) {
185
+ onDateChange({
186
+ first: this.doubleDate.first ? this.doubleDate.first.toDate() : null,
187
+ second: this.doubleDate.second ? this.doubleDate.second.toDate() : null
188
+ });
189
+ // const cloned = {
190
+ // first: this.doubleDate.first ? new Date(this.doubleDate.first.year(), this.doubleDate.first.month(), this.doubleDate.first.date()) : null,
191
+ // second: this.doubleDate.second ? new Date(this.doubleDate.second.year(), this.doubleDate.second.month(), this.doubleDate.second.date()) : null
192
+ // };
193
+ // onDateChange(cloned);
194
+ }
195
+ }
196
+ } else {
197
+ if (onCTAStateChange) {
198
+ onCTAStateChange(true);
199
+ }
200
+ if (this.cellHeaderSingle.current) {
201
+ if (this.doubleDate.first) {
202
+ this.cellHeaderSingle.current.updateView(this.doubleDate.first, true);
203
+ this.selectedDate = this.doubleDate.first;
204
+ } else {
205
+ this.cellHeaderSingle.current.updateView(this.selectedDate, true);
206
+ }
207
+
208
+ if (onDateChange) {
209
+ // const clone = moment(this.selectedDate);
210
+ // const cloned = new Date(clone.year(), clone.month(), clone.date());
211
+ onDateChange(this.selectedDate.toDate());
212
+ }
213
+ }
214
+ }
215
+ };
216
+
217
+ toggleSelectionDateMode = () => {
218
+ const { onCallbackCalendar } = this.props;
219
+ this.setState((preState) => ({ isDoubleDateMode: !preState.isDoubleDateMode }), () => {
220
+ const { isDoubleDateMode } = this.state;
221
+ this.updateHeaderView();
222
+ if (onCallbackCalendar && typeof onCallbackCalendar === 'function') {
223
+ onCallbackCalendar('switch', isDoubleDateMode);
224
+ }
225
+ });
226
+ };
227
+
228
+ renderSwitchReturnSelection = () => {
229
+ const { isDoubleDateMode } = this.state;
230
+ return (
231
+ <View style={styles.viewSwitch}>
232
+ <Text.Caption style={styles.textSwitch}>
233
+ {SwitchLanguage.chooseRoundtrip}
234
+ </Text.Caption>
235
+ <Switch
236
+ value={isDoubleDateMode}
237
+ onValueChange={this.toggleSelectionDateMode}
238
+ thumbColor={isDoubleDateMode ? '#78ca32' : 'white'}
239
+ trackColor={{ false: '#e5e7ec', true: '#e5e7ec' }}
240
+ style={[Platform.OS === 'ios' && { transform: [{ scaleX: 0.8 }, { scaleY: 0.8 }] }]}
241
+ />
242
+ </View>
243
+ );
244
+ };
245
+
246
+ renderHeaderPanel = () => {
247
+ const { isDoubleDateMode } = this.state;
248
+ const { headerFrom, headerTo } = this.props;
249
+ return (isDoubleDateMode ? (
250
+ <View style={styles.viewPanel}>
251
+ <TabHeader
252
+ id={0}
253
+ ref={this.cellHeader1}
254
+ onChangeTab={this.onChangeTab}
255
+ label={headerFrom || SwitchLanguage.depart}
256
+ activeTab
257
+ date={this.doubleDate.first}
258
+ />
259
+
260
+ <TabHeader
261
+ id={1}
262
+ ref={this.cellHeader2}
263
+ onChangeTab={this.onChangeTab}
264
+ label={headerTo || SwitchLanguage.return}
265
+ activeTab={false}
266
+ date=""
267
+ />
268
+ </View>
269
+ ) : (
270
+ <View style={styles.viewPanel_2}>
271
+ <TabHeader
272
+ id={1}
273
+ disabled
274
+ ref={this.cellHeaderSingle}
275
+ label={headerFrom || SwitchLanguage.depart}
276
+ activeTab
277
+ date={this.selectedDate}
278
+ />
279
+ </View>
280
+ ));
281
+ };
282
+
283
+ setDateRange = (dateRange, isScrollToStartDate) => {
284
+ const { mode, doubleDate = {} } = this.props;
285
+ if (mode === 'doubleDate') {
286
+ this.cellHeader1.current.updateView(dateRange.startDate, this.tabSelected === 0);
287
+ this.cellHeader2.current.updateView(dateRange.endDate, this.tabSelected === 1);
288
+ this.calendarPicker?.current?.setDateRange(dateRange, isScrollToStartDate);
289
+ this.doubleDate = doubleDate ? {
290
+ first: dateRange.startDate ? moment(dateRange.startDate) : null,
291
+ second: dateRange.endDate ? moment(dateRange.endDate) : null
292
+ } : {};
293
+ }
294
+ }
295
+
296
+ render() {
297
+ const {
298
+ isOffLunar, isHideHoliday, isHiddenSwitch, isShowLunar, onCallbackCalendar, priceList, labelFrom, labelTo, isHideLabel, minDate, maxDate, doubleDate,
299
+ isHideHeaderPanel
300
+ } = this.props;
301
+ const { isDoubleDateMode } = this.state;
302
+ return (
303
+ <ScrollView style={{ flex: 1, backgroundColor: 'white' }}>
304
+ {!isHiddenSwitch && this.renderSwitchReturnSelection()}
305
+ {!isHideHeaderPanel && this.renderHeaderPanel()}
306
+ <CalendarPro
307
+ ref={this.calendarPicker}
308
+ startDate={doubleDate?.first}
309
+ endDate={doubleDate?.second}
310
+ onDateChange={this.onDateChange}
311
+ isDoubleDateMode={isDoubleDateMode}
312
+ selectedDate={this.selectedDate}
313
+ isShowLunar={isShowLunar}
314
+ onCallbackCalendar={onCallbackCalendar}
315
+ priceList={priceList}
316
+ labelFrom={labelFrom}
317
+ labelTo={labelTo}
318
+ isHideLabel={isHideLabel}
319
+ minDate={minDate}
320
+ maxDate={maxDate}
321
+ isHideHoliday={isHideHoliday}
322
+ isOffLunar={isOffLunar}
323
+ />
324
+ </ScrollView>
325
+ );
326
+ }
327
+ }
328
+
329
+ export default Calendar;
330
+
331
+ Calendar.propTypes = {
332
+ doubleDate: PropTypes.shape({
333
+ first: PropTypes.any,
334
+ second: PropTypes.any
335
+ }),
336
+ id: PropTypes.any,
337
+ isHiddenSwitch: PropTypes.bool,
338
+ isShowLunar: PropTypes.bool,
339
+ mode: PropTypes.string,
340
+ onCTAStateChange: PropTypes.func,
341
+ onCallbackCalendar: PropTypes.func,
342
+ onDateChange: PropTypes.func,
343
+ selectedDate: PropTypes.any,
344
+ priceList: PropTypes.any,
345
+ labelFrom: PropTypes.string,
346
+ labelTo: PropTypes.string,
347
+ headerFrom: PropTypes.string,
348
+ headerTo: PropTypes.string,
349
+ isHideLabel: PropTypes.bool,
350
+ isHideHoliday: PropTypes.bool,
351
+ minDate: PropTypes.oneOfType([PropTypes.string, PropTypes.instanceOf(Date)]),
352
+ maxDate: PropTypes.oneOfType([PropTypes.string, PropTypes.instanceOf(Date)])
353
+ };
354
+
355
+ Calendar.defaultProps = {
356
+ mode: 'single',
357
+ isHiddenSwitch: false
358
+ };
359
+
360
+ const styles = StyleSheet.create({
361
+ viewPanel_2: {
362
+ height: 46,
363
+ paddingVertical: 10,
364
+ justifyContent: 'center',
365
+ alignItems: 'center',
366
+ backgroundColor: 'white',
367
+ borderRadius: 8
368
+ },
369
+ viewPanel: {
370
+ height: 50,
371
+ marginHorizontal: 12,
372
+ marginTop: 6,
373
+ marginBottom: 25,
374
+ padding: 2,
375
+ flexDirection: 'row',
376
+ backgroundColor: '#eeeeef',
377
+ justifyContent: 'space-around',
378
+ borderRadius: 8
379
+ },
380
+ textSwitch: {
381
+ // fontSize: 10,
382
+ fontWeight: 'bold',
383
+ color: '#222222'
384
+ },
385
+ viewSwitch: {
386
+ flexDirection: 'row',
387
+ justifyContent: 'space-between',
388
+ paddingHorizontal: 12,
389
+ alignItems: 'center',
390
+ backgroundColor: '#f2f3f5',
391
+ paddingVertical: 9,
392
+ height: 42
393
+ },
394
+ });