@changwoolab/react-native-big-calendar

中文文档
6.1.0发布于 2024/09/10MITTypeScriptESM + CJS近 30 天下载 2342
中文使用文档
文档目录19 节
  1. 帮助我调试此组件
  2. 其他依赖关系
  3. 类型脚本
  4. 网上的使用
  5. 事件渲染器
  6. ICalendar EventBase 日历
  7. 小时渲染器
  8. 全天活动
  9. 使用自定义事件渲染函数
  10. 显示事件笔记
  11. 主题
  12. I18n 时
  13. 丰富事件逻辑( 绩效提示)
  14. 执行数据结构
  15. 多日活动
  16. 丰富事件渲染器
  17. 预处理数据
  18. 设置
  19. 开始

test release npm version

反应-内生-大日历

跨平台 gcal/ 外观为 React Natural 的日历组件 .

帮助我调试此组件

在三个平台上调试这个库是一项艰巨的任务. 我通常先用Web版本开发,然后用真正的设备确认其功能. 我的电脑是Linux,我的手机是Android,所以在Android上很容易测试,但是要在iOS上调试,我必须把我的Macbook Pro从我的车库拿来,连接我妻子的iPhone并测试. 每次我推出我的"MacBook Pro"时,都需要更新Xcode,甚至需要完成一个完整的系统更新. 开始调试需要很长时间. 由于React Industrial在iOS上的工作优于Android,我 永远 有时会跳过测试,所以iOS上应该有bug. 如果你帮我调试,我会很感激的!

模块

特征

  • 交叉平台:在网络,iOS,Android上运行,具有回放的力量
  • 类型安全: 完全写入类型脚本
  • 自定义: 能够提供您自己的主题, 并传递您的组件来渲染 .
  • 轻量:~9KB(min + gzip),依赖是 dayjs 财务报告和审定财务报表 calendarize

安装

npm install --save react-native-big-calendar

或者如果你用雅恩的话:

yarn add react-native-big-calendar

其他依赖关系

请确保安装对等依赖 .

npm install react react-native

类型脚本

如果使用类型脚本保证 @types/react 财务报告和审定财务报表 @types/react-native 已安装. react-native-big-calendar 内部使用.

npm install --save-dev @types/react @types/react-native

网上的使用

如果您在网络上使用此模块, 请安装 react-native-web。 。 。 .

npm install react-native-web

如果您正在使用 Create React App, 您已经准备好去QQ

详见官方反应-内设-网络安装指南.

https://github.com/necolas/ react-native-web 互联网档案馆的存檔,存档日期2013-12-21

开始

import { Calendar } from 'react-native-big-calendar'

const events = [
  {
    title: 'Meeting',
    start: new Date(2020, 1, 11, 10, 0),
    end: new Date(2020, 1, 11, 10, 30),
  },
  {
    title: 'Coffee break',
    start: new Date(2020, 1, 11, 15, 45),
    end: new Date(2020, 1, 11, 16, 30),
  },
]

function App() {
  return <Calendar events={events} height={600} />
}

API 文档

内容提要

export interface CalendarProps<T extends ICalendarEventBase> {
  events: T
  height: number
  overlapOffset?: number
  hourRowHeight?: number
  ampm?: boolean
  date?: Date
  eventCellStyle?: EventCellStyle<T>
  eventCellAccessibilityProps?: AccessibilityProps
  eventCellTextColor?: string
  allDayEventCellStyle?: allDayEventCellStyle<>
  allDayEventCellAccessibilityProps?: AccessibilityProps
  calendarCellAccessibilityPropsForMonthView?: AccessiblityProps
  allDayEventCellTextColor?: string
  calendarContainerStyle?: ViewStyle
  calendarCellAccessibilityProps?: AccessibilityProps
  headerContainerStyle?: ViewStyle
  headerContainerAccessibilityProps?: AccessibilityProps
  headerCellAccessibilityProps?: AccessibilityProps
  bodyContainerStyle?: ViewStyle
  renderEvent?: (
    event: T,
    touchableOpacityProps: CalendarTouchableOpacityProps,
  ) => ReactElement | null
  renderHeader?: React.ComponentType<CalendarHeaderProps<T> & { mode: Mode }>
  renderHeaderForMonthView?: React.ComponentType<CalendarHeaderForMonthViewProps>
  locale?: string
  hideNowIndicator?: boolean
  mode?: Mode
  scrollOffsetMinutes?: number
  showTime?: boolean
  minHour?: number
  maxHour?: number
  swipeEnabled?: boolean
  weekStartsOn?: WeekNum
  weekEndsOn?: WeekNum
  onChangeDate?: DateRangeHandler
  onPressCell?: (date: Date) => void
  onPressDateHeader?: (date: Date) => void
  onPressEvent?: (event: ICalendarEvent<T>) => void
  eventMinHeightForMonthView?: number
  activeDate?: Date
  moreLabel?: string
  showAdjacentMonths?: boolean
  sortedMonthView?: boolean
  showVerticalScrollIndicator?: boolean
  timeslots?: number
}

<Calendar /> 道具为:

名称所需经费类型说明
events对ICalendarEvent<T>[]日历上的活动。 您可以扩展类型 ICalendarEvent 提供通用类型 T 的值(参见 ./stories/events.tsx (以举例而言) 具有在事件内显示自定义组件的可选子,并具有可选事件渲染器功能,以完全控制被渲染出的事件(高级功能). 在同一时间范围内发生的事件将被分层、相抵并指定独特的颜色.
height对number日历高度.
hideNowIndicator没有boolean隐藏当前时间的指标。 默认情况下,将显示现在的指标.
hourRowHeight没有number小时行高
onPressEvent没有(event: ICalendarEvent<T>) => void事件处理器, 当用户点击一个事件时, 将会开火 .
onChangeDate没有([start: Date, end: Date]) => void事件处理器, 当当前日期范围改变时会开火 .
onPressCell没有(date: Date) => void当单击当前日期单元格时将启用的事件处理器 。 分钟设定到0.
onLongPressCell没有(date: Date) => void和上面一样,但被长长的媒体所触发.
onPressDateHeader没有(date: Date) => void事件处理器, 当用户从信头点击日期时, 将会开火 .
mode没有'month' | 'week' | '3days' | 'day' | 'schedule' | 'custom'
eventCellStyle没有ViewStyle | (event: ICalendarEvent<T>) => ViewStyle事件细胞的风格. 接受样式对象(静态)或函数(动态).
eventCellAccessiblityProps没有AccessibilityProps事件单元格的可访问性
eventCellTextColor没有string事件单元格文本的颜色 .
allDayEventCellStyle没有ViewStyle | (event: ICalendarEvent<T>) => ViewStyle全天事件单元的风格. 接受样式对象(静态)或函数(动态).
allDayEventCellTextColor没有string全天事件单元格文本的颜色 .
allDayEventCellAccessibilityProps没有AccessibilityProps全天事件单元格文本的可访问性 .
calendarCellAccessibilityProps没有AccessibilityProps日历体中细胞的可访问性,包括数小时的细胞.
calendarCellAccessibilityPropsForMonthView没有AccessibilityProps月视图日历正文中日期单元格的可访问性 .
headerContentStyle没有ViewStyle标题内容的风格. 接受样式对象(静态).
headerContainerAccessibilityProps没有AccessibilityPropsHeader 容器的接通性正体 使用此设定来控制屏幕阅读器以识别整个标题行为单个可访问元素
headerCellAccessibilityProps没有AccessibilityProps头部细胞的接合器.
dayHeaderStyle没有ViewStyleHeader日号的风格. 接受样式对象(静态).
dayHeaderHighlightColor没有stringHeader突出日号的风格. 接受样式对象(静态).
weekDayHeaderHighlightColor没有stringHeader突出的周日的风格. 接受样式对象(静态).
scrollOffsetMinutes没有number在一天中滚动到特定的分钟。 例如) 设定 480 当日历显示时, 滚动到8: 00.
date没有Date日历的初始日期。 默认为 new Date (当前时间).
onSwipeEnd没有(date: Date) => void事件处理器,在向左或向右擦去时会开火。 提醒您的功能, 防止无源重现
swipeEnabled没有boolean
showTime没有boolean
minHour没有number以周/日模式显示的第一个小时 .
maxHour没有number以周/日模式显示的最后一小时 .
ampm没有boolean使用12小时的时间格式而不是24小时.
weekStartsOn没有0 | 1 | 2 | 3 | 4 | 5 | 6这周哪天开始? 周日为 0。 。 。 .
weekEndsOn没有0 | 1 | 2 | 3 | 4 | 5 | 6哪个星期结束? 周日为 0。 。 。 .
locale没有string自定义地盘 。 见I18n节
overlapOffset没有number调整同期所发生事件的缩进. 默认为网络上20个,移动上8个.
isRTL没有boolean切换布局的方向,以便使用RTL语言。 默认为假.
renderEvent没有EventRenderer自定义事件渲染器 。 见下文类型定义.
renderHeader没有HeaderRenderer自定义页眉渲染器.
eventMinHeightForMonthView没有number月视图中事件的迷你元高. 应当符合您的定制事件 。 默认为22.
activeDate没有Date以页眉突出日期 。 默认为今天( 当前时间) .
headerComponent没有ReactElement日历正文标题组件 .
headerComponentStyle没有ViewStyle日历正文标题组件包装样式 。 接受样式对象(静态)
hourStyle没有TextStyle日历时数造型。 接受样式对象(静态)
showAllDayEventCell没有boolean显示/隐藏全天事件单元格的布尔
moreLabel没有string在月视图中替换更多标签的字符串 。 默认 : “ { moreCount} More'. { moreCount} 已被额外事件数所取代
showAdjacentMonths没有boolean在月视图中显示/ 隐藏相邻月份的布尔 。 默认为真
sortedMonthView没有boolean(用于表演)布尔用于月视图中的排序事件. 默认为真
isEventOrderingEnabled没有boolean布尔用于在所有视图中排序事件 。 默认为真
renderCustomDateForMonth没有boolean日期单元格自定义渲染器
disableMonthEventCellPress没有boolean防止月视图事件单元格被按下 。 默认为虚假
itemSeparatorComponent没有ReactElement单项中的反应组件 schedule 模式。 参考 反应原生平板 ItemSeparatorComponent 需要更多信息.
enrichedEventsByDate没有Record<string, T[](用于表演) 丰富事件词典,将使用,而不是在库中构建.
enableEnrichedEvents没有boolean(用于执行) 浓缩事件 逻辑 默认为虚假
eventsAreSorted没有boolean(用于性能) 跳过库内事件排序的布尔已排序 。 默认为虚假
showWeekNumber没有boolean显示周数. 周数将显示在周/日模式的左上角和月模式的每行起始处
weekNumberPrefix没有string周号前缀. 对于月份模式,前缀会以头行显示.
maxVisibleEventCount没有number在月视图中单元格中显示的最大事件数 。 如果事件数量超过此值,单元格将显示 moreLabel。默认为 3.
timeslots没有number每小时的乘数。 默认为 0
hourComponent没有HourRenderer自定义小时渲染器

事件渲染器

type EventRenderer<T> = (
  event: ICalendarEvent<T>,
  touchableOpacityProps: CalendarTouchableOpacityProps,
) => ReactElement | null

更多信息见 故事书

ICalendar EventBase 日历

interface ICalendarEventBase {
  start: Date
  end: Date
  title: string
  children?: ReactElement | null
  disabled?: boolean
}

小时渲染器

type HourRenderer = {
  appm: boolean
  hour: number
}

全天活动

所有日事均应以时,分,秒(T:00:00)开始并结束. 例如:

{
    title: 'all day event',
    start: "2021-12-24T00:00:00.000Z",
    end: "2021-12-24T00:00:00.000Z", // same date as `start`
}

使用自定义事件渲染函数

您可以指定接收计算结果的自定义事件渲染函数 TouchableOpacity 螺旋桨和 event。 。 。 .

  • 职能 renderEvent 必须返回 ReactElement。 。 。 .
  • 构成部分 应 被包裹在一个 TouchableOpacity 或者说 任意 接受定位和单击事件的DOM元素(onPress(中文(简体) ).
export interface MyCustomEventType {
  color: string
}

const renderEvent = <T extends ICalendarEventBase>(
  event: T,
  touchableOpacityProps: CalendarTouchableOpacityProps,
) => (
  <TouchableOpacity {...touchableOpacityProps}>
    <Text>{`My custom event: ${event.title} with a color: ${event.color}`}</Text>
  </TouchableOpacity>
)

<Calendar renderEvent={renderEvent} />

显示事件笔记

您的事件可以包含一个道具 children 可以找到一个实例 这里。 。 。 .

const eventNotes = useMemo(
  () => (
    <View style={{ marginTop: 3 }}>
      <Text style={{ fontSize: 10, color: 'white' }}> Phone number: 555-123-4567 </Text>
      <Text style={{ fontSize: 10, color: 'white' }}> Arrive 15 minutes early </Text>
    </View>
  ),
  [],
)

export const myEvents: ICalendarEventBase[] = [
  {
    title: 'Custom reminder',
    start: dayjs().set('hour', 16).set('minute', 0).toDate(),
    end: dayjs().set('hour', 17).set('minute', 0).toDate(),
    children: eventNotes,
  },
]

主题

您可以自定义日历 theme 道具 (英语). theme 应该像这个接口 :

export interface Palette {
  main: string
  contrastText: string
}

export type Typography = Pick<
  TextStyle,
  'fontFamily' | 'fontWeight' | 'fontSize' | 'lineHeight' | 'letterSpacing' | 'textAlign'
>

export interface ThemeInterface {
  palette: {
    primary: Palette
    nowIndicator: string
    gray: {
      100: string
      200: string
      300: string
      500: string
      800: string
    }
    moreLabel: string
  }
  isRTL: boolean
  typography: {
    fontFamily?: string
    xs: Typography
    sm: Typography
    xl: Typography
    moreLabel: Typography
  }
  eventCellOverlappings: readonly Palette[]
  moreLabel: TextStyle
}

例如:

const darkTheme = {
  palette: {
    primary: {
      main: '#6185d0',
      contrastText: '#000',
    },
    gray: {
      '100': '#333',
      '200': '#666',
      '300': '#888',
      '500': '#aaa',
      '800': '#ccc',
    },
  },
}

<Calendar
  height={SCREEN_HEIGHT}
  theme={darkTheme}
/>

I18n 时

请通过您的地址 locale 道具 财务报告和审定财务报表 导入 day.js locale 文件 :

import 'dayjs/locale/ja'

<Calendar
  locale="ja"
  {/* ... */}
/>

你可以在这里找到你的日地:

https://github.com/iamkun/dayjs/tree/dev/src/locale 互联网档案馆的存檔,存档日期2013-12-22

丰富事件逻辑( 绩效提示)

执行数据结构

我们创建并缓存一个按日期键的字典,其中包含所有事件属性以及重叠的计数:

{
    [YYYY-MM-DD]: [
        {
            ...all event information,
            overlapPosition: int
            overlapCount: int
        }
    ]
}

多日活动

当一个活动跨出多天时,我们会为它的每一天创造出一个新的活动. 例如从2021-05-01起起至2021-05-03起止的事件将作为3起事件进行代表,每天一次,并配有以下时间道具: 1

--- First day
2021-05-01: {
   ...other data
   start: event start datetime
   end: current day midnight
}
-- All the intermediate days:
2021-05-02: {
   ...other data
   start: previous day midnight
   end: current day midnight
}
-- Final day
2021-05-03: {
   ...other data
   start: previous day midnight
   end: event start datetime
}

丰富事件渲染器

优化的渲染器从词典中获取每个事件,并在不添加过滤或排序等任何额外逻辑的情况下来渲染.

预处理数据

你可以自己编字典,通过道具寄到图书馆 enrichedEventsByDate。 。 。 .

例如,当您想要在背景工作中构建词典时, 这样做特别有用 .

在真实设备上运行演示并开发

设置

检查后,请运行:

yarn install
yarn sync-rndemo
cd rndemo
yarn install

开始

在演示目录中启动 React 原生开发服务器 :

cd rndemo
yarn start

然后,打开另一个终端运行:

# For ios
pod install
yarn ios

# For Android
yarn android

每次修改此库的代码时, 您应该在根目录中运行以下命令 :

yarn sync-rndemo

截图

谁用这个?

如果你使用这个图书馆,请发送公关 添加你的组织!

发起人

企业支助

首先,谢谢你对这个项目的兴趣。 随着这个图书馆越来越出名,很多人都要求具备他们需要的特征. 我想尽可能地回应他们 但我在做这项工作的时间有限 要成为全职开放源代码,使这个项目可持续,我决定增加企业支持.

企业客户可以获得:

  • 完全定制,如颜色,标志,图像,等等.
  • 优先应对与发展.
  • React, TypeScript, 和 React Indust 应用程序的咨询 .

请注意,一些企业功能也将与开放源码软件版本合并.

如果您对这些功能感兴趣,请发电子邮件给: [email protected] (英语)

聘请我

我是一个自由职业的软件工程师,专门研究反应,反应原生和TypeScript. 还可用于GraphQL和RDB后端,以及Node.JS应用.

如果您有兴趣雇用我,请发电子邮件给: [email protected] (英语)

我住在日本(在美丽的海边),所以远程合同工作特别受欢迎.

版本与发布记录

@changwoolab/react-native-big-calendar 共发布 17 个版本,首次发布于 2023/12/12;过去 12 个月发布了 0 个版本。

版本发布日期距今
6.1.0latest2024/09/102 年前
6.0.02024/02/012 年前
5.1.42024/01/042 年前
5.1.32024/01/042 年前
5.1.22024/01/042 年前
5.1.12024/01/042 年前

关于 @changwoolab/react-native-big-calendar 的常见问题

@changwoolab/react-native-big-calendar 是什么?

[[npm版本] (https://badge.fury.io/js/resact-native-big-calendar.sv 互联网档案馆的存檔,存档日期2014-12-02

如何安装 @changwoolab/react-native-big-calendar?

在项目目录运行 npm install @changwoolab/react-native-big-calendar,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(*)、react-native(*)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@changwoolab/react-native-big-calendar 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@changwoolab/react-native-big-calendar 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@changwoolab/react-native-big-calendar 可以商用吗?

@changwoolab/react-native-big-calendar 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@changwoolab/react-native-big-calendar 的下载量有多少?

根据 npm 官方下载统计,@changwoolab/react-native-big-calendar 在 2026/10/10 – 2026/11/08 这 30 天内被下载 2,342 次,日均约 78 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@changwoolab/react-native-big-calendar 还在维护吗?

最新版本 6.1.0 发布于 2024/09/10(2 年前);至今共发布 17 个版本,其中过去 12 个月发布了 0 个;首次发布于 2023/12/12。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。