react-native-calendars

repository·master·Indexed 27 days ago

https://github.com/wix/react-native-calendars

A declarative, cross-platform React Native calendar component for iOS and Android. Written in pure JavaScript and compatible with Expo, it provides components like Calendar, Agenda, and AgendaList. Features include date marking, custom themes, locale configuration via LocaleConfig, and extensive customization for headers, arrows, and date constraints.

Tokens
20K
Snippets
33
Records
102
Agent score
92%

What's inside react-native-calendars

  1. Use the CalendarList component

    master

    CalendarList is a scrollable, semi-infinite calendar composed of multiple Calendar components. It supports both vertical and horizontal scrolling. It inherits all props from the standard Calendar component, plus additional configuration for scroll range and layout.

    <CalendarList
      // Callback which gets executed when visible months change in scroll view. Default = undefined
      onVisibleMonthsChange={(months) => {console.log('now these months are visible', months);}}
      // Max amount of months allowed to scroll to the past. Default = 50
      pastScrollRange={50}
      // Max amount of months allowed to scroll to the future. Default = 50
      futureScrollRange={50}
      // Enable or disable scrolling of calendar list
      scrollEnabled={true}
      // Enable or disable vertical scroll indicator. Default = false
      showScrollIndicator={true}
      ...calendarParams
    />
  2. Configure horizontal scrolling in CalendarList

    master

    To switch from vertical to horizontal scrolling, set the horizontal prop to true. You can also enable pagingEnabled for a snap-to-page effect and must provide a calendarWidth to define the width of the calendar during horizontal scrolling.

    <CalendarList
      // Enable horizontal scrolling, default = false
      horizontal={true}
      // Enable paging on horizontal, default = false
      pagingEnabled={true}
      // Set custom calendarWidth.
      calendarWidth={320}
      ...calendarListParams
      ...calendarParams
    />
  3. Use the Agenda component

    master

    The Agenda component provides a combined calendar and list view, allowing users to see a calendar at the top and a list of items for the selected day below. It extends props from CalendarList and FlatList.

    To use it, you must provide an items object where keys are date strings (e.g., '2012-05-22') and values are arrays of objects representing the items for that day. To represent an empty date, use an empty array []. If a date key is missing entirely, the component treats it as not yet loaded.

    <Agenda
      items={{
        '2012-05-22': [{name: 'item 1 - any js object'}],
        '2012-05-23': [{name: 'item 2 - any js object', height: 80}],
        '2012-05-24': [],
        '2012-05-25': [{name: 'item 3 - any js object'}, {name: 'any js object'}]
      }}
      // ... other props
    />
  4. Handle nested testIDs in complex components

    master

    Some components render other components internally. In these cases, the testID of the internal element is a concatenation of the entire render hierarchy's IDs.

    For example, if you use ExpandableCalendar with testID="myExpandableCalendar", the hierarchy is: ExpandableCalendar -> CalendarList -> Calendar -> Day.

    To query a Day element within an ExpandableCalendar, the format is: ${parentTestID}.calendarList.item_${year}-${month}.day_${date_string}

  5. Query Calendar components in tests using testID

    master
    Each component in react-native-calendars accepts a testID prop. Internal elements are identified by concatenating the provided testID with a specific element type or data suffix. To query specific elements like days or headers in your testing suite (e.g., using React Native Testing Library), you must construct the string following the component's specific format.