GithubHelp home page GithubHelp logo

christopherdro / react-native-calendar Goto Github PK

View Code? Open in Web Editor NEW
536.0 17.0 244.0 2.11 MB

[DEPRECATED] Calendar Component for React Native

License: MIT License

Objective-C 14.59% JavaScript 75.27% Python 5.73% Java 4.41%

react-native-calendar's Introduction

⚠️ Deprecated ⚠️

This library is no longer being actively maintained. Try https://github.com/wix/react-native-calendars

react-native-calendar

A <Calendar> component for React Native

Portrait mode only

Installation

npm install react-native-calendar --save

Usage

<Calendar
  currentMonth={'2015-08-01'}       // Optional date to set the currently displayed month after initialization
  customStyle={{day: {fontSize: 15, textAlign: 'center'}}} // Customize any pre-defined styles
  dayHeadings={Array}               // Default: ['S', 'M', 'T', 'W', 'T', 'F', 'S']
  eventDates={['2015-07-01']}       // Optional array of moment() parseable dates that will show an event indicator
  events={[{date:'2015-07-01', ..}]}// Optional array of event objects with a date property and custom styles for the event indicator
  monthNames={Array}                // Defaults to english names of months
  nextButtonText={'Next'}           // Text for next button. Default: 'Next'
  onDateSelect={(date) => this.onDateSelect(date)} // Callback after date selection
  onDateLongPress={(date) => this.onDateLongPress(date)} // Callback after date is long pressed
  onSwipeNext={this.onSwipeNext}    // Callback for forward swipe event
  onSwipePrev={this.onSwipePrev}    // Callback for back swipe event
  onTouchNext={this.onTouchNext}    // Callback for next touch event
  onTouchPrev={this.onTouchPrev}    // Callback for prev touch event
  onTitlePress={this.onTitlePress}  // Callback on title press
  prevButtonText={'Prev'}           // Text for previous button. Default: 'Prev'
  removeClippedSubviews={false}     // Set to false for us within Modals. Default: true
  renderDay={<CustomDay />}         // Optionally render a custom day component
  scrollEnabled={true}              // False disables swiping. Default: False
  selectedDate={'2015-08-15'}       // Day to be selected
  showControls={true}               // False hides prev/next buttons. Default: False
  showEventIndicators={true}        // False hides event indicators. Default:False
  startDate={'2015-08-01'}          // The first month that will display. Default: current month
  titleFormat={'MMMM YYYY'}         // Format for displaying current month. Default: 'MMMM YYYY'
  today={'2017-05-16'}              // Defaults to today
  weekStart={1} // Day on which week starts 0 - Sunday, 1 - Monday, 2 - Tuesday, etc, Default: 1
/>

Available custom styles

There are a number of pre-defined styles in the calendar. Below, we will give an example of how each of them can be changed depending on your use case.

calendarContainer

calendarContainer changes the background of the calendar.

const Schedule = () => {
  const customStyle = {
    calendarContainer: {
      backgroundColor: 'blue',
    },
  }
  return <Calendar customStyle={customStyle} />
}

calendarContainer

calendarControls

calendarControls changes only the bar on the top that contains the month and year by default, but can also contain controls for changing the month.

const Schedule = () => {
  const customStyle = {
    calendarControls: {
      backgroundColor: 'blue',
    },
  }
  return <Calendar customStyle={customStyle} />
}

calendarControls

calendarHeading

calendarHeading changes the bar that contains the days of the week.

const Schedule = () => {
  const customStyle = {
    calendarHeading: {
      backgroundColor: 'blue',
    },
  }
  return <Calendar customStyle={customStyle} />
}

calendarHeading

controlButton

controlButton shows the next and previous buttons that allow you to change the current month. The showControls prop must be passed through to <Calendar /> in order for this style to take effect.

const Schedule = () => {
  const customStyle = {
    controlButton: {
      backgroundColor: 'blue',
    },
  }
  return (
    <Calendar
      showControls
      customStyle={customStyle} />
  )
}

controlButton

controlButtonText

controlButtonText applies styles to the text that is rendered when the showControls prop is true. The text can also be changed using the prevButtonText and nextButtonText props.

const Schedule = () => {
  const customStyle = {
    controlButtonText: {
      color: 'blue',
    },
  }
  return (
    <Calendar
      showControls
      customStyle={customStyle} />
  )
}

controlButtonText

currentDayCircle

currentDayCircle changes the style of the background behind the currently-selected day when the currently-selected day is today.

const Schedule = () => {
  const customStyle = {
    currentDayCircle: {
      backgroundColor: 'blue',
    },
  }
  return <Calendar customStyle={customStyle} />
}

currentDayCircle

currentDayText

currentDayText changes the style of the current day (defaults to red) to differentiate it from other days.

const Schedule = () => {
  const customStyle = {
    currentDayText: {
      color: 'blue',
    },
  }
  return <Calendar customStyle={customStyle} />
}

currentDayText

day

day changes the text of every day other than today and weekend days.

const Schedule = () => {
  const customStyle = {
    day: {
      color: 'blue',
    },
  }
  return <Calendar customStyle={customStyle} />
}

day

dayButton

dayButton changes the background behind all valid days.

const Schedule = () => {
  const customStyle = {
    dayButton: {
      backgroundColor: 'blue',
    },
  }
  return <Calendar customStyle={customStyle} />
}

dayButton

dayButtonFiller

dayButtonFiller styles the background behind all invalid days.

const Schedule = () => {
  const customStyle = {
    dayButtonFiller: {
      backgroundColor: 'blue',
    },
  }
  return <Calendar customStyle={customStyle} />
}

dayButtonFiller

dayCircleFiller

dayCircleFiller styles a circle around all days other than the active day.

const Schedule = () => {
  const customStyle = {
    dayCircleFiller: {
      backgroundColor: 'blue',
    },
  }
  return <Calendar customStyle={customStyle} />
}

dayCircleFiller

dayHeading

dayHeading styles the text for non-weekend days in the day of the week bar.

const Schedule = () => {
  const customStyle = {
    dayHeading: {
      color: 'blue',
    },
  }
  return (
    <Calendar
    showEventIndicators
    customStyle={customStyle} />
  )
}

dayHeading

eventIndicator

eventIndicator styles the event indicator bubble for days that have events. Must pass either an events array or eventDates array and have showEventIndicators passed as true for the event indicators to display.

const Schedule = () => {
  const customStyle = {
    eventIndicator: {
      backgroundColor: 'blue',
      width: 10,
      height: 10,
    },
  }
  return (
    <Calendar
      showEventIndicators
      eventDates={['2016-11-01', '2016-11-07', '2016-11-19']}
      customStyle={customStyle} />
  )
}

eventIndicator

eventIndicatorFiller

eventIndicatorFiller styles the event indicator space for days that do not have events. Must pass showEventIndicators as true for the event indicators to display.

const Schedule = () => {
  const customStyle = {
    eventIndicatorFiller: {
      backgroundColor: 'blue',
      width: 10,
      height: 10,
    },
  }
  return (
    <Calendar
      showEventIndicators
      eventDates={['2016-11-01', '2016-11-07', '2016-11-19']}
      customStyle={customStyle} />
  )
}

eventIndicatorFiller

hasEventCircle

hasEventCircle styles the circle around the days that have events associated with them. Must pass either an events array or eventDates array and have showEventIndicators passed as true for the event indicators to display.

const Schedule = () => {
  const customStyle = {
    hasEventCircle: {
      backgroundColor: 'blue',
    },
  }
  return (
    <Calendar
      showEventIndicators
      eventDates={['2016-11-01', '2016-11-07', '2016-11-19']}
      customStyle={customStyle} />
  )
}

hasEventCircle

hasEventDaySelectedCircle

hasEventDaySelectedCircle styles the circle around the selected day that have events associated with them. Must pass either an events array or eventDates array and have showEventIndicators passed as true for the event indicators to display.

const Schedule = () => {
  const customStyle = {
    hasEventCircle: {
      backgroundColor: 'blue',
    },
    hasEventDaySelectedCircle: {
      backgroundColor: 'red',
  	},
  }
  return (
    <Calendar
      showEventIndicators
      eventDates={['2016-12-03', '2016-12-21', '2016-12-22', '2016-12-30']}
      customStyle={customStyle} />
  )
}

hasEventText

hasEventText styles the text of the days that have events associated with them. Must pass either an events array or eventDates array and have showEventIndicators passed as true for the event indicators to display.

const Schedule = () => {
  const customStyle = {
    hasEventText: {
      backgroundColor: 'blue',
    },
  }
  return (
    <Calendar
      showEventIndicators
      eventDates={['2016-11-01', '2016-11-07', '2016-11-19']}
      customStyle={customStyle} />
  )
}

hasEventText

monthContainer

monthContainer styles the background behind the month.

const Schedule = () => {
  const customStyle = {
    monthContainer: {
      backgroundColor: 'blue',
    },
  }
  return <Calendar customStyle={customStyle} />
}

monthContainer

selectedDayCircle

selectedDayCircle styles the circle behind any selected day other than today.

const Schedule = () => {
  const customStyle = {
    selectedDayCircle: {
      backgroundColor: 'blue',
    },
  }
  return <Calendar customStyle={customStyle} />
}

selectedDayCircle

selectedDayText

selectedDayText styles the text of the currently-selected day.

const Schedule = () => {
  const customStyle = {
    selectedDayText: {
      color: 'blue',
    },
  }
  return <Calendar customStyle={customStyle} />
}

selectedDayText

title

title styles the title at the top of the calendar. titleText styles text within title.

const Schedule = () => {
  const customStyle = {
    title: {
      color: 'blue',
    },
    titleText: {
      fontSize: 12,
    },
  }
  return <Calendar customStyle={customStyle} />
}

title

weekendDayButton

weekendDayButton styles the weekends background.

const Schedule = () => {
  const customStyle = {
    weekendDayButton: {
      backgroundColor: 'red',
    },
  }
  return <Calendar customStyle={customStyle} />
}

weekendDayButton

weekendDayText

weekendDayText styles the text of weekends.

const Schedule = () => {
  const customStyle = {
    weekendDayText: {
      color: 'blue',
    },
  }
  return <Calendar customStyle={customStyle} />
}

weekendDayText

weekendHeading

weekendHeading styles the text of the weekend heading.

const Schedule = () => {
  const customStyle = {
    weekendHeading: {
      color: 'blue',
    },
  }
  return <Calendar customStyle={customStyle} />
}

weekendHeading

weekRow

weekRow styles the background of the row associated with each week.

const Schedule = () => {
  const customStyle = {
    weekRow: {
      backgroundColor: 'blue',
    },
  }
  return <Calendar customStyle={customStyle} />
}

weekRow

TODOS

  • Improve swipe feature
  • Language support

DEMO

Demo gif

react-native-calendar's People

Contributors

aforty avatar albertwchang avatar alex-hofsteede avatar andreyco avatar bitholic avatar bradbyte avatar christopherdro avatar coderdave avatar creamtreacle avatar daemonchen avatar devanymoe avatar dragfire avatar dsibiski avatar g6ling avatar hyb175 avatar jankcat avatar joshjhargreaves avatar kgallet avatar lofgrenfredrik avatar mrharel avatar mrtoph avatar nikolaiwarner avatar noitcudni avatar rouralberto avatar samcorcos avatar simonmarton avatar tomaskulich avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-native-calendar's Issues

Min/Max date

Component is missing min/max date.
I feel like I will implement this. If you are about to, please, let me know - I will pay attention to other things (onDateSelect seems a bit slow - I experience ~1s delay between press & callback)

Edit Multiple Style of calendar view using customStyle props

customStyle={({ eventIndicator: { backgroundColor: '#ff0000' } },
{ eventIndicatorFiller: { marginTop: 10, width: 10 } },
{ currentDayCircle: { backgroundColor: 'black' } })}

when I used above code, It is only editing currentDayCircle not all three.

can you please tell me how to edit multiple style at once by using customStyle props.

changing events prop with onTouch events

i'm creating a calendar with day events by doing something like this (irrelevant props removed):

set_events(month) {
  this.setState({ events: [] });
}
<Calendar
events={this.state.events}
onTouchPrev={(month) => this.set_events(month)
/>

when i change the month, set_events(month) is ran correctly but unless the events array is empty, it skips a month, ie if i'm moving from october to september, september events are loaded but calendar is rendered for august.

am i missing something? thanks

wrong initial state in Android

Hi Guys,

I am using this calendar in our project and whenever i switch to the page which has this calendar in android the initial view is wrong. shows some dates and current month but it is not correct. look at attachment for what i get on the load. once i click on any dates then it shows correct view, any comments? this only happens in android.

initial load
screen shot 2016-12-29 at 11 57 45 pm

Add support for hasEventDaySelectedCircle?

Hello, thanks for this amazing library first of all.

I'm just wondering is there any style configuration to styling the circle of event days, but only for selected state.

Currently if I use hasEventCircle the circle will turns into the defined background color even there already has an indicator below.

So I'm looking for something like hasEventDaySelectedCircle or selectedEventIndicator, thank you very much.

Ability to overwrite styles

Would be great to have ability to overwrite various style to customize the control to the L&F of the app. border colors, fonts, highlight colors etc.

Not able to set width to 1/3 device width for example

Hi,
First, thanks for the great calendar, it really looks nice, has a lot of features. The one problem I have is I'm trying to use it on ipad inside the popover, so it shouldn't be full width, the popover is not so big it should be probably 1/3 of device width. I have problems setting custom width, the top header and buttons look ok but the cells for days are too wide, it looks like they are made to fit calendar in full width (device width). Is there a way to set a custom width of a calendar and have day cells look as they should?

Thanks.

Feature request: Customizable start date

Hi,

yet another feature request: the current calendar sesms to start with "Sun" all the time. It'd be nice if one is able to customize the starting date, i.e. having "Monday" at the very left of the calendar.

Regards
Philipp

Slow load when shown from an on tap event /w scroll enabled

There is a long pause when the cal is shown as a result of a state change after the initial render. This seems to only be an issue when scroll is enabled.

If anyone has any suggestions or direction on this i'd be happy to work on it and do a pull request.

How do I refresh another component after a day is selected?

Hi there,

I need to have call a API based on a selected date and show list of items with that selected date. Can you suggest a way to do this? It might not be this component related question and more of react native but couldn't find anywhere else to ask this. Thank you in advance.

Thanks

Multiple events per day

Is there any way to have show multiple events per day, right now?

I've tried adding the same day multiple times in the event array with different styles, but only the last event is shown:

  <Calendar
      weekStart={1}
      scrollEnabled
      showControls
      showEventIndicators
      eventDates={['2016-12-03', '2016-12-04', '2016-12-28', '2016-12-30']}
      events={[{date: '2016-12-04', eventIndicator: {backgroundColor: 'powderblue'}}, {date: '2016-12-04', eventIndicator: {backgroundColor: 'red'}}]}
  />

Should appear both blue and red indicators on 2016-12-04:

Days (numbers) not in line with days of the week header when using margin

Hi,
I'm using the iPhone 5 simulator and the days are not aligned with the days of the week. The header shows fine, but the last column of days (numbers) shows just half. I've tryed to reduce the size of the day font but it's the same.

Another problem I'm facing is, everytime I press one day, the calendar scrolls to the previous month.

Regards.

Inconsistency in passing value to callbacks

I spotted inconsistency in callback values. Namely these:
onSwipePrep and onSwipeNext receive moment instance.
onDateSelected receives date in plain string format.

Unifying this issue is essentially a breaking change, but it would be nice to be consistent.

Feature request: Multi-selection

Hi,

I'd be nice to be able to select multiple dates by swiping from a start date to an end date (or simply clicking both days after each other).

In case I can support, drop me a line here. :)

Regards
Philipp

Can we remove usingEvents prop in Day.js?

For example:

if there is no events in 2016 October, the eventIndicatorFiller view won't be there, the height of day is 65, then if we change date to 2016 Nov, let's say there are events in this month, then the eventIndicatorFiller view will be render , the height of day will be 70 (if the eventIndicatorFiller view height is 5), it will cause page flash for row height change.

Can we remove the usingEvents props? instead we can always keep the view there, we can show the indicator based on the events, but i don't want the page shake

Prev month and next month

Hello,

Instead of showing the words 'prev' and 'next', it's better to show the name and previous month and next month, example:
If current displayed month is 'Nov', show 'Oct' on the left and 'Dec' on the right.

Thanks,

Add license to repo.

Is there any chance we could add an explicit license to this project (hopefully MIT?).
Thanks :).

CustomStyle

Hey there,

First off, thank you for uploading the calendar for every to use its awesome.

I was trying to change the style of the calendar using the syntax that you posted on your page, but it seems not to be working.

For example, to change the currentDayCircle I used this code but it would not work.

<Calendar
style={{flex: 0.7}}
ref="calendar"
showControls={true}
titleFormat={'MMMM YYYY'}
prevButtonText={'<'}
nextButtonText={'>'}
onDateSelect={this.handleDatePress}
customStyle={{currentDayCircle: {backgroundColor : 'blue' }}}/>

I was wondering if this was a bug? Thank you for your help.

Layout is broken on RN 0.28

calendarControls has unnecessary flex: 1 which breaks in RN 0.28.

Extracted from release notes:

Updates to css-layout leading to many fixes but requiring some breaking changes:

  • flex styling property behavior now behaves slightly differently. If you previously used flex: 1 where not necessary this change will likely break your layout as the measuring behavior is slightly different than before due to performance optimizations. Removing that unnecessary flex: 1 will solve your layout in most cases.
  • Due to performance tweaks flexWrap: wrap no longer works together with alignItems: 'stretch' (the default). If you use flexWrap: wrap you probably will want to add the alignItems: 'flex-start' style as well.

Fixed via one of commits from PR #42

Change year

I don't know if this is possible but is there a way to change year on click or swipe?
If I want to allow users to easily add dates from 50 years ago?

I can't seem to find this fuctionality.

Unable to resolve module from moment

After trying to test this calendar module I replaced the index.ios.js with the example, I get and error in the simulator "Unable to resolve module moment from ... Unable to find this module in its module map or any of the node_modules directories under ... and its parent directories. "

It gave a suggestion to fix but I tried and still get this issue. Any clue what the issue might be?

Disable past dates

Hi,
Thank you for this great library 👍 !
I've customized this library to disable past dates by passing property called pastDisabled.
What do you think about this customization? I can send pull request if you dont mind.

Thank you

question: How to add date to calendar

Hi, I try to make a link but i don't find any documentation about that, someone knows how to make a link to add date to calendar app? thanks y'all.

Slow load time

I have been testing this module on iPhone 6S, the date selection is pretty slow.

Let me know if there are any tweaks that I could try to make it faster.

Thanks.

Readme doc issue

The scrollEnabled props defaults to false according to tests, but the doc says that the default value is True.

When trying an example and selecting a date: Warning: setState(...): Can only update a mounted or mounting component...

Hi,

It looks like I can't make a use of the date selected because of this issue.
Please advise.

Thanks,
Alex

Code:

<Calendar ref="calendar" eventDates={['2016-07-03', '2016-07-05', '2016-07-28', '2016-07-30']} scrollEnabled showControls dayHeadings={customDayHeadings} monthNames={customMonthNames} titleFormat={'MMMM YYYY'} prevButtonText={'Prev'} nextButtonText={'Next'} onDateSelect={(date) => this.setState({ selectedDate: date })} onTouchPrev={() => console.log('Back TOUCH')} // eslint-disable-line no-console onTouchNext={() => console.log('Forward TOUCH')} // eslint-disable-line no-console onSwipePrev={() => console.log('Back SWIPE')} // eslint-disable-line no-console onSwipeNext={() => console.log('Forward SWIPE')} // eslint-disable-line no-console /> <Text>Selected Date: {moment(this.state.selectedDate).format('MMMM DD YYYY')}</Text>

screen shot 2016-06-21 at 4 47 29 pm

Wrong start date on Android

Hey @christopherdro ,

I have tried to set a start date(2016-09-10T03:00:00.000Z) and it work very well on iOS, however on Android it changes the date that is visible on calendar showing 2 months ago.

<Calendar
          scrollEnabled={true}
          showControls={true}
          titleFormat={'MMMM'}
          dayHeadings={dayLabels}
          monthNames={monthLabels}
          prevButtonText={<Icon name="ios-arrow-back-outline" color="white" size={30} />}
          nextButtonText={<Icon name="ios-arrow-forward-outline" color="white" size={30} />}
          onDateSelect={(date) => handleDateSelection(date)}
          onTouchPrev={this.onTouchPrev}
          onTouchNext={this.onTouchNext}
          onSwipePrev={this.onSwipePrev}
          onSwipeNext={this.onSwipeNext}
          eventDates={eventDates}
          startDate={startDate}
          customStyle={calendarStyle}
          weekStart={0}
        />

screen shot 2016-10-20 at 11 38 40

Show full year instead of month?

Hi,
I have a case where I need to show events in a full year to be similar to the html version (client wants it).

I was gonna try and write a calendar myself and I stumbled upon this.
Is it possible to show 12 months one under another in a ScrollView ?

Regards,
Akondo

Remove the last table-row if it's not being used?

Hey!

Loving the calendar and using it in an app I'm working on atm.

I was just wondering if it's possible somehow to get rid of the very last table row if it's not being used?
This would enable me to push the content up a little more on some months and not to have a gap there.

I have attached a screenshot!

Thanks
David
screen shot 2016-06-21 at 14 41 03

Slow load time

I'm not sure how it is on other devices, but the load time is so slow on my Nexus (Android). In my emulator it goes fast, but probably due to being on a computer...

If I click menu link 'events' it waits like 4 seconds then it goes to the events page with the Calendar.

Am I the only one with this problem?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.