1 | <h1 align="center"> react-native-calendar-strip </h1>
|
2 | <div align="center">
|
3 | <strong> Easy to use and visually stunning calendar component for React Native.</strong>
|
4 | </div>
|
5 | <br>
|
6 | <div align="center">
|
7 | <a href="https://npmjs.org/package/react-native-calendar-strip">
|
8 | <img src="https://img.shields.io/npm/v/react-native-calendar-strip.svg?style=flat-square" alt="npm package version" />
|
9 | </a>
|
10 | <a href="https://npmjs.org/package/react-native-calendar-strip">
|
11 | <img src="https://img.shields.io/npm/dm/react-native-calendar-strip.svg?style=flat-square" alt="npm downloads" />
|
12 | </a>
|
13 | <a href="https://github.com/feross/standard">
|
14 | <img src="https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square" alt="standard JS linter" />
|
15 | </a>
|
16 | <a href="https://github.com/BugiDev/react-native-calendar-strip/blob/master/LICENSE.md">
|
17 | <img src="https://img.shields.io/npm/l/react-native-calendar-strip.svg?style=flat-square" alt="project license" />
|
18 | </a>
|
19 | <a href="http://makeapullrequest.com">
|
20 | <img src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square" alt="make a pull request" />
|
21 | </a>
|
22 | <img src="https://img.shields.io/badge/all_contributors-7-orange.svg?style=flat-square" alt="All Contributors" />
|
23 | </div>
|
24 | <br>
|
25 | <div align="center">
|
26 | <a href="https://github.com/BugiDev/react-native-calendar-strip/watchers">
|
27 | <img src="https://img.shields.io/github/watchers/BugiDev/react-native-calendar-strip.svg?style=social" alt="Github Watch Badge" />
|
28 | </a>
|
29 | <a href="https://github.com/BugiDev/react-native-calendar-strip/stargazers">
|
30 | <img src="https://img.shields.io/github/stars/BugiDev/react-native-calendar-strip.svg?style=social" alt="Github Star Badge" />
|
31 | </a>
|
32 | <a href="https://twitter.com/intent/tweet?text=Check%20out%20react-native-calendar-strip!%20https://github.com/BugiDev/react-native-calendar-strip%20%F0%9F%91%8D">
|
33 | <img src="https://img.shields.io/twitter/url/https/github.com/BugiDev/react-native-calendar-strip.svg?style=social" alt="Tweet" />
|
34 | </a>
|
35 | </div>
|
36 | <br>
|
37 | <div align="center">
|
38 | Built with ❤︎ by <a href="https://github.com/BugiDev">BugiDev</a> and <a href="https://github.com/BugiDev/react-native-calendar-strip/graphs/contributors">contributors</a>
|
39 | </div>
|
40 |
|
41 | <h2>Table of Contents</h2>
|
42 | <li><a href="#install">Install</a></li>
|
43 | <li><a href="#usage">Usage</a></li>
|
44 | <li><a href="#props">Props</a></li>
|
45 | <li><a href="#animations">Animations</a></li>
|
46 | <li><a href="#localization">Localization</a></li>
|
47 | <li><a href="#device-specific-notes">Device Specific Notes</a></li>
|
48 | <li><a href="#development-with-sample-application">Local Development</a></li>
|
49 | <li><a href="#contributing">Contributing</a></li>
|
50 | <li><a href="#license">License</a></li>
|
51 |
|
52 | ## Install
|
53 |
|
54 | ```sh
|
55 | $ npm install react-native-calendar-strip
|
56 | # OR
|
57 | $ yarn add react-native-calendar-strip
|
58 | ```
|
59 |
|
60 | ## Usage
|
61 |
|
62 | ### Scrollable CalendarStrip — New in 2.x
|
63 |
|
64 | The `scrollable` prop was introduced in 2.0.0 and features a bi-directional infinite scroller. It recycles days using RecyclerListView, shifting the dates as the ends are reached. The Chrome debugger can cause issues with this updating due to a [RN setTimeout bug](https://github.com/facebook/react-native/issues/4470). To prevent date shifts at the ends of the scroller, set the `minDate` and `maxDate` range to a year or less.
|
65 |
|
66 | The refactor to support `scrollable` introduced internal changes to the `CalendarDay` component. Users of the `dayComponent` prop may need to adjust their custom day component to accommodate the props passed to it.
|
67 |
|
68 | <div align="center">
|
69 | <img src="https://user-images.githubusercontent.com/6295083/82712731-54a98780-9c4e-11ea-9076-eddf0b756239.gif" alt="">
|
70 | </div>
|
71 |
|
72 | <details>
|
73 |
|
74 | ```jsx
|
75 | import { View, StyleSheet } from 'react-native';
|
76 | import CalendarStrip from 'react-native-calendar-strip';
|
77 |
|
78 | const Example = () => (
|
79 | <View style={styles.container}>
|
80 | <CalendarStrip
|
81 | scrollable
|
82 | style={{height:200, paddingTop: 20, paddingBottom: 10}}
|
83 | calendarColor={'#3343CE'}
|
84 | calendarHeaderStyle={{color: 'white'}}
|
85 | dateNumberStyle={{color: 'white'}}
|
86 | dateNameStyle={{color: 'white'}}
|
87 | iconContainer={{flex: 0.1}}
|
88 | />
|
89 | </View>
|
90 | );
|
91 |
|
92 | const styles = StyleSheet.create({
|
93 | container: { flex: 1 }
|
94 | });
|
95 | ```
|
96 |
|
97 | </details>
|
98 |
|
99 |
|
100 | ### Simple "out of the box" Example
|
101 |
|
102 | You can use this component without any styling or customization. Just import it in your project and render it:
|
103 | <div align="center">
|
104 | <img src="https://user-images.githubusercontent.com/6295083/81627792-9459af00-93c4-11ea-870c-601390912615.gif" alt="">
|
105 | </div>
|
106 |
|
107 | <details>
|
108 |
|
109 | ```jsx
|
110 | import { View, StyleSheet } from 'react-native';
|
111 | import CalendarStrip from 'react-native-calendar-strip';
|
112 |
|
113 | const Example = () => (
|
114 | <View style={styles.container}>
|
115 | <CalendarStrip
|
116 | style={{height:150, paddingTop: 20, paddingBottom: 10}}
|
117 | />
|
118 | </View>
|
119 | );
|
120 |
|
121 | const styles = StyleSheet.create({
|
122 | container: { flex: 1 }
|
123 | });
|
124 | ```
|
125 |
|
126 | </details>
|
127 |
|
128 | ### Styling and animations Example
|
129 |
|
130 | Even though this component works withouth any customization, it is possible to customize almost everything, so you can make it as beautiful as you want:
|
131 |
|
132 | <div align="center">
|
133 | <img src="https://user-images.githubusercontent.com/6295083/81627795-958adc00-93c4-11ea-9307-878e9f023cfd.gif" alt="">
|
134 | </div>
|
135 |
|
136 | <details>
|
137 |
|
138 | ```jsx
|
139 | import React, {Component} from 'react';
|
140 | import {
|
141 | AppRegistry,
|
142 | View
|
143 | } from 'react-native';
|
144 | import moment from 'moment';
|
145 |
|
146 | import CalendarStrip from 'react-native-calendar-strip';
|
147 |
|
148 | class Example extends Component {
|
149 | let datesWhitelist = [{
|
150 | start: moment(),
|
151 | end: moment().add(3, 'days') // total 4 days enabled
|
152 | }];
|
153 | let datesBlacklist = [ moment().add(1, 'days') ]; // 1 day disabled
|
154 |
|
155 | render() {
|
156 | return (
|
157 | <View>
|
158 | <CalendarStrip
|
159 | calendarAnimation={{type: 'sequence', duration: 30}}
|
160 | daySelectionAnimation={{type: 'border', duration: 200, borderWidth: 1, borderHighlightColor: 'white'}}
|
161 | style={{height: 100, paddingTop: 20, paddingBottom: 10}}
|
162 | calendarHeaderStyle={{color: 'white'}}
|
163 | calendarColor={'#7743CE'}
|
164 | dateNumberStyle={{color: 'white'}}
|
165 | dateNameStyle={{color: 'white'}}
|
166 | highlightDateNumberStyle={{color: 'yellow'}}
|
167 | highlightDateNameStyle={{color: 'yellow'}}
|
168 | disabledDateNameStyle={{color: 'grey'}}
|
169 | disabledDateNumberStyle={{color: 'grey'}}
|
170 | datesWhitelist={datesWhitelist}
|
171 | datesBlacklist={datesBlacklist}
|
172 | iconLeft={require('./img/left-arrow.png')}
|
173 | iconRight={require('./img/right-arrow.png')}
|
174 | iconContainer={{flex: 0.1}}
|
175 | />
|
176 | </View>
|
177 | );
|
178 | }
|
179 | }
|
180 |
|
181 | AppRegistry.registerComponent('Example', () => Example);
|
182 | ```
|
183 |
|
184 | </details>
|
185 |
|
186 | ## Props
|
187 |
|
188 | ### Initial data and onDateSelected handler
|
189 |
|
190 | | Prop | Description | Type | Default |
|
191 | | -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -------- | ---------- |
|
192 | | **`numDaysInWeek`** | Number of days shown in week. Applicable only when scrollable is false. | Number | **`7`** |
|
193 | | **`scrollable`** | Dates are scrollable if true. | Bool | **`False`**|
|
194 | | **`scrollerPaging`** | Dates are scrollable as a page (7 days) if true (Only works with `scrollable` set to true). | Bool | **`False`**|
|
195 | | **`startingDate`** | Date to be used for centering the calendar/showing the week based on that date. It is internally wrapped by `moment` so it accepts both `Date` and `moment Date`. | Any |
|
196 | | **`selectedDate`** | Date to be used as pre selected Date. It is internally wrapped by `moment` so it accepts both `Date` and `moment Date`. | Any |
|
197 | | **`onDateSelected`** | Function to be used as a callback when a date is selected. Receives param `date` Moment date. | Function |
|
198 | | **`onWeekChanged`** | Function to be used as a callback when a week is changed. Receives params `(start, end)` Moment dates. | Function |
|
199 | | **`onWeekScrollStart`**| Function to be used as a callback in `scrollable` mode when dates page starts gliding. Receives params `(start, end)` Moment dates. | Function |
|
200 | | **`onWeekScrollEnd`**| Function to be used as a callback in `scrollable` mode when dates page stops gliding. Receives params `(start, end)` Moment dates. | Function |
|
201 | | **`onHeaderSelected`**| Function to be used as a callback when the header is selected. Receives param object `{weekStartDate, weekEndDate}` Moment dates. | Function |
|
202 | | **`headerText`** | Text to use in the header. Use with `onWeekChanged` to receive the visible start & end dates. | String |
|
203 | | **`updateWeek`** | Update the week view if other props change. If `false`, the week view won't change when other props change, but will still respond to left/right selectors. | Bool | **`True`** |
|
204 | | **`useIsoWeekday`** | start week on ISO day of week (default true). If false, starts week on _startingDate_ parameter. | Bool | **`True`** |
|
205 | | **`minDate`** | minimum date that the calendar may navigate to. A week is allowed if minDate falls within the current week. | Any |
|
206 | | **`maxDate`** | maximum date that the calendar may navigate to. A week is allowed if maxDate falls within the current week. | Any |
|
207 | | **`datesWhitelist`** | Array of dates that are enabled, or a function callback which receives a date param and returns true if enabled. Array supports ranges specified with an object entry in the array. Check example <a href="#dateswhitelist-array-example">Below</a> | Array or Func |
|
208 | | **`datesBlacklist`** | Array of dates that are disabled, or a function callback. Same format as _datesWhitelist_. This overrides dates in _datesWhitelist_. | Array or Func |
|
209 | | **`markedDates`** | Dates that are marked with dots or lines. Format as <a href="#markeddates-example">markedDatesFormat</a>. | Array or Func | **[]**
|
210 | | **`scrollToOnSetSelectedDate`** | Controls whether to reposition the scroller to the date passed to `setSelectedDate`. | Bool | **`True`** |
|
211 |
|
212 |
|
213 | ##### datesWhitelist Array Example
|
214 |
|
215 | ```jsx
|
216 | datesWhitelist = [
|
217 | // single date (today)
|
218 | moment(),
|
219 |
|
220 | // date range
|
221 | {
|
222 | start: (Date or moment Date),
|
223 | end: (Date or moment Date)
|
224 | }
|
225 | ];
|
226 |
|
227 | return (
|
228 | <CalendarStrip
|
229 | datesWhitelist={datesWhitelist}
|
230 | />
|
231 | );
|
232 | ```
|
233 |
|
234 | ##### datesBlacklist Callback Example
|
235 |
|
236 | ```jsx
|
237 | const datesBlacklistFunc = date => {
|
238 | return date.isoWeekday() === 6; // disable Saturdays
|
239 | }
|
240 |
|
241 | return (
|
242 | <CalendarStrip
|
243 | datesBlacklist={datesBlacklistFunc}
|
244 | />
|
245 | );
|
246 | ```
|
247 |
|
248 | ##### markedDates Example
|
249 | <div align="center">
|
250 | <img src="https://user-images.githubusercontent.com/6295083/83835989-e1752c00-a6b7-11ea-9104-c79a26438c50.png" alt="marked dates example">
|
251 | </div>
|
252 |
|
253 | `markedDates` may be an array of dates with dots/lines, or a callback that returns the same shaped object for a date passed to it.
|
254 |
|
255 | ```jsx
|
256 | // Marked dates array format
|
257 | markedDatesArray = [
|
258 | {
|
259 | date: '(string, Date or Moment object)',
|
260 | dots: [
|
261 | {
|
262 | color: <string>,
|
263 | selectedColor: <string> (optional),
|
264 | },
|
265 | ],
|
266 | },
|
267 | {
|
268 | date: '(string, Date or Moment object)',
|
269 | lines: [
|
270 | {
|
271 | color: <string>,
|
272 | selectedColor: <string> (optional),
|
273 | },
|
274 | ],
|
275 | },
|
276 | ];
|
277 |
|
278 | ```
|
279 |
|
280 | ```jsx
|
281 | // Marked dates callback
|
282 | markedDatesFunc = date => {
|
283 | // Dot
|
284 | if (date.isoWeekday() === 4) { // Thursdays
|
285 | return {
|
286 | dots:[{
|
287 | color: <string>,
|
288 | selectedColor: <string> (optional),
|
289 | }]
|
290 | };
|
291 | }
|
292 | // Line
|
293 | if (date.isoWeekday() === 6) { // Saturdays
|
294 | return {
|
295 | lines:[{
|
296 | color: <string>,
|
297 | selectedColor: <string> (optional),
|
298 | }]
|
299 | };
|
300 | }
|
301 | return {};
|
302 | }
|
303 |
|
304 | ```
|
305 |
|
306 | ### Hiding Components
|
307 |
|
308 | | Prop | Description | Type | Default |
|
309 | | ------------------- | --------------------------------- | ---- | ---------- |
|
310 | | **`showMonth`** | Show or hide the month label. | Bool | **`True`** |
|
311 | | **`showDate`** | Show or hide all the dates. | Bool | **`True`** |
|
312 | | **`showDayName`** | Show or hide the day name label | Bool | **`True`** |
|
313 | | **`showDayNumber`** | Show or hide the day number label | Bool | **`True`** |
|
314 |
|
315 | ### Styling
|
316 |
|
317 | | Prop | Description | Type | Default |
|
318 | | ------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------ | -------------- | ---------- |
|
319 | | **`style`** | Style for the top level CalendarStrip component. | Any |
|
320 | | **`innerStyle`** | Style for the responsively sized inner view. This is necessary to account for padding/margin from the top level view. The inner view has style `flex:1` by default. If this component is nested within another dynamically sized container, remove the flex style by passing in `[]`. | Any |
|
321 | | **`calendarHeaderStyle`** | Style for the header text of the calendar | Any |
|
322 | | **`calendarHeaderContainerStyle`** | Style for the header text wrapper of the calendar | Any |
|
323 | | **`calendarHeaderPosition`** | Position of the header text (above or below) | `above, below` | **`above`** |
|
324 | | **`calendarHeaderFormat`** | Format for the header text of the calendar. For options, refer to [Moment documentation](http://momentjs.com/docs/#/displaying/format/) | String |
|
325 | | **`dateNameStyle`** | Style for the name of the day on work days in dates strip | Any |
|
326 | | **`dateNumberStyle`** | Style for the number of the day on work days in dates strip. | Any |
|
327 | | **`dayContainerStyle`** | Style for all day containers. RNCS scales the width & height responsively, so take that into account if overriding them. | Any |
|
328 | | **`weekendDateNameStyle`** | Style for the name of the day on weekend days in dates strip. | Any |
|
329 | | **`weekendDateNumberStyle`** | Style for the number of the day on weekend days in dates strip. | Any |
|
330 | | **`styleWeekend`** | Whether to style weekend dates separately. | Bool | **`True`** |
|
331 | | **`highlightDateNameStyle`** | Style for the selected name of the day in dates strip. | Any |
|
332 | | **`highlightDateNumberStyle`** | Style for the selected number of the day in dates strip. | Any |
|
333 | | **`highlightDateNumberContainerStyle`** | Style for the selected date number container. Similar to `highlightDateNumberStyle`, but this fixes the issue that some styles may have on iOS when using `highlightDateNumberStyle`. | Any |
|
334 | | **`highlightDateContainerStyle`** | Style for the selected date container. | Object |
|
335 | | **`disabledDateNameStyle`** | Style for disabled name of the day in dates strip (controlled by datesWhitelist & datesBlacklist). | Any |
|
336 | | **`disabledDateNumberStyle`** | Style for disabled number of the day in dates strip (controlled by datesWhitelist & datesBlacklist). | Any |
|
337 | | **`markedDatesStyle`** | Style for the marked dates marker. | Object |
|
338 | | **`disabledDateOpacity`** | Opacity of disabled dates strip. | Number | **`0.3`** |
|
339 | | **`customDatesStyles`** | Custom per-date styling, overriding the styles above. Check Table <a href="#customdatesstyles"> Below </a> . | Array or Func | [] |
|
340 | | **`shouldAllowFontScaling`** | Override the underlying Text element scaling to respect font settings | Bool | **`True`**|
|
341 | | **`upperCaseDays`** | Format text of the days to upper case or title case | Bool | **`True`**|
|
342 |
|
343 | #### customDatesStyles
|
344 |
|
345 | <div align="center">
|
346 | <img src="https://cloud.githubusercontent.com/assets/6295083/25105759/a3335fc8-238b-11e7-9a92-3174498a0d89.png" alt="Custom date styling example">
|
347 | </div>
|
348 |
|
349 | This prop may be passed an array of style objects or a callback which receives a date param and returns a style object for it. The format for the style object follows:
|
350 |
|
351 | | Key | Description | Type | optional |
|
352 | | ------------------------ | ---------------------------------------------------------------------------------- | ---- | ----------- |
|
353 | | **`startDate`** | anything parseable by Moment. | Any | **`False`** (unused w/ callback)|
|
354 | | **`endDate`** | specify a range. If no endDate is supplied, startDate is treated as a single date. | Any | **`True`** (unused w/ callback) |
|
355 | | **`dateNameStyle`** | Text style for the name of the day. | Any | **`True`** |
|
356 | | **`dateNumberStyle`** | Text style for the number of the day. | Any | **`True`** |
|
357 | | **`highlightDateNameStyle`** | Text style for the selected name of the day. This overrides the global prop. | Any | **`True`** |
|
358 | | **`highlightDateNumberStyle`** | Text style for the selected number of the day. This overrides the global prop. | Any | **`True`** |
|
359 | | **`dateContainerStyle`** | Style for the date Container. | Any | **`True`** |
|
360 |
|
361 | ##### Array Usage Example:
|
362 |
|
363 | <details>
|
364 |
|
365 | ```jsx
|
366 | let customDatesStyles = [];
|
367 | let startDate = moment();
|
368 | for (let i=0; i<6; i++) {
|
369 | customDatesStyles.push({
|
370 | startDate: startDate.clone().add(i, 'days'), // Single date since no endDate provided
|
371 | dateNameStyle: styles.dateNameStyle,
|
372 | dateNumberStyle: styles.dateNumberStyle,
|
373 | // Random color...
|
374 | dateContainerStyle: { backgroundColor: `#${(`#00000${(Math.random() * (1 << 24) | 0).toString(16)}`).slice(-6)}` },
|
375 | });
|
376 | }
|
377 |
|
378 | render() {
|
379 | return (
|
380 | <CalendarStrip
|
381 | customDatesStyles={customDatesStyles}
|
382 | ...
|
383 | />
|
384 | );
|
385 | }
|
386 | ```
|
387 | </details>
|
388 |
|
389 | ##### Callback Usage Example:
|
390 |
|
391 | <details>
|
392 |
|
393 | ```jsx
|
394 | const customDatesStylesFunc = date => {
|
395 | if (date.isoWeekday() === 5) { // Fridays
|
396 | return {
|
397 | dateNameStyle: {color: 'blue'},
|
398 | dateNumberStyle: {color: 'purple'},
|
399 | dateContainerStyle: {color: 'yellow'},
|
400 | }
|
401 | }
|
402 | }
|
403 |
|
404 | render() {
|
405 | return (
|
406 | <CalendarStrip
|
407 | customDatesStyles={customDatesStylesFunc}
|
408 | ...
|
409 | />
|
410 | );
|
411 | }
|
412 | ```
|
413 | </details>
|
414 |
|
415 |
|
416 | #### Responsive Sizing
|
417 |
|
418 | | Prop | Description | Type | Default |
|
419 | | ---------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- | ------ | -------- |
|
420 | | **`maxDayComponentSize`** | Maximum size that CalendarDay will responsively size up to. | Number | **`80`** |
|
421 | | **`minDayComponentSize`** | Minimum size that CalendarDay will responsively size down to. | Number | **`10`** |
|
422 | | **`responsiveSizingOffset`** | Adjust the responsive sizing. May be positive (increase size) or negative (decrease size). This value is added to the calculated day component width | Number | **`0`** |
|
423 | | **`dayComponentHeight`** | Fixed height for the CalendarDay component or custom `dayComponent`. | Number | |
|
424 |
|
425 | #### Icon Sizing
|
426 |
|
427 | | Prop | Description | Type | Default |
|
428 | | -------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---- | ------- |
|
429 | | **`iconLeft`** | Icon to be used for the left icon. It accepts require statement with url to the image (`require('./img/icon.png')`), or object with remote uri `{uri: 'http://example.com/image.png'}` | Any |
|
430 | | **`iconRight`** | Icon to be used for the right icon. It accepts require statement with url to the image (`require('./img/icon.png')`), or object with remote uri `{uri: 'http://example.com/image.png'}` | Any |
|
431 | | **`iconStyle`** | Style that is applied to both left and right icons. It is applied before _iconLeftStyle_ or _iconRightStyle_. | Any |
|
432 | | **`iconLeftStyle`** | Style for left icon. It will override all of the other styles applied to icons. | Any |
|
433 | | **`iconRightStyle`** | Style for right icon. It will override all of the other styles applied to icons. | Any |
|
434 | | **`iconContainer`** | Style for the container of icons. (Example usage is to add `flex` property to it so in the portrait mode, it will shrink the dates strip) | Any |
|
435 | | **`leftSelector`** | Component for the left selector control. May be an instance of any React component. This overrides the icon\* props above. Passing in an empty array `[]` hides this control. | Any |
|
436 | | **`rightSelector`** | Component for the right selector control. May be an instance of any React component. This overrides the icon\* props above. Passing in an empty array `[]` hides this control. | Any |
|
437 |
|
438 | #### Custom Day component
|
439 |
|
440 | | Prop | Description | Type | Default |
|
441 | | -------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---- | ------- |
|
442 | | **`dayComponent`** | User-defined component for the Days. All day-related props are passed to the custom component: https://github.com/BugiDev/react-native-calendar-strip/blob/master/src/CalendarStrip.js#L542 | Any |
|
443 |
|
444 | ### Methods
|
445 |
|
446 | Methods may be accessed through the instantiated component's [ref](https://reactjs.org/docs/react-component.html).
|
447 |
|
448 | | Prop | Description |
|
449 | | ------------------------------------- | --------------------------------------------------------------------------------- |
|
450 | | **`getSelectedDate()`** | Returns the currently selected date. If no date is selected, returns undefined. |
|
451 | | **`setSelectedDate(date)`** | Sets the selected date. `date` may be a Moment object, ISO8601 date string, or any format that Moment is able to parse. It is the responsibility of the caller to select a date that makes sense (e.g. within the current week view). Passing in a value of `0` effectively clears the selected date. `scrollToOnSetSelectedDate` controls whether the scroller repositions to the selected date. |
|
452 | | **`getNextWeek()`** | Advance to the next week. |
|
453 | | **`getPreviousWeek()`** | Rewind to the previous week. |
|
454 | | **`updateWeekView(date)`** | Show the week starting on `date`. |
|
455 |
|
456 |
|
457 | ## Animations
|
458 |
|
459 | ### Week Strip Animation
|
460 |
|
461 | | Sequence example (dates shown one by one) | Parallel example (dates shown all at once) |
|
462 | | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
463 | | ![alt text](https://user-images.githubusercontent.com/6295083/81627798-96237280-93c4-11ea-998f-53f7ee07caba.gif "react-native-calendar-strip parallel animation demo") | ![alt text](https://user-images.githubusercontent.com/6295083/81627797-96237280-93c4-11ea-874d-1f23fe6ba487.gif "react-native-calendar-strip parallel animation demo") |
|
464 |
|
465 | #### Week Strip Animation Options
|
466 |
|
467 | The `calendarAnimation` prop accepts an object in the following format:
|
468 |
|
469 | | Props | Description | Types |
|
470 | | -------------- | --------------------------------------------------- | ------------------------ |
|
471 | | **`Type`** | Pick which type of animation you would like to show | `sequence` or `parallel` |
|
472 | | **`duration`** | duration of animation in milliseconds | Number (ms) |
|
473 | | **`useNativeDriver`** | Use Animated's native driver (default true) | Bool |
|
474 |
|
475 | ### Day Selection Animation
|
476 |
|
477 | | Border example | Background example |
|
478 | | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
479 | | ![alt text](https://user-images.githubusercontent.com/6295083/81627793-94f24580-93c4-11ea-9726-89a56b2c4d49.gif "react-native-calendar-strip border animation demo") | ![alt text](https://user-images.githubusercontent.com/6295083/81627791-93c11880-93c4-11ea-8a1b-e5fb5848d2a7.gif "react-native-calendar-strip simple demo") |
|
480 |
|
481 | #### Day Selection Animation Options
|
482 |
|
483 | The `daySelectionAnimation` prop accepts an object in the following format:
|
484 |
|
485 | | Props | Description | Type |
|
486 | | -------------------------- | ---------------------------------------------------------------------------------------------------------------------- | ------------------------ |
|
487 | | **`Type`** | Pick which type of animation you would like to show | `border` or `background` |
|
488 | | **`duration`** | duration of animation in milliseconds | Number (ms) |
|
489 | | **`borderWidth`** | Selected day's border width. _Required if the type is set to border_. | Number |
|
490 | | **`borderHighlightColor`** | Selected day's border color. _Required if the type is set to border_. | String |
|
491 | | **`highlightColor`** | Highlighted color of selected date. _Required if the type is set to background_. | String |
|
492 | | **`animType`** | optional config options passed to [LayoutAnimation](https://facebook.github.io/react-native/docs/layoutanimation.html) | any |
|
493 | | **`animUpdateType`** | optional config options passed to [LayoutAnimation](https://facebook.github.io/react-native/docs/layoutanimation.html) | any |
|
494 | | **`animProperty`** | optional config options passed to [LayoutAnimation](https://facebook.github.io/react-native/docs/layoutanimation.html) | any |
|
495 | | **`animSpringDamping`** | optional config options passed to [LayoutAnimation](https://facebook.github.io/react-native/docs/layoutanimation.html) | any |
|
496 |
|
497 | ## Localization
|
498 |
|
499 | | Props | Description | Type |
|
500 | | ------------ | ---------------- | ------ |
|
501 | | **`locale`** | Locale for dates | Object |
|
502 |
|
503 | This prop is used for adding localization to react-native-calendar-strip component. The localization rules are the same as moments and can be found in [moments documentation](http://momentjs.com/docs/#/i18n/)
|
504 |
|
505 | | `locale` Props | Description | Type |
|
506 | | -------------- | ----------------------------------------------------------- | ------ |
|
507 | | **`name`** | The name of the locale (ex. 'fr') | String |
|
508 | | **`config`** | The config object holding all of the localization strings.. | Object |
|
509 |
|
510 | #### Build Release info
|
511 |
|
512 | To properly make a release build, import the appropriate "Locale" module using the following steps. Not importing the locale module will crash the release build (though the dev build will work).
|
513 |
|
514 | 1- import momentJs module:
|
515 | > $ yarn add moment
|
516 |
|
517 | or
|
518 |
|
519 | > $ npm install moment
|
520 |
|
521 | 2- Go to your index.js and import the specific "Locale" after the main moment import. Ex:
|
522 | ```
|
523 | import 'moment';
|
524 | import 'moment/locale/fr'; // language must match config
|
525 | import moment from 'moment-timezone'; // only if timezone is needed
|
526 | ```
|
527 |
|
528 | The locale import must match the language specified in the locale config (example below).
|
529 |
|
530 | #### Example of one locale object is:
|
531 |
|
532 | <details>
|
533 |
|
534 | ```jsx
|
535 | const locale = {
|
536 | name: 'fr',
|
537 | config: {
|
538 | months: 'Janvier_Février_Mars_Avril_Mai_Juin_Juillet_Août_Septembre_Octobre_Novembre_Décembre'.split(
|
539 | '_'
|
540 | ),
|
541 | monthsShort: 'Janv_Févr_Mars_Avr_Mai_Juin_Juil_Août_Sept_Oct_Nov_Déc'.split(
|
542 | '_'
|
543 | ),
|
544 | weekdays: 'Dimanche_Lundi_Mardi_Mercredi_Jeudi_Vendredi_Samedi'.split('_'),
|
545 | weekdaysShort: 'Dim_Lun_Mar_Mer_Jeu_Ven_Sam'.split('_'),
|
546 | weekdaysMin: 'Di_Lu_Ma_Me_Je_Ve_Sa'.split('_'),
|
547 | longDateFormat: {
|
548 | LT: 'HH:mm',
|
549 | LTS: 'HH:mm:ss',
|
550 | L: 'DD/MM/YYYY',
|
551 | LL: 'D MMMM YYYY',
|
552 | LLL: 'D MMMM YYYY LT',
|
553 | LLLL: 'dddd D MMMM YYYY LT'
|
554 | },
|
555 | calendar: {
|
556 | sameDay: "[Aujourd'hui à] LT",
|
557 | nextDay: '[Demain à] LT',
|
558 | nextWeek: 'dddd [à] LT',
|
559 | lastDay: '[Hier à] LT',
|
560 | lastWeek: 'dddd [dernier à] LT',
|
561 | sameElse: 'L'
|
562 | },
|
563 | relativeTime: {
|
564 | future: 'dans %s',
|
565 | past: 'il y a %s',
|
566 | s: 'quelques secondes',
|
567 | m: 'une minute',
|
568 | mm: '%d minutes',
|
569 | h: 'une heure',
|
570 | hh: '%d heures',
|
571 | d: 'un jour',
|
572 | dd: '%d jours',
|
573 | M: 'un mois',
|
574 | MM: '%d mois',
|
575 | y: 'une année',
|
576 | yy: '%d années'
|
577 | },
|
578 | ordinalParse: /\d{1,2}(er|ème)/,
|
579 | ordinal: function(number) {
|
580 | return number + (number === 1 ? 'er' : 'ème');
|
581 | },
|
582 | meridiemParse: /PD|MD/,
|
583 | isPM: function(input) {
|
584 | return input.charAt(0) === 'M';
|
585 | },
|
586 | // in case the meridiem units are not separated around 12, then implement
|
587 | // this function (look at locale/id.js for an example)
|
588 | // meridiemHour : function (hour, meridiem) {
|
589 | // return /* 0-23 hour, given meridiem token and hour 1-12 */
|
590 | // },
|
591 | meridiem: function(hours, minutes, isLower) {
|
592 | return hours < 12 ? 'PD' : 'MD';
|
593 | },
|
594 | week: {
|
595 | dow: 1, // Monday is the first day of the week.
|
596 | doy: 4 // The week that contains Jan 4th is the first week of the year.
|
597 | }
|
598 | }
|
599 | };
|
600 | ```
|
601 |
|
602 | </details>
|
603 | </br>
|
604 |
|
605 | ## Device Specific Notes
|
606 |
|
607 | <ul>
|
608 | <li>OnePlus devices use OnePlus Slate font by default which causes text being cut off in the date number in react-native-calendar-strip. To overcome this change the default font of the device or use a specific font throughout your app.</li>
|
609 | </ul>
|
610 |
|
611 | ## Development with Sample Application
|
612 |
|
613 | To facilitate development, the `example` directory has a sample app.
|
614 |
|
615 | ```sh
|
616 | cd example
|
617 | npm run cp
|
618 | npm install
|
619 | npm start
|
620 | ```
|
621 |
|
622 | The CalendarStrip source files are copied from the project root directory into `example/CalendarStrip` using `npm run cp`. If a source file is modified, it must be copied over again with `npm run cp`.
|
623 |
|
624 | ## Contributing
|
625 |
|
626 | Contributions are welcome!
|
627 |
|
628 | 1. Fork it.
|
629 | 2. Create your feature branch: `git checkout -b my-new-feature`
|
630 | 3. Commit your changes: `git commit -am 'Add some feature'`
|
631 | 4. Push to the branch: `git push origin my-new-feature`
|
632 | 5. Submit a pull request :D
|
633 |
|
634 | Or open up [an issue](https://github.com/BugiDev/react-native-calendar-strip/issues).
|
635 |
|
636 |
|
637 | ## Contributors
|
638 |
|
639 |
|
640 |
|
641 | | [<img src="https://avatars0.githubusercontent.com/u/4005545?v=4" width="100px;"/><br /><sub><b>Bogdan Begovic</b></sub>](https://github.com/BugiDev)<br />[💬](#question-BugiDev "Answering Questions") [💻](https://github.com/bugidev/react-native-calendar-strip/commits?author=BugiDev "Code") [🎨](#design-BugiDev "Design") [📖](https://github.com/bugidev/react-native-calendar-strip/commits?author=BugiDev "Documentation") [💡](#example-BugiDev "Examples") [🔧](#tool-BugiDev "Tools") | [<img src="https://avatars3.githubusercontent.com/u/6295083?v=4" width="100px;"/><br /><sub><b>Peace</b></sub>](https://github.com/peacechen)<br />[💬](#question-peacechen "Answering Questions") [🐛](https://github.com/bugidev/react-native-calendar-strip/issues?q=author%3Apeacechen "Bug reports") [💻](https://github.com/bugidev/react-native-calendar-strip/commits?author=peacechen "Code") [📖](https://github.com/bugidev/react-native-calendar-strip/commits?author=peacechen "Documentation") [👀](#review-peacechen "Reviewed Pull Requests") | [<img src="https://avatars1.githubusercontent.com/u/15834048?v=4" width="100px;"/><br /><sub><b>Chris Burns</b></sub>](http://www.usebillo.com)<br />[💬](#question-Burnsy "Answering Questions") [🐛](https://github.com/bugidev/react-native-calendar-strip/issues?q=author%3ABurnsy "Bug reports") [💻](https://github.com/bugidev/react-native-calendar-strip/commits?author=Burnsy "Code") [📖](https://github.com/bugidev/react-native-calendar-strip/commits?author=Burnsy "Documentation") [🔧](#tool-Burnsy "Tools") [💡](#example-Burnsy "Examples") [👀](#review-Burnsy "Reviewed Pull Requests") | [<img src="https://avatars0.githubusercontent.com/u/26348965?v=4" width="100px;"/><br /><sub><b>samcolby</b></sub>](https://github.com/samcolby)<br />[💻](https://github.com/bugidev/react-native-calendar-strip/commits?author=samcolby "Code") [⚠️](https://github.com/bugidev/react-native-calendar-strip/commits?author=samcolby "Tests") | [<img src="https://avatars0.githubusercontent.com/u/239360?v=4" width="100px;"/><br /><sub><b>Florian Biebel</b></sub>](https://chromosom23.de)<br />[💻](https://github.com/bugidev/react-native-calendar-strip/commits?author=1ne8ight7even "Code") | [<img src="https://avatars0.githubusercontent.com/u/986135?v=4" width="100px;"/><br /><sub><b>Vitaliy Zhukov</b></sub>](http://intspirit.com/)<br />[💻](https://github.com/bugidev/react-native-calendar-strip/commits?author=Vitall "Code") | [<img src="https://avatars1.githubusercontent.com/u/15323137?v=4" width="100px;"/><br /><sub><b>lbrdar</b></sub>](https://github.com/lbrdar)<br />[💻](https://github.com/bugidev/react-native-calendar-strip/commits?author=lbrdar "Code") |
|
642 | | :---: | :---: | :---: | :---: | :---: | :---: | :---: |
|
643 | | [<img src="https://avatars0.githubusercontent.com/u/6774813?v=4" width="100px;"/><br /><sub><b>Dimka Vasilyev</b></sub>](https://github.com/gHashTag)<br />[💻](https://github.com/bugidev/react-native-calendar-strip/commits?author=gHashTag "Code") | [<img src="https://avatars2.githubusercontent.com/u/6241354?v=4" width="100px;"/><br /><sub><b>Eugene</b></sub>](https://github.com/hellpirat)<br />[💻](https://github.com/bugidev/react-native-calendar-strip/commits?author=hellpirat "Code") |
|
644 |
|
645 | Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds/all-contributors#emoji-key)):
|
646 |
|
647 | ## Discussion and Collaboration
|
648 |
|
649 | In addition to the [Github Issues](https://github.com/BugiDev/react-native-calendar-strip/issues) page, there is a [Discord group](https://discord.gg/RvFM97v) for React Native with a channel specifically for [react-native-calendar-strip](https://discordapp.com/channels/413352084981678082/413360340579909633). Thanks @MichelDiz for setting that up.
|
650 |
|
651 | ## License
|
652 |
|
653 | Licensed under the MIT License.
|