-
Notifications
You must be signed in to change notification settings - Fork 3k
/
Copy pathindex.js
139 lines (130 loc) Β· 4.11 KB
/
index.js
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
import React, { Component } from 'react';
import { ActivityIndicator } from 'react-native';
import { View, Text, TouchableOpacity, Image } from 'react-native';
import XDate from 'xdate';
import PropTypes from 'prop-types';
import styleConstructor from './style';
import { weekDayNames } from '../../dateutils';
class CalendarHeader extends Component {
static propTypes = {
theme: PropTypes.object,
hideArrows: PropTypes.bool,
month: PropTypes.instanceOf(XDate),
addMonth: PropTypes.func,
showIndicator: PropTypes.bool,
firstDay: PropTypes.number,
renderArrow: PropTypes.func,
hideDayNames: PropTypes.bool,
weekNumbers: PropTypes.bool,
onPressArrowLeft: PropTypes.func,
onPressArrowRight: PropTypes.func
};
constructor(props) {
super(props);
this.style = styleConstructor(props.theme);
this.addMonth = this.addMonth.bind(this);
this.substractMonth = this.substractMonth.bind(this);
this.onPressLeft = this.onPressLeft.bind(this);
this.onPressRight = this.onPressRight.bind(this);
}
addMonth() {
this.props.addMonth(1);
}
substractMonth() {
this.props.addMonth(-1);
}
shouldComponentUpdate(nextProps) {
if (
nextProps.month.toString('yyyy MM') !==
this.props.month.toString('yyyy MM')
) {
return true;
}
if (nextProps.showIndicator !== this.props.showIndicator) {
return true;
}
if (nextProps.hideDayNames !== this.props.hideDayNames) {
return true;
}
return false;
}
onPressLeft() {
const {onPressArrowLeft} = this.props;
if(typeof onPressArrowLeft === 'function') {
return onPressArrowLeft(this.substractMonth);
}
return this.substractMonth();
}
onPressRight() {
const {onPressArrowRight} = this.props;
if(typeof onPressArrowRight === 'function') {
return onPressArrowRight(this.addMonth);
}
return this.addMonth();
}
render() {
let leftArrow = <View />;
let rightArrow = <View />;
let weekDaysNames = weekDayNames(this.props.firstDay);
if (!this.props.hideArrows) {
leftArrow = (
<TouchableOpacity
onPress={this.onPressLeft}
style={this.style.arrow}
hitSlop={{left: 20, right: 20, top: 20, bottom: 20}}
>
{this.props.renderArrow
? this.props.renderArrow('left')
: <Image
source={require('../img/previous.png')}
style={this.style.arrowImage}
/>}
</TouchableOpacity>
);
rightArrow = (
<TouchableOpacity
onPress={this.onPressRight}
style={this.style.arrow}
hitSlop={{left: 20, right: 20, top: 20, bottom: 20}}
>
{this.props.renderArrow
? this.props.renderArrow('right')
: <Image
source={require('../img/next.png')}
style={this.style.arrowImage}
/>}
</TouchableOpacity>
);
}
let indicator;
if (this.props.showIndicator) {
indicator = <ActivityIndicator />;
}
return (
<View>
<View style={this.style.header}>
{leftArrow}
<TouchableOpacity disabled={!this.props.onPressYear} onPress={this.props.onPressYear}>
<View style={{ flexDirection: 'row' }}>
<Text allowFontScaling={false} style={this.style.monthText} accessibilityTraits='header'>
{this.props.month.toString(this.props.monthFormat ? this.props.monthFormat : 'MMMM yyyy')}
</Text>
{indicator}
</View>
</TouchableOpacity>
{rightArrow}
</View>
{
!this.props.hideDayNames &&
<View style={this.style.week}>
{this.props.weekNumbers && <Text allowFontScaling={false} style={this.style.dayHeader}></Text>}
{weekDaysNames.map((day, idx) => (
<Text allowFontScaling={false} key={idx} accessible={false} style={this.style.dayHeader} numberOfLines={1} importantForAccessibility='no'>{day}</Text>
))}
</View>
}
</View>
);
}
}
export default CalendarHeader;