react-native-calendars README

The project's README from github.com/wix/react-native-calendars. As one markdown file: README.md.

Stand With Ukraine

React Native Calendars 🗓️ 📆

A declarative cross-platform React Native calendar component for iOS and Android.

Version Build status

This module includes information on how to use this customizable React Native calendar component.

The package is compatible with both Android and iOS


Official documentation

This README provides basic examples of how to get started with react-native-calendars. For detailed information, refer to the official documentation site.

Features ✨

Try it out ⚡

You can run a sample module using these steps:

$ git clone [email protected]:wix/react-native-calendars.git

$ cd react-native-calendars

$ yarn install

$ cd ios && pod install && cd ..

$ react-native run-ios

You can check example screens source code in example module screens

This project is compatible with Expo/CRNA (without ejecting), and the examples have been published on Expo

Getting Started 🔧

Here's how to get started with react-native-calendars in your React Native project:

Install the package:

$ yarn add react-native-calendars

RN Calendars is implemented in JavaScript, so no native module linking is required.

Usage 🚀

Basic usage examples of the library

For detailed information on using this component, see the official documentation site

Importing the Calendar component

import {Calendar, CalendarList, Agenda} from 'react-native-calendars';

Use the Calendar component in your app:

<Calendar
  onDayPress={day => {
    console.log('selected day', day);
  }}
/>

Some Code Examples

Here are a few code snippets that demonstrate how to use some of the key features of react-native-calendars:

Creating a basic calendar with default settings:

import React, {useState} from 'react';
import {Calendar, LocaleConfig} from 'react-native-calendars';

const App = () => {
  const [selected, setSelected] = useState('');

  return (
    <Calendar
      onDayPress={day => {
        setSelected(day.dateString);
      }}
      markedDates={{
        [selected]: {selected: true, disableTouchEvent: true, selectedDotColor: 'orange'}
      }}
    />
  );
};

export default App;

Customize the appearance of the calendar:

<Calendar
  // Customize the appearance of the calendar
  style={{
    borderWidth: 1,
    borderColor: 'gray',
    height: 350
  }}
  // Specify the current date
  current={'2012-03-01'}
  // Callback that gets called when the user selects a day
  onDayPress={day => {
    console.log('selected day', day);
  }}
  // Mark specific dates as marked
  markedDates={{
    '2012-03-01': {selected: true, marked: true, selectedColor: 'blue'},
    '2012-03-02': {marked: true},
    '2012-03-03': {selected: true, marked: true, selectedColor: 'blue'}
  }}
/>

Configuring the locale:

import {LocaleConfig} from 'react-native-calendars';
import React, {useState} from 'react';
import {Calendar, LocaleConfig} from 'react-native-calendars';

LocaleConfig.locales['fr'] = {
  monthNames: [
    'Janvier',
    'Février',
    'Mars',
    'Avril',
    'Mai',
    'Juin',
    'Juillet',
    'Août',
    'Septembre',
    'Octobre',
    'Novembre',
    'Décembre'
  ],
  monthNamesShort: ['Janv.', 'Févr.', 'Mars', 'Avril', 'Mai', 'Juin', 'Juil.', 'Août', 'Sept.', 'Oct.', 'Nov.', 'Déc.'],
  dayNames: ['Dimanche', 'Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi'],
  dayNamesShort: ['Dim.', 'Lun.', 'Mar.', 'Mer.', 'Jeu.', 'Ven.', 'Sam.'],
  today: "Aujourd'hui"
};

LocaleConfig.defaultLocale = 'fr';

const App = () => {
  const [selected, setSelected] = useState('');

  return (
    <Calendar
      onDayPress={day => {
        setSelected(day.dateString);
      }}
      markedDates={{
        [selected]: {selected: true, disableTouchEvent: true, selectedDotColor: 'orange'}
      }}
    />
  );
};

export default App;

Adding a global theme to the calendar:

    <Calendar
      style={{
        borderWidth: 1,
        borderColor: 'gray',
        height: 350,
      }}
      theme={{
        backgroundColor: '#ffffff',
        calendarBackground: '#ffffff',
        textSectionTitleColor: '#b6c1cd',
        selectedDayBackgroundColor: '#00adf5',
        selectedDayTextColor: '#ffffff',
        todayTextColor: '#00adf5',
        dayTextColor: '#2d4150',
        textDisabledColor: '#dd99ee'
      }}
    />

Customized Calendar Examples

Calendar

Dot marking

Multi-Dot marking

Period Marking

Multi-Period marking

Custom marking

Date loading indicator

Scrollable semi-infinite calendar

Horizontal calendar

Agenda


Authors

See also the list of contributors who participated in this project.

Contributing

We welcome contributions to react-native-calendars.

If you have an idea for a new feature or have discovered a bug, please open an issue.

Please yarn test and yarn lint before pushing changes.

Don't forget to add a title and a description explaining the issue you're trying to solve and your proposed solution.

Screenshots and Gifs are VERY helpful to add to the PR for reviews.

Please DO NOT format the files - we're trying to keep a unified syntax and keep the reviewing process fast and simple.

License

React Native Calendars is MIT licensed

react-native-calendars (wix/react-native-calendars)

Searching Database…

这是什么?这是一套由 Wix 维护、可用于 React Native 应用的可自定义日历组件。你把它们添加到自己的项目中,用来显示日历和选择日期。
这是一个独立的日历应用,还是我添加到自己项目里的组件?它是一个组件库。你从 npm 安装 react-native-calendars 软件包,然后在你的 React Native 页面中渲染它的组件——没有可供下载的应用。
我怎么把它加到我的应用里?用 npm 或 yarn 安装这个软件包,然后导入你需要的组件即可。它是纯 JavaScript,所以不需要链接原生模块的步骤。
使用它需要从 Expo 弹出(eject)或改动原生代码吗?不需要。这个库可以在不弹出的情况下配合 Expo 和 CRNA 使用,它的示例页面也发布在 Expo 上,可以直接预览。
它能连接手机自带的日历应用吗?不能。它是纯 JavaScript,没有任何原生代码,所以它自己绘制和管理日历界面,而不是读取或同步设备的日历。
同一个组件在 iOS 和 Android 上都能用吗?可以——它是一个声明式、跨平台的组件,这个软件包同时兼容 Android 和 iOS。
我可以在商业应用里用它吗?可以——react-native-calendars 采用 MIT 许可证,商用没有问题。
除了选择单个日期,这个日历还能做什么?可以用圆点、多点、时段、多时段或完全自定义的标记来标注日期;你还可以允许或禁用某些日期、滚动到今天,并通过自定义渲染在月份之间左右滑动切换。
我能在多大程度上调整它的样式来配合我的应用设计?调整空间很大:日、月和单个日期的样式和内容都可以自定义,还可以为可滑动的日历应用全局主题或灵活的自定义渲染。
日期在其他语言和地区设置下能正确显示吗?可以——日历会自动按不同的地区设置格式化日期,README 里有配置语言环境的说明。
它对使用屏幕阅读器的用户友好吗?是的,无障碍支持被列在这个库的核心功能之中。
Creator
wix
Size
19.2 MB
Stars
10.3K
Age
9y
Commits · 90 Days