forked from ahmad2smile/react-native-calendar-select
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ios.js
127 lines (123 loc) · 2.95 KB
/
index.ios.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
/**
* Created by TinySymphony on 2017-05-08.
*/
import React, { Component } from "react"
import { AppRegistry, StyleSheet, Text, View, TouchableHighlight } from "react-native"
import Calendar from "./Calendar"
export default class calendar extends Component {
constructor (props) {
super(props)
this.calendar = null
this.state = {
startDate: new Date(2017, 7, 12),
endDate : new Date(2017, 8, 23)
}
this.openCalendar = this.openCalendar.bind(this)
this.confirmDate = this.confirmDate.bind(this)
}
// when confirm button is clicked, an object is conveyed to outer component
// contains following property:
// startDate [Date Object], endDate [Date Object]
// startMoment [Moment Object], endMoment [Moment Object]
confirmDate ({ startDate, endDate, startMoment, endMoment }) {
this.setState({
startDate,
endDate
})
}
openCalendar () {
!!this.calendar && this.calendar.open()
}
render () {
// It's an optional property, I use this to show the structure of customI18n object.
// const customI18n = {
// w : ["", "Mon", "Tues", "Wed", "Thur", "Fri", "Sat", "Sun"],
// weekday: [
// "",
// "Monday",
// "Tuesday",
// "Wednesday",
// "Thursday",
// "Friday",
// "Saturday",
// "Sunday"
// ],
// text: {
// start: "Check in",
// end : "Check out",
// date : "Date",
// save : "Confirm",
// clear: "Reset"
// },
// date: "DD / MM" // date format
// }
// optional property, too.
const color = {
mainColor: "#138691"
}
const { startDate, endDate } = this.state
const text =
startDate && endDate
? startDate.toLocaleDateString() + " / " + endDate.toLocaleDateString()
: "Please select a period"
return (
<View style={styles.container}>
<TouchableHighlight style={styles.btn} title="press" onPress={this.openCalendar}>
<Text style={styles.btnFont}>Choose Dates</Text>
</TouchableHighlight>
<View>
<Text style={styles.font}>{text}</Text>
</View>
<Calendar
i18n="en"
color={color}
ref={calendar => {
this.calendar = calendar
}}
format="YYYYMMDD"
minDate="20170510"
maxDate="20180412"
startDate={this.state.startDate}
endDate={this.state.endDate}
onConfirm={this.confirmDate}
/>
</View>
)
}
}
const styles = StyleSheet.create({
container: {
flex : 1,
justifyContent : "center",
alignItems : "center",
backgroundColor: "#F5FCFF"
},
btn: {
paddingHorizontal: 20,
paddingVertical : 10,
overflow : "hidden",
borderRadius : 6,
marginBottom : 30,
backgroundColor : "#138691"
},
btnFont: {
color : "#fff",
fontSize: 20
},
welcome: {
fontSize : 20,
textAlign: "center",
margin : 10
},
font: {
fontSize : 24,
fontWeight: "400",
color : "#304853"
},
instructions: {
textAlign : "center",
color : "#333333",
marginBottom: 5
}
})
AppRegistry.registerComponent("calendar", () => calendar)