Skip to content

Commit ddf12c7

Browse files
committed
Update example app.
Add datesBlacklist function. Display the selected date. Move processing from render to state.
1 parent d2242bd commit ddf12c7

File tree

1 file changed

+62
-25
lines changed

1 file changed

+62
-25
lines changed

example/App.js

Lines changed: 62 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,48 +5,85 @@
55
*/
66

77
import React, { Component } from 'react';
8+
import { View, Text } from "react-native";
89
import CalendarStrip from './CalendarStrip/CalendarStrip';
910
import moment from 'moment';
1011

1112
export default class App extends Component<{}> {
12-
render() {
13+
constructor(props) {
14+
super(props);
15+
16+
let startDate = moment(); // today
17+
18+
// Create a week's worth of custom date styles and marked dates.
1319
let customDatesStyles = [];
1420
let markedDates = [];
15-
let startDate = moment();
16-
for (let i=0; i<6; i++) {
17-
let _date = startDate.clone().add(i, 'days');
21+
for (let i=0; i<7; i++) {
22+
let date = startDate.clone().add(i, 'days');
23+
1824
customDatesStyles.push({
19-
startDate: _date, // Single date since no endDate provided
25+
startDate: date, // Single date since no endDate provided
2026
dateNameStyle: {color: 'blue'},
2127
dateNumberStyle: {color: 'purple'},
2228
// Random color...
2329
dateContainerStyle: { backgroundColor: `#${(`#00000${(Math.random() * (1 << 24) | 0).toString(16)}`).slice(-6)}` },
2430
});
31+
32+
let dots = [{
33+
key: i,
34+
color: 'red',
35+
selectedDotColor: 'yellow',
36+
}];
37+
if (i % 2) { // add second dot to alternating days
38+
dots.push({
39+
key: i + 'b',
40+
color: 'blue',
41+
selectedDotColor: 'yellow',
42+
});
43+
}
2544
markedDates.push({
26-
date: _date,
27-
dots: [
28-
{
29-
key: i,
30-
color: 'red',
31-
selectedDotColor: 'yellow',
32-
},
33-
],
45+
date,
46+
dots,
3447
});
3548
}
3649

50+
this.state = {
51+
selectedDate: '',
52+
customDatesStyles,
53+
markedDates,
54+
startDate,
55+
};
56+
}
57+
58+
datesBlacklistFunc = date => {
59+
return date.isoWeekday() === 6; // disable Saturdays
60+
}
61+
62+
onDateSelected = date => {
63+
this.setState({ formattedDate: date.format('YYYY-MM-DD')});
64+
}
65+
66+
render() {
3767
return (
38-
<CalendarStrip
39-
calendarAnimation={{type: 'sequence', duration: 30}}
40-
daySelectionAnimation={{type: 'background', duration: 300, highlightColor: '#9265DC'}}
41-
style={{height:200, paddingTop: 20, paddingBottom: 10}}
42-
calendarHeaderStyle={{color: 'white'}}
43-
calendarColor={'#7743CE'}
44-
dateNumberStyle={{color: 'white'}}
45-
dateNameStyle={{color: 'white'}}
46-
iconContainer={{flex: 0.1}}
47-
customDatesStyles={customDatesStyles}
48-
markedDates={markedDates}
49-
/>
68+
<View>
69+
<CalendarStrip
70+
scrollable
71+
calendarAnimation={{type: 'sequence', duration: 30}}
72+
daySelectionAnimation={{type: 'background', duration: 300, highlightColor: '#9265DC'}}
73+
style={{height:200, paddingTop: 20, paddingBottom: 10}}
74+
calendarHeaderStyle={{color: 'white'}}
75+
calendarColor={'#3343CE'}
76+
dateNumberStyle={{color: 'white'}}
77+
dateNameStyle={{color: 'white'}}
78+
iconContainer={{flex: 0.1}}
79+
customDatesStyles={this.state.customDatesStyles}
80+
markedDates={this.state.markedDates}
81+
datesBlacklist={this.datesBlacklistFunc}
82+
onDateSelected={this.onDateSelected}
83+
useIsoWeekday={false}
84+
/>
85+
<Text style={{fontSize: 24}}>Selected Date: {this.state.formattedDate}</Text>
86+
</View>
5087
);
5188
}
5289
}

0 commit comments

Comments
 (0)