|
5 | 5 | */
|
6 | 6 |
|
7 | 7 | import React, { Component } from 'react';
|
| 8 | +import { View, Text } from "react-native"; |
8 | 9 | import CalendarStrip from './CalendarStrip/CalendarStrip';
|
9 | 10 | import moment from 'moment';
|
10 | 11 |
|
11 | 12 | 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. |
13 | 19 | let customDatesStyles = [];
|
14 | 20 | 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 | + |
18 | 24 | customDatesStyles.push({
|
19 |
| - startDate: _date, // Single date since no endDate provided |
| 25 | + startDate: date, // Single date since no endDate provided |
20 | 26 | dateNameStyle: {color: 'blue'},
|
21 | 27 | dateNumberStyle: {color: 'purple'},
|
22 | 28 | // Random color...
|
23 | 29 | dateContainerStyle: { backgroundColor: `#${(`#00000${(Math.random() * (1 << 24) | 0).toString(16)}`).slice(-6)}` },
|
24 | 30 | });
|
| 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 | + } |
25 | 44 | markedDates.push({
|
26 |
| - date: _date, |
27 |
| - dots: [ |
28 |
| - { |
29 |
| - key: i, |
30 |
| - color: 'red', |
31 |
| - selectedDotColor: 'yellow', |
32 |
| - }, |
33 |
| - ], |
| 45 | + date, |
| 46 | + dots, |
34 | 47 | });
|
35 | 48 | }
|
36 | 49 |
|
| 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() { |
37 | 67 | 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> |
50 | 87 | );
|
51 | 88 | }
|
52 | 89 | }
|
0 commit comments