├── .all-contributorsrc ├── .babelrc ├── .eslintrc ├── .githooks └── pre-commit ├── .gitignore ├── .npmignore ├── CONTRIBUTING.md ├── LICENSE.md ├── README.md ├── __tests__ ├── CalendarHeader.js ├── Scroller.js └── WeekSelector.js ├── example ├── .expo-shared │ └── assets.json ├── .gitignore ├── App.js ├── app.json ├── assets │ └── icon.png ├── babel.config.js └── package.json ├── index.d.ts ├── index.js ├── package.json ├── src ├── Calendar.style.js ├── CalendarDay.js ├── CalendarHeader.js ├── CalendarStrip.js ├── Scroller.js ├── WeekSelector.js └── img │ ├── left-arrow-black.png │ └── right-arrow-black.png └── tsconfig.json /.all-contributorsrc: -------------------------------------------------------------------------------- 1 | { 2 | "projectName": "react-native-calendar-strip", 3 | "projectOwner": "bugidev", 4 | "files": [ 5 | "README.md" 6 | ], 7 | "imageSize": 100, 8 | "commit": false, 9 | "contributors": [ 10 | { 11 | "login": "BugiDev", 12 | "name": "Bogdan Begovic", 13 | "avatar_url": "https://avatars0.githubusercontent.com/u/4005545?v=4", 14 | "profile": "https://github.com/BugiDev", 15 | "contributions": [ 16 | "question", 17 | "code", 18 | "design", 19 | "doc", 20 | "example", 21 | "tool" 22 | ] 23 | }, 24 | { 25 | "login": "peacechen", 26 | "name": "Peace", 27 | "avatar_url": "https://avatars3.githubusercontent.com/u/6295083?v=4", 28 | "profile": "https://github.com/peacechen", 29 | "contributions": [ 30 | "question", 31 | "bug", 32 | "code", 33 | "doc", 34 | "review" 35 | ] 36 | }, 37 | { 38 | "login": "Burnsy", 39 | "name": "Chris Burns", 40 | "avatar_url": "https://avatars1.githubusercontent.com/u/15834048?v=4", 41 | "profile": "http://www.usebillo.com", 42 | "contributions": [ 43 | "question", 44 | "bug", 45 | "code", 46 | "doc", 47 | "tool", 48 | "example", 49 | "review" 50 | ] 51 | }, 52 | { 53 | "login": "samcolby", 54 | "name": "samcolby", 55 | "avatar_url": "https://avatars0.githubusercontent.com/u/26348965?v=4", 56 | "profile": "https://github.com/samcolby", 57 | "contributions": [ 58 | "code", 59 | "test" 60 | ] 61 | }, 62 | { 63 | "login": "1ne8ight7even", 64 | "name": "Florian Biebel", 65 | "avatar_url": "https://avatars0.githubusercontent.com/u/239360?v=4", 66 | "profile": "https://chromosom23.de", 67 | "contributions": [ 68 | "code" 69 | ] 70 | }, 71 | { 72 | "login": "Vitall", 73 | "name": "Vitaliy Zhukov", 74 | "avatar_url": "https://avatars0.githubusercontent.com/u/986135?v=4", 75 | "profile": "http://intspirit.com/", 76 | "contributions": [ 77 | "code" 78 | ] 79 | }, 80 | { 81 | "login": "lbrdar", 82 | "name": "lbrdar", 83 | "avatar_url": "https://avatars1.githubusercontent.com/u/15323137?v=4", 84 | "profile": "https://github.com/lbrdar", 85 | "contributions": [ 86 | "code" 87 | ] 88 | }, 89 | { 90 | "login": "gHashTag", 91 | "name": "Dimka Vasilyev", 92 | "avatar_url": "https://avatars0.githubusercontent.com/u/6774813?v=4", 93 | "profile": "https://github.com/gHashTag", 94 | "contributions": [ 95 | "code" 96 | ] 97 | }, 98 | { 99 | "login": "hellpirat", 100 | "name": "Eugene", 101 | "avatar_url": "https://avatars2.githubusercontent.com/u/6241354?v=4", 102 | "profile": "https://github.com/hellpirat", 103 | "contributions": [ 104 | "code" 105 | ] 106 | } 107 | ] 108 | } 109 | -------------------------------------------------------------------------------- /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | "module:metro-react-native-babel-preset" 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "parser": "babel-eslint", 3 | "env": { 4 | "es6": true, 5 | "browser": true, 6 | "jest": true 7 | }, 8 | "extends": [ 9 | "eslint:recommended", 10 | "plugin:react/recommended" 11 | ], 12 | "plugins": [ 13 | "react", 14 | "import" 15 | ], 16 | "rules": { 17 | "indent": ["error", 2, { SwitchCase: 1 }], 18 | "import/order": [ 19 | "error" 20 | ], 21 | "no-unused-vars": [ 22 | "error", 23 | { 24 | "args": "none" 25 | } 26 | ] 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /.githooks/pre-commit: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | ./node_modules/.bin/eslint src __tests__ 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | coverage 2 | jsconfig.json 3 | .vscode 4 | 5 | # OSX 6 | # 7 | .DS_Store 8 | 9 | # Xcode 10 | # 11 | build/ 12 | *.pbxuser 13 | !default.pbxuser 14 | *.mode1v3 15 | !default.mode1v3 16 | *.mode2v3 17 | !default.mode2v3 18 | *.perspectivev3 19 | !default.perspectivev3 20 | xcuserdata 21 | *.xccheckout 22 | *.moved-aside 23 | DerivedData 24 | *.hmap 25 | *.ipa 26 | 27 | # Android/IJ 28 | # 29 | .idea 30 | .gradle 31 | local.properties 32 | 33 | # node.js 34 | # 35 | node_modules/ 36 | npm-debug.log 37 | example/CalendarStrip 38 | package-lock.json 39 | yarn.lock 40 | 41 | # BUCK 42 | buck-out/ 43 | \.buckd/ 44 | android/app/libs 45 | android/keystores/debug.keystore 46 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | example -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | When contributing to this repository, please first discuss the change you wish to make via issue, 4 | email, or any other method with the owners of this repository before making a change. 5 | 6 | Please note we have a code of conduct, please follow it in all your interactions with the project. 7 | 8 | ## Pull Request Process 9 | 10 | 1. Ensure any install or build dependencies are removed before the end of the layer when doing a 11 | build. 12 | 2. Update the README.md with details of changes to the interface, this includes new environment 13 | variables, exposed ports, useful file locations and container parameters. 14 | 3. Increase the version numbers in any examples files and the README.md to the new version that this 15 | Pull Request would represent. The versioning scheme we use is [SemVer](http://semver.org/). 16 | 4. You may merge the Pull Request in once you have the sign-off of two other developers, or if you 17 | do not have permission to do that, you may request the second reviewer to merge it for you. 18 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | Copyright (c) 2016 Bogdan Begovic 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 5 | 6 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 7 | 8 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

react-native-calendar-strip

2 |
3 | Easy to use and visually stunning calendar component for React Native. 4 |
5 |
6 |
7 | 8 | npm package version 9 | 10 | 11 | npm downloads 12 | 13 | 14 | standard JS linter 15 | 16 | 17 | project license 18 | 19 | 20 | make a pull request 21 | 22 | All Contributors 23 |
24 |
25 |
26 | 27 | Github Watch Badge 28 | 29 | 30 | Github Star Badge 31 | 32 | 33 | Tweet 34 | 35 |
36 |
37 |
38 | Built with ❤︎ by BugiDev and contributors 39 |
40 | 41 |

Table of Contents

42 |
  • Install
  • 43 |
  • Usage
  • 44 |
  • Props
  • 45 |
  • Animations
  • 46 |
  • Localization
  • 47 |
  • Device Specific Notes
  • 48 |
  • Local Development
  • 49 |
  • Contributing
  • 50 |
  • License
  • 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 |
    69 | 70 |
    71 | 72 |
    73 | 74 | ```jsx 75 | import { View, StyleSheet } from 'react-native'; 76 | import CalendarStrip from 'react-native-calendar-strip'; 77 | 78 | const Example = () => ( 79 | 80 | 89 | 90 | ); 91 | 92 | const styles = StyleSheet.create({ 93 | container: { flex: 1 } 94 | }); 95 | ``` 96 | 97 |
    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 |
    104 | 105 |
    106 | 107 |
    108 | 109 | ```jsx 110 | import { View, StyleSheet } from 'react-native'; 111 | import CalendarStrip from 'react-native-calendar-strip'; 112 | 113 | const Example = () => ( 114 | 115 | 118 | 119 | ); 120 | 121 | const styles = StyleSheet.create({ 122 | container: { flex: 1 } 123 | }); 124 | ``` 125 | 126 |
    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 |
    133 | 134 |
    135 | 136 |
    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 | 158 | 176 | 177 | ); 178 | } 179 | } 180 | 181 | AppRegistry.registerComponent('Example', () => Example); 182 | ``` 183 | 184 |
    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 Below | 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 markedDatesFormat. | 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 | 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 | 245 | ); 246 | ``` 247 | 248 | ##### markedDates Example 249 |
    250 | marked dates example 251 |
    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: , 263 | selectedColor: (optional), 264 | }, 265 | ], 266 | }, 267 | { 268 | date: '(string, Date or Moment object)', 269 | lines: [ 270 | { 271 | color: , 272 | selectedColor: (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: , 288 | selectedColor: (optional), 289 | }] 290 | }; 291 | } 292 | // Line 293 | if (date.isoWeekday() === 6) { // Saturdays 294 | return { 295 | lines:[{ 296 | color: , 297 | selectedColor: (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 Below . | 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 |
    346 | Custom date styling example 347 |
    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 |
    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 | 384 | ); 385 | } 386 | ``` 387 |
    388 | 389 | ##### Callback Usage Example: 390 | 391 |
    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 | 410 | ); 411 | } 412 | ``` 413 |
    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 |
    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 |
    603 |
    604 | 605 | ## Device Specific Notes 606 | 607 |
      608 |
    • 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.
    • 609 |
    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 | | [
    Bogdan Begovic](https://github.com/BugiDev)
    [💬](#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") | [
    Peace](https://github.com/peacechen)
    [💬](#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") | [
    Chris Burns](http://www.usebillo.com)
    [💬](#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") | [
    samcolby](https://github.com/samcolby)
    [💻](https://github.com/bugidev/react-native-calendar-strip/commits?author=samcolby "Code") [⚠️](https://github.com/bugidev/react-native-calendar-strip/commits?author=samcolby "Tests") | [
    Florian Biebel](https://chromosom23.de)
    [💻](https://github.com/bugidev/react-native-calendar-strip/commits?author=1ne8ight7even "Code") | [
    Vitaliy Zhukov](http://intspirit.com/)
    [💻](https://github.com/bugidev/react-native-calendar-strip/commits?author=Vitall "Code") | [
    lbrdar](https://github.com/lbrdar)
    [💻](https://github.com/bugidev/react-native-calendar-strip/commits?author=lbrdar "Code") | 642 | | :---: | :---: | :---: | :---: | :---: | :---: | :---: | 643 | | [
    Dimka Vasilyev](https://github.com/gHashTag)
    [💻](https://github.com/bugidev/react-native-calendar-strip/commits?author=gHashTag "Code") | [
    Eugene](https://github.com/hellpirat)
    [💻](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. 654 | -------------------------------------------------------------------------------- /__tests__/CalendarHeader.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import { configure, shallow } from "enzyme"; 3 | import Adapter from "enzyme-adapter-react-16"; 4 | import moment from "moment"; 5 | 6 | import CalendarHeader from "../src/CalendarHeader"; 7 | 8 | configure({ adapter: new Adapter() }); 9 | 10 | const today = moment(); 11 | 12 | describe("CalendarHeader Component", () => { 13 | it("should render without issues", () => { 14 | const component = shallow( 15 | 22 | ); 23 | 24 | expect(component).toBeTruthy(); 25 | }); 26 | 27 | it("should render custom header without issues", () => { 28 | const component = shallow( 29 | 37 | ); 38 | 39 | expect(component).toBeTruthy(); 40 | }); 41 | }); 42 | -------------------------------------------------------------------------------- /__tests__/Scroller.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import { configure, shallow } from "enzyme"; 3 | import Adapter from "enzyme-adapter-react-16"; 4 | import moment from "moment"; 5 | 6 | import CalendarScroller from "../src/Scroller"; 7 | 8 | configure({ adapter: new Adapter() }); 9 | 10 | const today = moment(); 11 | 12 | describe("CalendarScroller Component", () => { 13 | it("should render without issues", () => { 14 | const component = shallow( 15 | 19 | ); 20 | 21 | expect(component).toBeTruthy(); 22 | }); 23 | 24 | }); 25 | -------------------------------------------------------------------------------- /__tests__/WeekSelector.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import { configure, shallow } from "enzyme"; 3 | import Adapter from "enzyme-adapter-react-16"; 4 | import moment from "moment"; 5 | 6 | import WeekSelector from "../src/WeekSelector"; 7 | 8 | configure({ adapter: new Adapter() }); 9 | 10 | const today = moment(); 11 | 12 | describe("WeekSelector Component", () => { 13 | it("should render without issues", () => { 14 | const component = shallow( 15 | 21 | ); 22 | 23 | expect(component).toBeTruthy(); 24 | }); 25 | 26 | }); 27 | -------------------------------------------------------------------------------- /example/.expo-shared/assets.json: -------------------------------------------------------------------------------- 1 | { 2 | "12bb71342c6255bbf50437ec8f4441c083f47cdb74bd89160c15e4f43e52a1cb": true, 3 | "40b842e832070c58deac6aa9e08fa459302ee3f9da492c7e77d93d2fbf4a56fd": true 4 | } 5 | -------------------------------------------------------------------------------- /example/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/**/* 2 | .expo/* 3 | npm-debug.* 4 | *.jks 5 | *.p8 6 | *.p12 7 | *.key 8 | *.mobileprovision 9 | *.orig.* 10 | web-build/ 11 | web-report/ 12 | 13 | # macOS 14 | .DS_Store 15 | -------------------------------------------------------------------------------- /example/App.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Sample React Native Calendar Strip 3 | * https://github.com/BugiDev/react-native-calendar-strip 4 | * @flow 5 | */ 6 | 7 | import React, { Component } from 'react'; 8 | import { View, Text, Button } from 'react-native'; 9 | import CalendarStrip from './CalendarStrip/CalendarStrip'; 10 | import moment from 'moment'; 11 | 12 | export default class App extends Component<{}> { 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. 19 | let customDatesStyles = []; 20 | let markedDates = []; 21 | for (let i=0; i<7; i++) { 22 | let date = startDate.clone().add(i, 'days'); 23 | 24 | customDatesStyles.push({ 25 | startDate: date, // Single date since no endDate provided 26 | dateNameStyle: {color: 'blue'}, 27 | dateNumberStyle: {color: 'purple'}, 28 | highlightDateNameStyle: {color: 'pink'}, 29 | highlightDateNumberStyle: {color: 'yellow'}, 30 | // Random color... 31 | dateContainerStyle: { backgroundColor: `#${(`#00000${(Math.random() * (1 << 24) | 0).toString(16)}`).slice(-6)}` }, 32 | }); 33 | 34 | let dots = []; 35 | let lines = []; 36 | 37 | if (i % 2) { 38 | lines.push({ 39 | color: 'cyan', 40 | selectedColor: 'orange', 41 | }); 42 | } 43 | else { 44 | dots.push({ 45 | color: 'red', 46 | selectedColor: 'yellow', 47 | }); 48 | } 49 | markedDates.push({ 50 | date, 51 | dots, 52 | lines 53 | }); 54 | } 55 | 56 | this.state = { 57 | selectedDate: undefined, 58 | customDatesStyles, 59 | markedDates, 60 | startDate, 61 | }; 62 | } 63 | 64 | datesBlacklistFunc = date => { 65 | return date.isoWeekday() === 6; // disable Saturdays 66 | } 67 | 68 | onDateSelected = selectedDate => { 69 | this.setState({ selectedDate }); 70 | this.setState({ formattedDate: selectedDate.format('YYYY-MM-DD')}); 71 | } 72 | 73 | setSelectedDateNextWeek = date => { 74 | const selectedDate = moment(this.state.selectedDate).add(1, 'week'); 75 | const formattedDate = selectedDate.format('YYYY-MM-DD'); 76 | this.setState({ selectedDate, formattedDate }); 77 | } 78 | 79 | setSelectedDatePrevWeek = date => { 80 | const selectedDate = moment(this.state.selectedDate).subtract(1, 'week'); 81 | const formattedDate = selectedDate.format('YYYY-MM-DD'); 82 | this.setState({ selectedDate, formattedDate }); 83 | } 84 | 85 | render() { 86 | return ( 87 | 88 | 108 | 109 | Selected Date: {this.state.formattedDate} 110 | 111 | 112 |