Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-native-calendars

Package Overview
Dependencies
Maintainers
2
Versions
1643
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-calendars

React Native Calendar Components

  • 1.1307.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
2
Created

What is react-native-calendars?

The react-native-calendars package provides a set of customizable calendar components for React Native applications. It allows developers to create various types of calendar views, including agenda views, calendar lists, and marked dates. The package is highly flexible and supports a wide range of customization options, making it suitable for different use cases such as scheduling, event planning, and date selection.

What are react-native-calendars's main functionalities?

Basic Calendar

This code demonstrates how to create a basic calendar using the react-native-calendars package. It includes various customization options such as setting the initial visible month, minimum and maximum selectable dates, handling day and month changes, and hiding navigation arrows.

import { Calendar } from 'react-native-calendars';

const MyCalendar = () => (
  <Calendar
    // Initially visible month. Default = Date()
    current={'2023-10-01'}
    // Minimum date that can be selected, dates before minDate will be grayed out. Default = undefined
    minDate={'2023-05-10'}
    // Maximum date that can be selected, dates after maxDate will be grayed out. Default = undefined
    maxDate={'2023-12-31'}
    // Handler which gets executed on day press. Default = undefined
    onDayPress={(day) => {console.log('selected day', day)}}
    // Month format in calendar title. Formatting values: http://arshaw.com/xdate/#Formatting
    monthFormat={'yyyy MM'}
    // Handler which gets executed when visible month changes in calendar. Default = undefined
    onMonthChange={(month) => {console.log('month changed', month)}}
    // Hide month navigation arrows. Default = false
    hideArrows={true}
    // Replace default arrows with custom ones (direction can be 'left' or 'right')
    renderArrow={(direction) => (<Arrow />)}
    // Do not show days of other months in month page. Default = false
    hideExtraDays={true}
    // If hideArrows=false and hideExtraDays=false do not switch month when tapping on greyed out day from another month that is visible in calendar page. Default = false
    disableMonthChange={true}
    // Handler which gets executed when press arrow icon left. It receive a callback can go back month
    onPressArrowLeft={subtractMonth => subtractMonth()}
    // Handler which gets executed when press arrow icon right. It receive a callback can go next month
    onPressArrowRight={addMonth => addMonth()}
    // Disable left arrow. Default = false
    disableArrowLeft={true}
    // Disable right arrow. Default = false
    disableArrowRight={true}
    // Disable all touch events for disabled days. can be override with disableTouchEvent in markedDates
    disableAllTouchEventsForDisabledDays={true}
    // Replace default month and year title with custom one. the function receive a date as parameter
    renderHeader={(date) => {/*Return JSX*/}}
    // Enable the option to swipe between months. Default = false
    enableSwipeMonths={true}
  />
);

Agenda View

This code demonstrates how to create an agenda view using the react-native-calendars package. The agenda view displays a list of items for each day, allowing users to see their schedule at a glance. The component supports various customization options, including rendering custom items, days, and empty dates.

import { Agenda } from 'react-native-calendars';

const MyAgenda = () => {
  const items = {
    '2023-10-22': [{name: 'item 1 - any js object'}],
    '2023-10-23': [{name: 'item 2 - any js object'}],
    '2023-10-24': [],
    '2023-10-25': [{name: 'item 3 - any js object'}, {name: 'any js object'}]
  };

  return (
    <Agenda
      items={items}
      // Callback that gets called when items for a certain month should be loaded (month became visible)
      loadItemsForMonth={(month) => {console.log('trigger items loading')}}
      // Callback that fires when the calendar is opened or closed
      onCalendarToggled={(calendarOpened) => {console.log(calendarOpened)}}
      // Callback that gets called on day press
      onDayPress={(day) => {console.log('day pressed')}}
      // Callback that gets called when day changes while scrolling agenda list
      onDayChange={(day) => {console.log('day changed')}}
      // Initially selected day
      selected={'2023-10-16'}
      // Minimum date that can be selected, dates before minDate will be grayed out. Default = undefined
      minDate={'2023-05-10'}
      // Maximum date that can be selected, dates after maxDate will be grayed out. Default = undefined
      maxDate={'2023-12-31'}
      // Max amount of months allowed to scroll to the past. Default = 50
      pastScrollRange={12}
      // Max amount of months allowed to scroll to the future. Default = 50
      futureScrollRange={12}
      // Specify how each item should be rendered in agenda
      renderItem={(item, firstItemInDay) => {return (<View />);}}
      // Specify how each date should be rendered. day can be undefined if the item is not first in that day.
      renderDay={(day, item) => {return (<View />);}}
      // Specify how empty date content with no items should be rendered
      renderEmptyDate={() => {return (<View />);}}
      // Specify how agenda knob should look like
      renderKnob={() => {return (<View />);}}
      // Specify what should be rendered instead of ActivityIndicator
      renderEmptyData={() => {return (<View />);}}
      // If disabledByDefault={true} dates flagged as not disabled will be enabled. Default = false
      disabledByDefault={true}
      // If hideKnob={true} calendar knob will not be displayed. Default = false
      hideKnob={true}
      // Agenda theme
      theme={{
        agendaDayTextColor: 'yellow',
        agendaDayNumColor: 'green',
        agendaTodayColor: 'red',
        agendaKnobColor: 'blue'
      }}
      // Agenda container style
      style={{}}
    />
  );
};

Marked Dates

This code demonstrates how to mark specific dates on the calendar using the react-native-calendars package. The marked dates feature allows developers to highlight important dates, such as events or deadlines, with different styles and colors.

import { Calendar } from 'react-native-calendars';

const MyMarkedDatesCalendar = () => (
  <Calendar
    // Collection of dates that have to be marked. Default = {}
    markedDates={{
      '2023-10-16': {selected: true, marked: true, selectedColor: 'blue'},
      '2023-10-17': {marked: true},
      '2023-10-18': {disabled: true, disableTouchEvent: true}
    }}
    // Date marking style [simple/period/multi-dot/custom]. Default = 'simple'
    markingType={'multi-dot'}
  />
);

Other packages similar to react-native-calendars

FAQs

Package last updated on 18 Sep 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc