@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.
@@ -1 +1,80 @@
1
- var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.default=void 0;var _extends2=_interopRequireDefault(require("@babel/runtime/helpers/extends"));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 _react=_interopRequireWildcard(require("react"));var _reactNative=require("react-native");var _moment=_interopRequireDefault(require("moment"));var _Day=_interopRequireDefault(require("../Day"));var _jsxFileName="/Users/trinh.ho2/momo-folk/kits/src/libs/calendar/dist/src/Month/index.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 Month=function(_PureComponent){(0,_inherits2.default)(Month,_PureComponent);var _super=_createSuper(Month);function Month(props){var _this;(0,_classCallCheck2.default)(this,Month);_this=_super.call(this,props);_this.findHoliday=function(date){var holidays=_this.props.holidays;if(date&&holidays&&holidays.length>0){var day=date.date();var month=date.month()+1;return holidays.find(function(item){return item.day===day&&item.month===month;});}return null;};_this.checkHoliday=function(date){var holiday=_this.findHoliday(date);return{isSolarHoliday:!!(holiday&&!holiday.lunar),isLunarHoliday:!!(holiday&&holiday.lunar)};};_this.renderDayRow=function(dayList,index){return _react.default.createElement(_reactNative.View,{style:{flexDirection:'row',justifyContent:'space-between'},key:"row"+index,__source:{fileName:_jsxFileName,lineNumber:36,columnNumber:9}},dayList.map(function(item,i){var _this$props,_this$props$priceList;var keyDay=(0,_moment.default)(item.date).format('YYYY-MM-DD');var priceInfo=(_this$props=_this.props)==null?void 0:(_this$props$priceList=_this$props.priceListDate)==null?void 0:_this$props$priceList[keyDay];return _react.default.createElement(_Day.default,(0,_extends2.default)({},_this.props,_this.checkHoliday(item.date),{date:item.date,lunarDate:item.lunarDate,empty:item.empty,key:"day"+i.toString(),index:i,price:priceInfo==null?void 0:priceInfo.priceAsString,isBestPrice:priceInfo==null?void 0:priceInfo.isBestPrice,__source:{fileName:_jsxFileName,lineNumber:47,columnNumber:21}}));}));};var dateList=props.dateList;_this.rowArray=new Array(dateList.length/7).fill('');_this.temp=_this.rowArray.map(function(item,i){return dateList.slice(i*7,i*7+7);});return _this;}(0,_createClass2.default)(Month,[{key:"render",value:function render(){var _this2=this;var month=this.props.month;if(month){return _react.default.createElement(_reactNative.View,{__source:{fileName:_jsxFileName,lineNumber:70,columnNumber:17}},_react.default.createElement(_reactNative.View,{style:{paddingHorizontal:7,paddingVertical:5},__source:{fileName:_jsxFileName,lineNumber:71,columnNumber:21}},this.temp.map(function(item,i){return _this2.renderDayRow(item,i);})));}return _react.default.createElement(_reactNative.View,{__source:{fileName:_jsxFileName,lineNumber:78,columnNumber:17}});}}]);return Month;}(_react.PureComponent);exports.default=Month;
1
+ import React, { PureComponent } from 'react';
2
+
3
+ import {
4
+ View
5
+ } from 'react-native';
6
+ import moment from 'moment';
7
+ import Day from '../Day';
8
+
9
+ export default class Month extends PureComponent {
10
+ constructor(props) {
11
+ super(props);
12
+ const { dateList } = props;
13
+ this.rowArray = new Array(dateList.length / 7).fill('');
14
+ this.temp = this.rowArray.map((item, i) => dateList.slice(i * 7, i * 7 + 7));
15
+ }
16
+
17
+ findHoliday = (date) => {
18
+ const { holidays } = this.props;
19
+ if (date && holidays && holidays.length > 0) {
20
+ const day = date.date();
21
+ const month = date.month() + 1;
22
+ return holidays.find((item) => item.day === day && item.month === month);
23
+ }
24
+ return null;
25
+ };
26
+
27
+ checkHoliday = (date) => {
28
+ const holiday = this.findHoliday(date);
29
+ return {
30
+ isSolarHoliday: !!(holiday && !holiday.lunar),
31
+ isLunarHoliday: !!(holiday && holiday.lunar)
32
+ };
33
+ };
34
+
35
+ renderDayRow = (dayList, index) => (
36
+ <View
37
+ style={{
38
+ flexDirection: 'row',
39
+ justifyContent: 'space-between'
40
+ }}
41
+ key={`row${index}`}
42
+ >
43
+ {dayList.map((item, i) => {
44
+ const keyDay = moment(item.date).format('YYYY-MM-DD');
45
+ const priceInfo = this.props?.priceListDate?.[keyDay];
46
+ return (
47
+ <Day
48
+ {...this.props}
49
+ {...this.checkHoliday(item.date)}
50
+ date={item.date}
51
+ lunarDate={item.lunarDate}
52
+ empty={item.empty}
53
+ key={`day${i.toString()}`}
54
+ index={i}
55
+ price={priceInfo?.priceAsString}
56
+ isBestPrice={priceInfo?.isBestPrice}
57
+ />
58
+ );
59
+ }
60
+ )}
61
+ </View>
62
+ );
63
+
64
+ render() {
65
+ const {
66
+ month
67
+ } = this.props;
68
+ if (month) {
69
+ return (
70
+ <View>
71
+ <View style={{ paddingHorizontal: 7, paddingVertical: 5 }}>
72
+ {this.temp.map((item, i) => this.renderDayRow(item, i)
73
+ )}
74
+ </View>
75
+ </View>
76
+ );
77
+ }
78
+ return (<View />);
79
+ }
80
+ }
package/src/MonthList.js CHANGED
@@ -1 +1,253 @@
1
- var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.default=void 0;var _defineProperty2=_interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));var _extends2=_interopRequireDefault(require("@babel/runtime/helpers/extends"));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 _react=_interopRequireWildcard(require("react"));var _reactNative=require("react-native");var _moment2=_interopRequireDefault(require("moment"));var _Month=_interopRequireDefault(require("./Month"));var _style=_interopRequireDefault(require("./Day/style"));var _LunarService=require("./LunarService");var _jsxFileName="/Users/trinh.ho2/momo-folk/kits/src/libs/calendar/dist/src/MonthList.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 ownKeys(object,enumerableOnly){var keys=Object.keys(object);if(Object.getOwnPropertySymbols){var symbols=Object.getOwnPropertySymbols(object);if(enumerableOnly){symbols=symbols.filter(function(sym){return Object.getOwnPropertyDescriptor(object,sym).enumerable;});}keys.push.apply(keys,symbols);}return keys;}function _objectSpread(target){for(var i=1;i<arguments.length;i++){var source=arguments[i]!=null?arguments[i]:{};if(i%2){ownKeys(Object(source),true).forEach(function(key){(0,_defineProperty2.default)(target,key,source[key]);});}else if(Object.getOwnPropertyDescriptors){Object.defineProperties(target,Object.getOwnPropertyDescriptors(source));}else{ownKeys(Object(source)).forEach(function(key){Object.defineProperty(target,key,Object.getOwnPropertyDescriptor(source,key));});}}return target;}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 ITEM_WIDTH=_reactNative.Dimensions.get('window').width-24;var MAX_RENDER_PER_BATCH=_reactNative.Platform.OS==='android'?1:12;var MonthList=function(_Component){(0,_inherits2.default)(MonthList,_Component);var _super=_createSuper(MonthList);function MonthList(_props){var _this;(0,_classCallCheck2.default)(this,MonthList);_this=_super.call(this,_props);_this.renderMonth=function(_ref){var _moment,_priceList$keyMonth;var item=_ref.item,index=_ref.index;var _this$props=_this.props,isDoubleDateMode=_this$props.isDoubleDateMode,priceList=_this$props.priceList;var keyMonth=(_moment=(0,_moment2.default)(item.date))==null?void 0:_moment.format('YYYY-MM');var priceListDate=priceList==null?void 0:(_priceList$keyMonth=priceList[keyMonth])==null?void 0:_priceList$keyMonth.day;return _react.default.createElement(_Month.default,(0,_extends2.default)({},_this.props,{key:index,month:item.date||{},dateList:item.dateList||[],priceListDate:priceListDate,isDoubleDateMode:isDoubleDateMode,__source:{fileName:_jsxFileName,lineNumber:45,columnNumber:13}}));};_this.checkRange=function(date,start,end){if(!date||!start)return false;if(!end)return date.year()===start.year()&&date.month()===start.month();if(date.year()<start.year()||date.year()===start.year()&&date.month()<start.month())return false;return!(date.year()>end.year()||date.year()===end.year()&&date.month()>end.month());};_this.shouldUpdate=function(month,props){if(!props)return false;var startDate=props.startDate,endDate=props.endDate;var _this$props2=_this.props,curStartDate=_this$props2.startDate,curEndDate=_this$props2.endDate;var date=month.date;var next=_this.checkRange(date,startDate,endDate);var prev=_this.checkRange(date,curStartDate,curEndDate);return!!(prev||next);};_this.findHoliday=function(date){var holidays=_this.props.holidays;if(date&&holidays&&holidays.length>0){var day=date.date();var month=date.month()+1;return holidays.find(function(item){return item.day===day&&item.month===month;});}return null;};_this.checkHoliday=function(date,holidays){var holiday=_this.findHoliday(date,holidays);return{isSolarHoliday:!!(holiday&&!holiday.lunar),isLunarHoliday:!!(holiday&&holiday.lunar)};};_this.getDayList=function(date){var dayList;var month=date.month();var weekday=date.isoWeekday();if(weekday===1){dayList=[];}else{dayList=new Array(weekday-1).fill(_objectSpread({empty:(0,_moment2.default)(date).subtract(1,'h'),lunarDate:_this.convertLunarToSolar(date)},_this.checkHoliday(date)));}while(date.month()===month){var cloned=(0,_moment2.default)(date);dayList.push(_objectSpread({date:cloned,lunarDate:_this.convertLunarToSolar(cloned)},_this.checkHoliday(date)));date.add(1,'days');}date.subtract(1,'days');weekday=date.isoWeekday();if(weekday===1){return dayList.concat(new Array(6).fill({empty:(0,_moment2.default)(date).hour(1),lunarDate:_this.convertLunarToSolar(date)}));}return dayList.concat(new Array(Math.abs(7-weekday)).fill({empty:(0,_moment2.default)(date).hour(1),lunarDate:_this.convertLunarToSolar(date)}));};_this.getMonthList=function(props){var minDate=(0,_moment2.default)((props||_this.props).minDate).date(1);var maxDate=(0,_moment2.default)((props||_this.props).maxDate);var monthList=[];if(!maxDate||!minDate)return monthList;while(maxDate>minDate||maxDate.year()===minDate.year()&&maxDate.month()===minDate.month()){var d=(0,_moment2.default)(minDate);var month={date:d,dateList:_this.getDayList(d)};month.shouldUpdate=_this.shouldUpdate(month,props);monthList.push(month);minDate.add(1,'month');}return monthList;};_this.getIndexOfMonth=function(month,data){return data.findIndex(function(item){return item.date.isSame(month,'month');});};_this.getCurrentVisibleMonth=function(info){var changed=info.changed;var onScrollCalendar=_this.props.onScrollCalendar;if(changed&&changed.length>0){var _changed$=changed[0],item=_changed$.item,key=_changed$.key,index=_changed$.index;if(onScrollCalendar&&item&&_this.currentKey!==key){_this.currentKey=key;try{_this.heightStyle=_this.data&&_this.data[index]&&_this.data[index].dateList?{height:_style.default.containerDayHeight*_this.data[index].dateList.length/7+10}:{};}catch(e){_this.heightStyle={};}if(onScrollCalendar){onScrollCalendar({date:item.date,key:key,currentIndex:index});}}}};_this.keyExtractor=function(item){return item.date.month()+1+"/"+item.date.year();};_this.scrollToMonth=function(month){var index=_this.getIndexOfMonth(month,_this.data);if(_this.list.current&&index!==-1){_this.list.current.scrollToIndex({index:index,animated:true});}};_this.getItemLayout=function(data,index){return{length:ITEM_WIDTH,offset:ITEM_WIDTH*index,index:index};};_this.currentDate=(0,_moment2.default)();_this.data=_this.getMonthList();_this.currentScrollIndex=_this.getIndexOfMonth((0,_moment2.default)(_props.selectedDate),_this.data);_this.list=_react.default.createRef();_this.heightStyle={};_this.holidays=_props.holidays;return _this;}(0,_createClass2.default)(MonthList,[{key:"convertLunarToSolar",value:function convertLunarToSolar(date){return date&&_LunarService.convertSolar2Lunar?(0,_LunarService.convertSolar2Lunar)(date.date(),date.month()+1,date.year(),7):{};}},{key:"render",value:function render(){var priceList=this.props.priceList;return _react.default.createElement(_reactNative.FlatList,{extraData:priceList,style:this.heightStyle,horizontal:true,pagingEnabled:true,ref:this.list,data:this.data,renderItem:this.renderMonth,showsHorizontalScrollIndicator:false,keyExtractor:this.keyExtractor,onViewableItemsChanged:this.getCurrentVisibleMonth,onScrollToIndexFailed:function onScrollToIndexFailed(){},removeClippedSubviews:true,initialNumToRender:1,maxToRenderPerBatch:MAX_RENDER_PER_BATCH,windowSize:3,contentContainerStyle:{paddingTop:5},initialScrollIndex:this.currentScrollIndex,getItemLayout:this.getItemLayout,viewabilityConfig:{itemVisiblePercentThreshold:50},__source:{fileName:_jsxFileName,lineNumber:228,columnNumber:13}});}}]);return MonthList;}(_react.Component);exports.default=MonthList;
1
+ /* eslint-disable react/no-did-update-set-state */
2
+ import React, { Component } from 'react';
3
+ import {
4
+ FlatList,
5
+ Dimensions,
6
+ Platform
7
+ } from 'react-native';
8
+ import moment from 'moment';
9
+ import Month from './Month';
10
+ import style from './Day/style';
11
+ import { convertSolar2Lunar } from './LunarService';
12
+
13
+ const ITEM_WIDTH = Dimensions.get('window').width - 24;
14
+ const MAX_RENDER_PER_BATCH = Platform.OS === 'android' ? 1 : 12;
15
+ export default class MonthList extends Component {
16
+ constructor(props) {
17
+ super(props);
18
+ // this.state = {
19
+ // // data: [],
20
+ // isDoubleDateMode: props.isDoubleDateMode
21
+ // };
22
+ this.currentDate = moment();
23
+ this.data = this.getMonthList();
24
+ this.currentScrollIndex = this.getIndexOfMonth(moment(props.selectedDate), this.data);
25
+ this.list = React.createRef();
26
+ this.heightStyle = {};
27
+ this.holidays = props.holidays;
28
+ }
29
+
30
+ // componentDidUpdate(prevProps) {
31
+ // const { isDoubleDateMode } = this.props;
32
+ // if (isDoubleDateMode !== prevProps.isDoubleDateMode) {
33
+ // this.setState({
34
+ // // data: this.getMonthList(this.props),
35
+ // isDoubleDateMode
36
+ // });
37
+ // }
38
+ // }
39
+
40
+ renderMonth = ({ item, index }) => {
41
+ const { isDoubleDateMode, priceList } = this.props;
42
+ const keyMonth = moment(item.date)?.format('YYYY-MM');
43
+ const priceListDate = priceList?.[keyMonth]?.day;
44
+ return (
45
+ <Month
46
+ {...this.props}
47
+ key={index}
48
+ month={item.date || {}}
49
+ dateList={item.dateList || []}
50
+ priceListDate={priceListDate}
51
+ isDoubleDateMode={isDoubleDateMode}
52
+ />
53
+ );
54
+ };
55
+
56
+ checkRange = (date, start, end) => {
57
+ if (!date || !start) return false;
58
+ if (!end) return date.year() === start.year() && date.month() === start.month();
59
+ if (date.year() < start.year() || (date.year() === start.year() && date.month() < start.month())) return false;
60
+ return !(date.year() > end.year() || (date.year() === end.year() && date.month() > end.month()));
61
+ };
62
+
63
+ shouldUpdate = (month, props) => {
64
+ if (!props) return false;
65
+ const {
66
+ startDate,
67
+ endDate
68
+ } = props;
69
+ const { startDate: curStartDate, endDate: curEndDate } = this.props;
70
+ const {
71
+ date
72
+ } = month;
73
+ const next = this.checkRange(date, startDate, endDate);
74
+ const prev = this.checkRange(date, curStartDate, curEndDate);
75
+ return !!(prev || next);
76
+ };
77
+
78
+ convertLunarToSolar(date) {
79
+ return date && convertSolar2Lunar ? convertSolar2Lunar(
80
+ date.date(),
81
+ date.month() + 1,
82
+ date.year(),
83
+ 7
84
+ ) : {};
85
+ }
86
+
87
+ findHoliday = (date) => {
88
+ const { holidays } = this.props;
89
+ if (date && holidays && holidays.length > 0) {
90
+ const day = date.date();
91
+ const month = date.month() + 1;
92
+ return holidays.find((item) => item.day === day && item.month === month);
93
+ }
94
+ return null;
95
+ };
96
+
97
+ checkHoliday = (date, holidays) => {
98
+ const holiday = this.findHoliday(date, holidays);
99
+ return {
100
+ isSolarHoliday: !!(holiday && !holiday.lunar),
101
+ isLunarHoliday: !!(holiday && holiday.lunar)
102
+ };
103
+ };
104
+
105
+ getDayList = (date) => {
106
+ let dayList;
107
+ const month = date.month();
108
+ let weekday = date.isoWeekday();
109
+ if (weekday === 1) {
110
+ dayList = [];
111
+ } else {
112
+ dayList = new Array(weekday - 1).fill({
113
+ empty: moment(date).subtract(1, 'h'),
114
+ lunarDate: this.convertLunarToSolar(date),
115
+ ...this.checkHoliday(date)
116
+ });
117
+ }
118
+ while (date.month() === month) {
119
+ const cloned = moment(date);
120
+ dayList.push({
121
+ date: cloned,
122
+ lunarDate: this.convertLunarToSolar(cloned),
123
+ ...this.checkHoliday(date)
124
+ });
125
+ date.add(1, 'days');
126
+ }
127
+ date.subtract(1, 'days');
128
+ weekday = date.isoWeekday();
129
+ if (weekday === 1) {
130
+ return dayList.concat(new Array(6).fill({
131
+ empty: moment(date).hour(1),
132
+ lunarDate: this.convertLunarToSolar(date)
133
+ }));
134
+ }
135
+ return dayList.concat(new Array(Math.abs(7 - weekday)).fill({
136
+ empty: moment(date).hour(1),
137
+ lunarDate: this.convertLunarToSolar(date)
138
+ }));
139
+ };
140
+
141
+ getMonthList = (props) => {
142
+ const minDate = moment((props || this.props).minDate).date(1);
143
+ const maxDate = moment((props || this.props).maxDate);
144
+ const monthList = [];
145
+ if (!maxDate || !minDate) return monthList;
146
+ while (maxDate > minDate || (
147
+ maxDate.year() === minDate.year()
148
+ && maxDate.month() === minDate.month()
149
+ )) {
150
+ const d = moment(minDate);
151
+ const month = {
152
+ date: d,
153
+ dateList: this.getDayList(d)
154
+ };
155
+ month.shouldUpdate = this.shouldUpdate(month, props);
156
+ monthList.push(month);
157
+ minDate.add(1, 'month');
158
+ }
159
+ return monthList;
160
+ };
161
+
162
+ getIndexOfMonth = (month, data) => data.findIndex((item) => item.date.isSame(month, 'month'));
163
+
164
+ // componentDidMount() {
165
+ // const {
166
+ // selectedDate
167
+ // } = this.props;
168
+ // const data = this.getMonthList();
169
+ // this.currentScrollIndex = this.getIndexOfMonth(moment(selectedDate), data);
170
+ // this.setState({ data });
171
+ // }
172
+ // componentDidMount() {
173
+ // if (this.list.current) {
174
+ // this.scrollToMonth(moment(this.props.selectedDate));
175
+ // }
176
+ // }
177
+
178
+ // componentWillUnmount() {
179
+ // const { isDoubleDateMode } = this.props;
180
+ // this.setState({
181
+ // // data: [],
182
+ // isDoubleDateMode
183
+ // });
184
+ // }
185
+
186
+ getCurrentVisibleMonth = (info) => {
187
+ const { changed } = info;
188
+ const { onScrollCalendar } = this.props;
189
+ if (changed && changed.length > 0) {
190
+ const { item, key, index } = changed[0];
191
+ if (onScrollCalendar && item && this.currentKey !== key) {
192
+ this.currentKey = key;
193
+ try {
194
+ this.heightStyle = this.data && this.data[index] && this.data[index].dateList
195
+ ? {
196
+ height: (style.containerDayHeight * this.data[index].dateList.length / 7) + 10
197
+ }
198
+ : {};
199
+ } catch (e) {
200
+ this.heightStyle = {};
201
+ }
202
+ if (onScrollCalendar) {
203
+ onScrollCalendar({ date: item.date, key, currentIndex: index });
204
+ }
205
+ }
206
+ }
207
+ };
208
+
209
+ keyExtractor = (item) => `${item.date.month() + 1}/${item.date.year()}`;
210
+
211
+ scrollToMonth = (month) => {
212
+ const index = this.getIndexOfMonth(month, this.data);
213
+ if (this.list.current && index !== -1) {
214
+ this.list.current.scrollToIndex({
215
+ index,
216
+ animated: true
217
+ });
218
+ }
219
+ };
220
+
221
+ getItemLayout = (data, index) => (
222
+ { length: ITEM_WIDTH, offset: ITEM_WIDTH * index, index }
223
+ )
224
+
225
+ render() {
226
+ const { priceList } = this.props;
227
+ return (
228
+ <FlatList
229
+ extraData={priceList}
230
+ style={this.heightStyle}
231
+ horizontal
232
+ pagingEnabled
233
+ ref={this.list}
234
+ data={this.data}
235
+ renderItem={this.renderMonth}
236
+ showsHorizontalScrollIndicator={false}
237
+ keyExtractor={this.keyExtractor}
238
+ onViewableItemsChanged={this.getCurrentVisibleMonth}
239
+ onScrollToIndexFailed={() => {}}
240
+ removeClippedSubviews
241
+ initialNumToRender={1}
242
+ maxToRenderPerBatch={MAX_RENDER_PER_BATCH}
243
+ windowSize={3}
244
+ contentContainerStyle={{ paddingTop: 5 }}
245
+ initialScrollIndex={this.currentScrollIndex}
246
+ getItemLayout={this.getItemLayout}
247
+ viewabilityConfig={{
248
+ itemVisiblePercentThreshold: 50
249
+ }}
250
+ />
251
+ );
252
+ }
253
+ }
package/src/TabHeader.js CHANGED
@@ -1 +1,79 @@
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 _react=_interopRequireDefault(require("react"));var _reactNative=require("react-native");var _moment=_interopRequireDefault(require("moment"));var _Util=_interopRequireDefault(require("./Util"));var _jsxFileName="/Users/trinh.ho2/momo-folk/kits/src/libs/calendar/dist/src/TabHeader.js";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 TabHeader=function(_React$Component){(0,_inherits2.default)(TabHeader,_React$Component);var _super=_createSuper(TabHeader);function TabHeader(props){var _this;(0,_classCallCheck2.default)(this,TabHeader);_this=_super.call(this,props);_this.onChangeTab=function(){var _this$props=_this.props,onChangeTab=_this$props.onChangeTab,id=_this$props.id;if(onChangeTab){onChangeTab(id);}};_this.updateView=function(date,activeTab){_this.setState({date:date?(0,_moment.default)(date):'',active:activeTab});};_this.setActiveTab=function(active){_this.setState({active:active});};_this.state={active:props.activeTab};_this.label=props.label;_this.defaultDate=props.date?(0,_moment.default)(props.date):'';return _this;}(0,_createClass2.default)(TabHeader,[{key:"render",value:function render(){var _this$props2=this.props,label=_this$props2.label,disabled=_this$props2.disabled;var _this$state=this.state,date=_this$state.date,active=_this$state.active;var formattedDateFromState=date?date.format('DD/MM/YYYY'):'';var formattedDateFromDefault=this.defaultDate?this.defaultDate.format('DD/MM/YYYY'):'';var dayOfWeekFromState=date?_Util.default.WEEKDAYSFROMMOMENT[date.day()]+" -":'';var dayOfWeekFromDefault=this.defaultDate?_Util.default.WEEKDAYSFROMMOMENT[this.defaultDate.day()]+" -":'';return _react.default.createElement(_reactNative.TouchableWithoutFeedback,{disabled:disabled,onPress:this.onChangeTab,__source:{fileName:_jsxFileName,lineNumber:43,columnNumber:13}},_react.default.createElement(_reactNative.View,{style:{flex:1,justifyContent:'center',alignItems:'center',backgroundColor:active?'white':'#eeeeef',borderRadius:8},__source:{fileName:_jsxFileName,lineNumber:44,columnNumber:17}},_react.default.createElement(_reactNative.Text,{style:{fontSize:12,color:active?'#222222':'#8d919d',fontWeight:'bold'},__source:{fileName:_jsxFileName,lineNumber:52,columnNumber:21}},label),_react.default.createElement(_reactNative.Text,{style:{marginTop:3,fontSize:12,color:'#8d919d'},__source:{fileName:_jsxFileName,lineNumber:62,columnNumber:21}},_react.default.createElement(_reactNative.Text,{style:{color:active?'#b0006d':'#8d919d',fontWeight:'bold'},__source:{fileName:_jsxFileName,lineNumber:69,columnNumber:25}},(dayOfWeekFromState||dayOfWeekFromDefault||'--')+" "),formattedDateFromState||formattedDateFromDefault||'--/--/----')));}}]);return TabHeader;}(_react.default.Component);exports.default=TabHeader;
1
+ import React from 'react';
2
+ import { TouchableWithoutFeedback, View, Text } from 'react-native';
3
+ import Moment from 'moment';
4
+ import Util from './Util';
5
+
6
+ export default class TabHeader extends React.Component {
7
+ constructor(props) {
8
+ super(props);
9
+ this.state = {
10
+ active: props.activeTab
11
+ };
12
+ this.label = props.label;
13
+ this.defaultDate = props.date ? Moment(props.date) : '';
14
+ }
15
+
16
+ onChangeTab = () => {
17
+ const { onChangeTab, id } = this.props;
18
+ if (onChangeTab) {
19
+ onChangeTab(id);
20
+ }
21
+ };
22
+
23
+ updateView = (date, activeTab) => {
24
+ this.setState({
25
+ date: date ? Moment(date) : '',
26
+ active: activeTab
27
+ });
28
+ };
29
+
30
+ setActiveTab = (active) => {
31
+ this.setState({ active });
32
+ };
33
+
34
+ render() {
35
+ const { label, disabled } = this.props;
36
+ const { date, active } = this.state;
37
+ const formattedDateFromState = date ? date.format('DD/MM/YYYY') : '';
38
+ const formattedDateFromDefault = this.defaultDate ? this.defaultDate.format('DD/MM/YYYY') : '';
39
+ const dayOfWeekFromState = date ? `${Util.WEEKDAYSFROMMOMENT[date.day()]} -` : '';
40
+ const dayOfWeekFromDefault = this.defaultDate ? `${Util.WEEKDAYSFROMMOMENT[this.defaultDate.day()]} -` : '';
41
+
42
+ return (
43
+ <TouchableWithoutFeedback disabled={disabled} onPress={this.onChangeTab}>
44
+ <View style={{
45
+ flex: 1,
46
+ justifyContent: 'center',
47
+ alignItems: 'center',
48
+ backgroundColor: active ? 'white' : '#eeeeef',
49
+ borderRadius: 8
50
+ }}
51
+ >
52
+ <Text style={{
53
+ fontSize: 12,
54
+ // lineHeight: 14,
55
+ color: active ? '#222222' : '#8d919d',
56
+ fontWeight: 'bold'
57
+ }}
58
+ >
59
+ {label}
60
+
61
+ </Text>
62
+ <Text style={{
63
+ marginTop: 3,
64
+ fontSize: 12,
65
+ // lineHeight: 14,
66
+ color: '#8d919d'
67
+ }}
68
+ >
69
+ <Text style={{ color: active ? '#b0006d' : '#8d919d', fontWeight: 'bold' }}>
70
+ {`${dayOfWeekFromState || dayOfWeekFromDefault || '--'} `}
71
+
72
+ </Text>
73
+ {formattedDateFromState || formattedDateFromDefault || '--/--/----'}
74
+ </Text>
75
+ </View>
76
+ </TouchableWithoutFeedback>
77
+ );
78
+ }
79
+ }