This module includes various customizable React-Native calendar components.
The package is both Android and iOS compatible.
You can run example module by performing these steps:
$ git clone git@github.com:wix/react-native-calendars.git
$ npm install
$ 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
$ npm install --save react-native-calendars
The solution is implemented in JavaScript so no native module linking is required.
import {
Calendar, CalendarList, Agenda} from 'react-native-calendars';
All parameters for components are optional. By default the month of current local date will be displayed.
Event handler callbacks are called with calendar objects
like this:
{
day: 1, // day of month (1-31)
month: 1, // month of year (1-12)
year: 2017, // year
timestamp, // UTC timestamp representing 00:00 AM of this date
dateString: '2016-05-13' // date formatted as 'YYYY-MM-DD' string
}
Parameters that require date types accept YYYY-MM-DD
formatted date-strings
, JavaScript date objects, calendar objects
and UTC timestamps
.
Calendars can be localized by adding custom locales to LocaleConfig
object:
import {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';
<Calendar
// Initially visible month. Default = Date()
current={'2012-03-01'}
// Minimum date that can be selected, dates before minDate will be grayed out. Default = undefined
minDate={'2012-05-10'}
// Maximum date that can be selected, dates after maxDate will be grayed out. Default = undefined
maxDate={'2012-05-30'}
// Handler which gets executed on day press. Default = undefined
onDayPress={(day) => {console.log('selected day', day)}}
// Handler which gets executed on day long press. Default = undefined
onDayLongPress={(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}
// If firstDay=1 week starts from Monday. Note that dayNames and dayNamesShort should still start from Sunday
firstDay={1}
// Hide day names. Default = false
hideDayNames={true}
// Show week numbers to the left. Default = false
showWeekNumbers={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}
/>
Disclaimer: Make sure that markedDates
param is immutable. If you change markedDates
object content but the reference to it does not change calendar update will not be triggered.
Dot marking
<Calendar
// Collection of dates that have to be marked. Default = {}
markedDates={{
'2012-05-16': {selected: true, marked: true, selectedColor: 'blue'},
'2012-05-17': {marked: true},
'2012-05-18': {marked: true, dotColor: 'red', activeOpacity: 0},
'2012-05-19': {disabled: true, disableTouchEvent: true}
}}
/>
You can customize a dot color for each day independently.
Multi-Dot marking
Use markingType={'multi-dot'}
if you want to display more than one dot. Both the <Calendar/>
and <CalendarList/>
support multiple dots by using dots
array in markedDates
prop.The property color
is mandatory while key
and selectedColor
are optional. If key is omitted then the array index is used as key. If selectedColor
is omitted then color
will be used for selected dates.
const vacation = {key: 'vacation', color: 'red', selectedDotColor: 'blue'};
const massage = {key: 'massage', color: 'blue', selectedDotColor: 'blue'};
const workout = {key: 'workout', color: 'green'};
<Calendar
markingType={'multi-dot'}
markedDates={{
'2017-10-25': {dots: [vacation, massage, workout], selected: true, selectedColor: 'red'},
'2017-10-26': {dots: [massage, workout], disabled: true}
}}
/>
Period marking
<Calendar
markingType={'period'}
markedDates={{
'2012-05-20': {textColor: 'green'},
'2012-05-22': {startingDay: true, color: 'green'},
'2012-05-23': {selected: true, endingDay: true, color: 'green', textColor: 'gray'},
'2012-05-04': {disabled: true, startingDay: true, color: 'green', endingDay: true}
}}
/>
Multi-period marking
CAUTION: This marking is only fully supported by the <Calendar/>
component because it expands its height. Usage with <CalendarList/>
might lead to overflow issues.
<Calendar
markingType='multi-period'
markedDates={{
'2017-12-14': {
periods: [
{startingDay: false, endingDay: true, color: '#5f9ea0'},
{startingDay: false, endingDay: true, color: '#ffa500'},
{startingDay: true, endingDay: false, color: '#f0e68c'}
]
},
'2017-12-15': {
periods: [
{startingDay: true, endingDay: false, color: '#ffa500'},
{color: 'transparent'},
{startingDay: false, endingDay: false, color: '#f0e68c'}
]
}
}}
/>
Custom marking allows you to customize each marker with custom styles.
<Calendar
markingType={'custom'}
markedDates={{
'2018-03-28': {
customStyles: {
container: {
backgroundColor: 'green'
},
text: {
color: 'black',
fontWeight: 'bold'
}
}
},
'2018-03-29': {
customStyles: {
container: {
backgroundColor: 'white',
elevation: 2
},
text: {
color: 'blue'
}
}
}
}}
/>
NEW! While we still don't support multi marking type, we add the possibility to combine between period
and simple
.
<Calendar
markingType={'period'}
markedDates={{
'2012-05-15': {marked: true, dotColor: '#50cebb'},
'2012-05-16': {marked: true, dotColor: '#50cebb'},
'2012-05-21': {startingDay: true, color: '#50cebb', textColor: 'white'},
'2012-05-22': {color: '#70d7c7', textColor: 'white'},
'2012-05-23': {color: '#70d7c7', textColor: 'white', marked: true, dotColor: 'white'},
'2012-05-24': {color: '#70d7c7', textColor: 'white'},
'2012-05-25': {endingDay: true, color: '#50cebb', textColor: 'white'}
}}
/>
Keep in mind that different marking types are not compatible. You can use just one marking style for a calendar.
The loading indicator next to the month name will be displayed if <Calendar/>
has displayLoadingIndicator
prop and the markedDates
collection does not have a value for every day of the month in question. When you load data for days, just set []
or special marking value to all days in markedDates
collection.
<Calendar
// Specify style for calendar container element. Default = {}
style={{
borderWidth: 1,
borderColor: 'gray',
height: 350
}}
// Specify theme properties to override specific styles for calendar parts. Default = {}
theme={{
backgroundColor: '#ffffff',
calendarBackground: '#ffffff',
textSectionTitleColor: '#b6c1cd',
textSectionTitleDisabledColor: '#d9e1e8',
selectedDayBackgroundColor: '#00adf5',
selectedDayTextColor: '#ffffff',
todayTextColor: '#00adf5',
dayTextColor: '#2d4150',
textDisabledColor: '#d9e1e8',
dotColor: '#00adf5',
selectedDotColor: '#ffffff',
arrowColor: 'orange',
disabledArrowColor: '#d9e1e8',
monthTextColor: 'blue',
indicatorColor: 'blue',
textDayFontFamily: 'monospace',
textMonthFontFamily: 'monospace',
textDayHeaderFontFamily: 'monospace',
textDayFontWeight: '300',
textMonthFontWeight: 'bold',
textDayHeaderFontWeight: '300',
textDayFontSize: 16,
textMonthFontSize: 16,
textDayHeaderFontSize: 16
}}
/>
<Calendar
theme={{
textSectionTitleDisabledColor: '#d9e1e8'
}}
markedDates={{
...this.getDisabledDates('2012-05-01', '2012-05-30', [0, 6])
}}
disabledDaysIndexes={[0, 6]}
/>
If you want to have complete control over the calendar styles you can do it by overriding default style.ts
files. For example, if you want to override <CalendarHeader/>
style first you have to find stylesheet id for this file:
https://github.com/wix/react-native-calendars/blob/master/src/calendar/header/style.ts#L60
In this case it is stylesheet.calendar.header
. Next you can add overriding stylesheet to your theme with this id.
https://github.com/wix/react-native-calendars/blob/master/example/src/screens/calendars.tsx#L142
theme={{
arrowColor: 'white',
'stylesheet.calendar.header': {
week: {
marginTop: 5,
flexDirection: 'row',
justifyContent: 'space-between'
}
}
}}
Using the above advanced styling, it is possible to set styles independently for each day's header. If we wanted to make the header for Sunday red, and Saturday blue, we could write something like the following:
theme={{
'stylesheet.calendar.header': {
dayTextAtIndex0: {
color: 'red'
},
dayTextAtIndex6: {
color: 'blue'
}
}
}}
Disclaimer: Issues that arise because something breaks after using stylesheet override will not be supported. Use this option at your own risk.
If you need custom functionality not supported by current day component implementations you can pass your own custom day component to the calendar.
<Calendar
style={[styles.calendar, {height: 300}]}
dayComponent={({date, state}) => {
return (
<View>
<Text style={{textAlign: 'center', color: state === 'disabled' ? 'gray' : 'black'}}>
{date.day}
</Text>
</View>
);
}}
/>
The dayComponent
prop has to receive a RN component or a function that receive props. The dayComponent
will receive such props:
markedDates
value for this day.Tip: Don't forget to implement shouldComponentUpdate()
for your custom day component to make the calendar perform better
If you implement an awesome day component please make a PR so that other people could use it :)
<CalendarList/>
is scrollable semi-infinite calendar composed of <Calendar/>
components. Currently it is possible to scroll 4 years back and 4 years to the future. All parameters that are available for <Calendar/>
are also available for this component. There are also some additional params that can be used:
<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
/>
You can also make the CalendarList
scroll horizontally. To do that you need to pass specific props to the CalendarList
:
<CalendarList
// Enable horizontal scrolling, default = false
horizontal={true}
// Enable paging on horizontal, default = false
pagingEnabled={true}
// Set custom calendarWidth.
calendarWidth={320}
...calendarListParams
...calendarParams
/>
An advanced Agenda
component that can display interactive listings for calendar day items.
<Agenda
// The list of items that have to be displayed in agenda. If you want to render item as empty date
// the value of date key has to be an empty array []. If there exists no value for date key it is
// considered that the date in question is not yet loaded
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'}]
}}
// 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={'2012-05-16'}
// Minimum date that can be selected, dates before minDate will be grayed out. Default = undefined
minDate={'2012-05-10'}
// Maximum date that can be selected, dates after maxDate will be grayed out. Default = undefined
maxDate={'2012-05-30'}
// 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}
// 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 />);}}
// Specify your item comparison function for increased performance
rowHasChanged={(r1, r2) => {return r1.text !== r2.text}}
// Hide knob button. Default = false
hideKnob={true}
// When `true` and `hideKnob` prop is `false`, the knob will always be visible and the user will be able to drag the knob up and close the calendar. Default = false
showClosingKnob={false}
// By default, agenda dates are marked if they have at least one item, but you can override this if needed
markedDates={{
'2012-05-16': {selected: true, marked: true},
'2012-05-17': {marked: true},
'2012-05-18': {disabled: true}
}}
// If disabledByDefault={true} dates flagged as not disabled will be enabled. Default = false
disabledByDefault={true}
// If provided, a standard RefreshControl will be added for "Pull to Refresh" functionality. Make sure to also set the refreshing prop correctly
onRefresh={() => console.log('refreshing...')}
// Set this true while waiting for new data from a refresh
refreshing={false}
// Add a custom RefreshControl component, used to provide pull-to-refresh functionality for the ScrollView
refreshControl={null}
// Agenda theme
theme={{
...calendarTheme,
agendaDayTextColor: 'yellow',
agendaDayNumColor: 'green',
agendaTodayColor: 'red',
agendaKnobColor: 'blue'
}}
// Agenda container style
style={{}}
/>
See also the list of contributors who participated in this project.
Pull requests are most welcome!Please npm run test
and npm run lint
before push.Don't forget to add a title and a description that explain the issue you're trying to solve and your suggested solution.Screenshots and gifs are VERY helpful.Please do NOT format the files as we are trying to keep a unified syntax and the reviewing process fast and simple.
今天介绍一些react-native-calendars的使用方法 npm网站点击这里 属性介绍: current:设置当前日期,当前日期不设置默认是当日 minDate&&maxDate:设置可选择日期的最小值和最大值 monthFormat:设置头部月份显示的格式 onDayPress:(方法)点击某日时触发 onMonthChange:(方法)切换月份的时候触发 hideArrows:(布尔
1、React Native获取组件的宽高 2、以及React Native屏幕dp与px转换计算; import React, {Component} from 'react'; import { Text, View, findNodeHandle, UIManager, TouchableOpacity, Dimensions, PixelRatio, } from 'react-nativ
1. 格式化日期 Date.prototype.Format = function (fmt) { var o = { "M+": this.getMonth() + 1, //月份 "d+": this.getDate(), //日 "h+": this.getHours(), //小时 "m+": thi
this.props.children 属性表示组件的所有子节点。利用this.props.children可以实现插槽功能。 class Index extends React.Component{ render(){ return <View> <Sub color="red"> <View><Text>++++++++</Text></View>
rn动画:http://blog.csdn.net/hello_hwc/article/details/51775696 股票金融类app:https://github.com/7kfpun/FinanceReactNative 图形表:https://github.com/wuxudong/react-native-charts-wrapper 好看的日历控件:https://github.co
因为业务需求,定义只包含年月的日期,react-native自带组件不符合,第三方鸡肋,于是自己写一个,安卓和IOS样式不同,自己体验 调用方法示例: import PickerData from '..//Picker'; <PickerData visible={store.visibleReferee} onCancel={ () => { store.visib
转自: https://www.jianshu.com/p/bd810785d3d6 本文收录了,React Native中常用的一些相关组件, 摘录的过程中,可能有所差错,不足之处还望指出. 希望大家可以互相学习,互帮互助! 第一部分 基于react-navigation组件的自定义 head 视图 react-native-carousel 轮播图 react-native-countdown
ES6 1、() => {} 箭头函数在RN里面尤为重要,扮演着bind(this)的作用,从此就可以告别闭包了。 2、promise在写法上没有async/await简洁好用,async/await直接把异步写出了同步的感觉。 3、… 这样语法糖也是简化了太多的代码。 4、util和api可以用static关键字 ScrollView 1、可以用onScroll来监听滑动的距离等参数。 2、可以
React Native 配置自定义字体 本想着配置自定义字体不是什么大坑,官网文档找了一下,没有。遂关键字:“React Native 配置自定义字体”这么一搜。都是一样的文章,作者名却是各式各样,真是天下文章大家抄。然而试了一下并不好用。 (这里使用最新的RN 0.48.4 测试) 这里想一下React Nativ… 这些JavaScript编程黑科技,装逼指南,高逼格代码,让你惊叹不已 这些
本文向大家介绍react-native 启动React Native Packager,包括了react-native 启动React Native Packager的使用技巧和注意事项,需要的朋友参考一下 示例 在最新版本的React Native上,无需运行打包程序。它将自动运行。 默认情况下,这将在端口8081上启动服务器。要指定服务器所在的端口
百度移动统计SDK支持使用react native框架的H5页面统计,封装好的插件已经在github上开源,相关用法具体请参考:https://github.com/BaiduMobileAnalysis/baidumobstat-react-native。
The React Native environment has a lot of little quirks, so this documentation is aimed at helping smooth those over. Please feel free to create issues on GitHub for recommendations and additions to t
React Native 可以基于目前大热的开源JavaScript库React.js来开发iOS和Android原生App。而且React Native已经用于生产环境——Facebook Groups iOS 应用就是基于它开发的。 React Native的原理是在JavaScript中用React抽象操作系统原生的UI组件,代替DOM元素来渲染,比如以<View>取代<div>,以<Ima
本文向大家介绍react-native setState,包括了react-native setState的使用技巧和注意事项,需要的朋友参考一下 示例 要在应用程序中更改视图,可以使用setState-这将重新渲染您的组件及其任何子组件。setState在新状态和先前状态之间执行浅表合并,并触发组件的重新呈现。 setState 接受键值对象或返回键值对象的函数 键值对象 功能 使用函数对于基于
诸葛io移动统计支持React Native插件,以下为集成方法。 1. 环境准备 1.1. iOS环境 iOS 8.0+ 代码支持iOS8.0的系统 pod 1.0+ iOS系统的集成依赖于cocoaPod工具 1.2. Android环境 Android SDK 16+ 代码支持Android 16+ 1.3. React Native环境 react-native 0.50+ react-n
ZhiHuDaily-React-Native 是使用 React Native for Android 实现的知乎日报客户端。 此项目使用 React Native 主要特性: Flex Style Direct Manipulation Native UI Components DrawerLayoutAndroid Image/Text/ListView TouchableHighlight
基于react-native实现的博客园移动客户端,兼容android和ios 功能列表: 用户登录 & 个人信息查看 博文列表 & 博文评论列表 & 博文评论添加 & 我的博文列表 & 博文离线 & 博文收藏 新闻列表 & 新闻评论列表 & 新闻评论添加 & 新闻离线 & 新闻收藏 闪存列表 & 闪存评论列表 & 闪存评论添加 & 新增闪存 & 我的闪存列表 博问列表 & 博问回答列表 & 博问