-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.android.js
More file actions
150 lines (134 loc) · 4.26 KB
/
index.android.js
File metadata and controls
150 lines (134 loc) · 4.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import React, { Component,ViewPropTypes } from 'react';
import { Dimensions, requireNativeComponent, View } from 'react-native';
import _ from 'lodash'
import PropTypes from 'prop-types'
var RCTMaterialCalendarView = requireNativeComponent('RCTMaterialCalendarView', ReactMaterialCalendarView);
class ReactMaterialCalendarView extends Component {
constructor() {
super();
this._onDateChange = this._onDateChange.bind(this);
this._onMonthChange = this._onMonthChange.bind(this);
}
_onDateChange(event) {
if (event.nativeEvent.selected&& this.props.onSelectDate) {
this.props.onSelectDate && this.props.onSelectDate(event.nativeEvent.date);
}else if(!event.nativeEvent.selected&&this.props.onDeselectDate){
this.props.onDeselectDate && this.props.onDeselectDate(event.nativeEvent.date);
}
}
_onMonthChange(event) {
if (this.props.onMonthChange) {
this.props.onMonthChange && this.props.onMonthChange(event.nativeEvent.date);
}
}
render() {
var { style,hideHeader,fillDefaultColorDates, subtitleTextSize,...rest } = this.props,
width = rest.width,
height = rest.height ? rest.height : rest.topbarVisible ? width / 7 * 8 : width;
style = {
...style,
width,
height
};
if(subtitleTextSize&& fillDefaultColorDates){
_.each(fillDefaultColorDates,(value,key)=>{
value.textSize=subtitleTextSize;
})
}
console.log("fillDefaultColorDates====",fillDefaultColorDates)
return (
<RCTMaterialCalendarView
{...rest}
style={style}
fillDefaultColorDates={fillDefaultColorDates}
topbarVisible={!hideHeader}
onDateChange={this._onDateChange}
onMonthChange={this._onMonthChange} />
);
}
}
var FIRST_DAY_OF_WEEK = [
'monday',
'tuesday',
'wednesday',
'thursday',
'friday',
'saturday',
'sunday'
];
var SHOWING_DATE = [
'all',
'none'
];
var SELECTION_MODES = [
'none',
'range',
'single',
'multiple'
];
const colorType = function (props, propName, componentName, ...rest) {
var checker = function () {
var color = props[propName];
var regex = /^#([0-9A-Fa-f]{6}|[0-9A-Fa-f]{8})$/;
if (color && !regex.test(color)) {
return new Error('Only accept color formats: #RRGGBB and #AARRGGBB');
}
};
return PropTypes.string(props, propName, componentName, ...rest) || checker();
};
const ColorValidator = function (props, propName, componentName, ...rest) {
var checker = function () {
var color = props[propName];
var regex = /^#([0-9A-Fa-f]{6}|[0-9A-Fa-f]{8})$/;
if (color && !regex.test(color)) {
return new Error('Color accept formats: #RRGGBB and #AARRGGBB');
}
};
return PropTypes.string(props, propName, componentName, ...rest) || checker();
};
const DatesValidator = function (props, propName, componentName, ...rest) {
console.log('DatesValidator');
var checker = function () {
var date = props[propName];
var regex = /^(19|20)\d\d[/](0[1-9]|1[012])[/](0[1-9]|[12][0-9]|3[01])/;
if (date && !regex.test(date)) {
return new Error('Date should be: YYYY/MM/DD');
}
};
return PropTypes.string(props, propName, componentName, ...rest) || checker();
};
ReactMaterialCalendarViewPropTypes = {
...ViewPropTypes,
width: PropTypes.number.isRequired,
height: PropTypes.number,
// Tile size
tileWidth: PropTypes.number,
tileHeight: PropTypes.number,
tileSize: PropTypes.number,
subtitleTextSize:PropTypes.number,
// Toolbar options
hideHeader:PropTypes.bool,
arrowColor: ColorValidator,
// Calendar config
firstDayOfWeek: PropTypes.oneOf(FIRST_DAY_OF_WEEK),
minimumDate: DatesValidator,
maximumDate: DatesValidator,
datesSelection: PropTypes.oneOf(SELECTION_MODES),
showOtherDates: PropTypes.oneOf(SHOWING_DATE),
// Set date
currentDate: DatesValidator,
selectedDates: PropTypes.arrayOf(DatesValidator),
eventsDates: PropTypes.arrayOf(DatesValidator),
// Color customizations
selectionColor: ColorValidator,
weekendsColor: ColorValidator,
eventsColor: ColorValidator,
//custom day color
fillDefaultColorDates:PropTypes.object
};
ReactMaterialCalendarView.defaultProps = {
hideHeader: false,
width: Dimensions.get('window').width,
firstDayOfWeek:"sunday"
};
export default ReactMaterialCalendarView;