Skip to content

Commit e88f6e4

Browse files
committed
Creating dynamic example
1 parent 8785f1f commit e88f6e4

File tree

2 files changed

+30
-14
lines changed

2 files changed

+30
-14
lines changed

example/src/screens/expandableCalendar.js

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,40 @@ import {
99
TouchableOpacity,
1010
Button
1111
} from 'react-native';
12-
import XDate from 'xdate';
1312
import {ExpandableCalendar, AgendaList, CalendarProvider} from 'react-native-calendars';
1413

1514

16-
const today = XDate().toString('yyyy-MM-dd');
15+
const today = new Date().toISOString().split('T')[0];
16+
const fastDate = getPastDate(3);
17+
const futureDates = getFutureDates(9);
18+
const dates = [fastDate, today].concat(futureDates);
19+
20+
function getFutureDates(days) {
21+
const array = [];
22+
for (let index = 1; index <= days; index++) {
23+
const date = new Date(Date.now() + (864e5 * index)); // 864e5 == 86400000 == 24*60*60*1000
24+
const dateString = date.toISOString().split('T')[0];
25+
array.push(dateString);
26+
}
27+
return array;
28+
}
29+
30+
function getPastDate(days) {
31+
return new Date(Date.now() - (864e5 * days)).toISOString().split('T')[0]; // 864e5 == 86400000 == 24*60*60*1000
32+
}
33+
1734
const items = [
18-
{title: '2019-05-27', data: [{hour: '12am', duration: '1h', title: 'Ashtanga Yoga'}]},
19-
{title: today, data: [{hour: '4pm', duration: '1h', title: 'Pilates ABC'}, {hour: '5pm', duration: '1h', title: 'Vinyasa Yoga'}]},
20-
{title: '2019-06-01', data: [{hour: '1pm', duration: '1h', title: 'Ashtanga Yoga'}, {hour: '2pm', duration: '1h', title: 'Deep Streches'}, {hour: '3pm', duration: '1h', title: 'Private Yoga'}]},
21-
{title: '2019-06-02', data: [{hour: '12am', duration: '1h', title: 'Ashtanga Yoga'}]},
22-
{title: '2019-06-03', data: [{}]},
23-
{title: '2019-06-04', data: [{hour: '9pm', duration: '1h', title: 'Pilates Reformer'}, {hour: '10pm', duration: '1h', title: 'Ashtanga'}, {hour: '11pm', duration: '1h', title: 'TRX'}, {hour: '12pm', duration: '1h', title: 'Running Group'}]},
24-
{title: '2019-06-05', data: [{hour: '12am', duration: '1h', title: 'Ashtanga Yoga'}]},
25-
{title: '2019-06-06', data: [{}]},
26-
{title: '2019-06-07', data: [{hour: '9pm', duration: '1h', title: 'Pilates Reformer'}, {hour: '10pm', duration: '1h', title: 'Ashtanga'}, {hour: '11pm', duration: '1h', title: 'TRX'}, {hour: '12pm', duration: '1h', title: 'Running Group'}]},
27-
{title: '2019-06-08', data: [{hour: '1pm', duration: '1h', title: 'Ashtanga Yoga'}, {hour: '2pm', duration: '1h', title: 'Deep Streches'}, {hour: '3pm', duration: '1h', title: 'Private Yoga'}]},
28-
{title: '2019-06-09', data: [{hour: '12am', duration: '1h', title: 'Ashtanga Yoga'}]}
35+
{title: dates[0], data: [{hour: '12am', duration: '1h', title: 'Ashtanga Yoga'}]},
36+
{title: dates[1], data: [{hour: '4pm', duration: '1h', title: 'Pilates ABC'}, {hour: '5pm', duration: '1h', title: 'Vinyasa Yoga'}]},
37+
{title: dates[2], data: [{hour: '1pm', duration: '1h', title: 'Ashtanga Yoga'}, {hour: '2pm', duration: '1h', title: 'Deep Streches'}, {hour: '3pm', duration: '1h', title: 'Private Yoga'}]},
38+
{title: dates[3], data: [{hour: '12am', duration: '1h', title: 'Ashtanga Yoga'}]},
39+
{title: dates[4], data: [{}]},
40+
{title: dates[5], data: [{hour: '9pm', duration: '1h', title: 'Pilates Reformer'}, {hour: '10pm', duration: '1h', title: 'Ashtanga'}, {hour: '11pm', duration: '1h', title: 'TRX'}, {hour: '12pm', duration: '1h', title: 'Running Group'}]},
41+
{title: dates[6], data: [{hour: '12am', duration: '1h', title: 'Ashtanga Yoga'}]},
42+
{title: dates[7], data: [{}]},
43+
{title: dates[8], data: [{hour: '9pm', duration: '1h', title: 'Pilates Reformer'}, {hour: '10pm', duration: '1h', title: 'Ashtanga'}, {hour: '11pm', duration: '1h', title: 'TRX'}, {hour: '12pm', duration: '1h', title: 'Running Group'}]},
44+
{title: dates[9], data: [{hour: '1pm', duration: '1h', title: 'Ashtanga Yoga'}, {hour: '2pm', duration: '1h', title: 'Deep Streches'}, {hour: '3pm', duration: '1h', title: 'Private Yoga'}]},
45+
{title: dates[10], data: [{hour: '12am', duration: '1h', title: 'Ashtanga Yoga'}]}
2946
];
3047

3148
export default class ExpandableCalendarScreen extends Component {

src/expandableCalendar/calendarProvider.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ class CalendarProvider extends Component {
8585

8686
animateTodayButton(date) {
8787
if (this.props.showTodayButton) {
88-
8988
const today = XDate().toString('yyyy-MM-dd');
9089
const isToday = today === date;
9190

0 commit comments

Comments
 (0)