React Native日历日程组件

这次介绍的这个React Native日历日程组件名叫react-native-calendars,是纯JS开发,可以适配IOS和安卓双平台。使用方便,功能强大,可以通过配置自定义样式和主题,更重要的是它支持日程显示。下面我们来看看这个组件的使用方法。

http://mp.weixin.qq.com/s/zS4VbGJh4WVxkP9xMIN3iw

安装

 
 
  1. npm install --save react-native-calendars

因为是纯JS的,所以不需要link,执行完就可以了。

使用

react-native-calendars主要包含三种子组件,分别是 Calendar(日历), CalendarList(日历列表), Agenda(日程),可以根据实际需要选择使用。下面我们分别介绍这三种组件的使用示例。

Calendar(日历)

示例代码
 
 
  1. <Calendar

  2.  // Initially visible month. Default = Date()

  3.  current={'2012-03-01'}

  4.  // Minimum date that can be selected, dates before minDate will be grayed out. Default = undefined

  5.  minDate={'2012-05-10'}

  6.  // Maximum date that can be selected, dates after maxDate will be grayed out. Default = undefined

  7.  maxDate={'2012-05-30'}

  8.  // Handler which gets executed on day press. Default = undefined

  9.  onDayPress={(day) => {console.log('selected day', day)}}

  10.  // Month format in calendar title. Formatting values: http://arshaw.com/xdate/#Formatting

  11.  monthFormat={'yyyy MM'}

  12.  // Handler which gets executed when visible month changes in calendar. Default = undefined

  13.  onMonthChange={(month) => {console.log('month changed', month)}}

  14.  // Hide month navigation arrows. Default = false

  15.  hideArrows={true}

  16.  // Replace default arrows with custom ones (direction can be 'left' or 'right')

  17.  renderArrow={(direction) => (<Arrow />)}

  18.  // Do not show days of other months in month page. Default = false

  19.  hideExtraDays={true}

  20.  // If hideArrows=false and hideExtraDays=false do not switch month when tapping on greyed out

  21.  // day from another month that is visible in calendar page. Default = false

  22.  disableMonthChange={true}

  23.  // If firstDay=1 week starts from Monday. Note that dayNames and dayNamesShort should still start from Sunday.

  24.  firstDay={1}

  25.  // Hide day names. Default = false

  26.  hideDayNames={true}

  27. />

CalendarList(日历列表)

示例代码
 
 
  1. <CalendarList

  2.  // Callback which gets executed when visible months change in scroll view. Default = undefined

  3.  onVisibleMonthsChange={(months) => {console.log('now these months are visible', months);}}

  4.  // Max amount of months allowed to scroll to the past. Default = 50

  5.  pastScrollRange={50}

  6.  // Max amount of months allowed to scroll to the future. Default = 50

  7.  futureScrollRange={50}

  8.  // Enable or disable scrolling of calendar list

  9.  scrollEnabled={true}

  10.  ...calendarParams

  11. />

Agenda(日程)

示例代码
 
 
  1. <Agenda

  2.  // the list of items that have to be displayed in agenda. If you want to render item as empty date

  3.  // the value of date key kas to be an empty array []. If there exists no value for date key it is

  4.  // considered that the date in question is not yet loaded

  5.  items={

  6.    {'2012-05-22': [{text: 'item 1 - any js object'}],

  7.     '2012-05-23': [{text: 'item 2 - any js object'}],

  8.     '2012-05-24': [],

  9.     '2012-05-25': [{text: 'item 3 - any js object'},{text: 'any js object'}],

  10.    }}

  11.  // callback that gets called when items for a certain month should be loaded (month became visible)

  12.  loadItemsForMonth={(month) => {console.log('trigger items loading')}}

  13.  // callback that gets called on day press

  14.  onDayPress={(day)=>{console.log('day pressed')}}

  15.  // callback that gets called when day changes while scrolling agenda list

  16.  onDayChange={(day)=>{console.log('day changed')}}

  17.  // initially selected day

  18.  selected={'2012-05-16'}

  19.  // Minimum date that can be selected, dates before minDate will be grayed out. Default = undefined

  20.  minDate={'2012-05-10'}

  21.  // Maximum date that can be selected, dates after maxDate will be grayed out. Default = undefined

  22.  maxDate={'2012-05-30'}

  23.  // Max amount of months allowed to scroll to the past. Default = 50

  24.  pastScrollRange={50}

  25.  // Max amount of months allowed to scroll to the future. Default = 50

  26.  futureScrollRange={50}

  27.  // specify how each item should be rendered in agenda

  28.  renderItem={(item, firstItemInDay) => {return (<View />);}}

  29.  // specify how each date should be rendered. day can be undefined if the item is not first in that day.

  30.  renderDay={(day, item) => {return (<View />);}}

  31.  // specify how empty date content with no items should be rendered

  32.  renderEmptyDate={() => {return (<View />);}}

  33.  // specify how agenda knob should look like

  34.  renderKnob={() => {return (<View />);}}

  35.  // specify your item comparison function for increased performance

  36.  rowHasChanged={(r1, r2) => {return r1.text !== r2.text}}

  37.  // Hide knob button. Default = false

  38.  hideKnob={true}

  39.  // By default, agenda dates are marked if they have at least one item, but you can override this if needed

  40.  markedDates={{

  41.    '2012-05-16': {selected: true, marked: true},

  42.    '2012-05-17': {marked: true},

  43.    '2012-05-18': {disabled: true}

  44.  }}

  45.  // agenda theme

  46.  theme={{

  47.    ...calendarTheme,

  48.    agendaDayTextColor: 'yellow',

  49.    agendaDayNumColor: 'green',

  50.    agendaTodayColor: 'red',

  51.    agendaKnobColor: 'blue'

  52.  }}

  53.  // agenda container style

  54.  style={{}}

  55. />

说明

react-native-calendars组件的GitHub 地址:https://github.com/wix/react-native-calendars,更多的配置和使用方法请点击查看原文查看GitHub上的文档以及示例代码。

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
React Native中可以使用Image组件和ImageEditor组件实现页面组件的黑白滤镜效果。以下是实现步骤: 1. 导入Image和ImageEditor组件: ```javascript import { Image, ImageEditor } from 'react-native'; ``` 2. 在组件中使用Image组件来渲染需要添加黑白滤镜的组件,并添加样式: ```javascript <Image source={require('./assets/image.jpg')} style={styles.image} /> ``` 其中,require('./assets/image.jpg')指定了需要添加黑白滤镜的组件的路径,styles.image定义了Image组件的样式: ```javascript const styles = StyleSheet.create({ image: { width: 200, height: 200, }, }); ``` 3. 使用ImageEditor组件组件进行黑白滤镜处理: ```javascript ImageEditor.cropImage(uri, { offset: { x: 0, y: 0 }, size: { width: screenWidth, height: screenHeight }, displaySize: { width: screenWidth, height: screenHeight }, resizeMode: 'contain', }, (croppedImageURI) => { ImageEditor.processImage(croppedImageURI, { width: screenWidth, height: screenHeight, resizeMode: 'contain', colorMatrix: [ 0.33, 0.33, 0.33, 0, 0, 0.33, 0.33, 0.33, 0, 0, 0.33, 0.33, 0.33, 0, 0, 0, 0, 0, 1, 0 ], }, (processedImageURI) => { this.setState({ processedImageURI }); }, (error) => console.error(error)); }, (error) => console.error(error)); ``` 其中,uri参数指定了需要添加黑白滤镜的组件的路径,colorMatrix参数指定了黑白滤镜的矩阵。处理完成后,将处理后的图片设置为组件的state,并在render方法中使用Image组件来渲染处理后的图片: ```javascript render() { return ( <View style={styles.container}> <Image source={{ uri: this.state.processedImageURI }} style={styles.image} /> // 其他组件 </View> ); } ``` 注意,ImageEditor组件是异步执行的,因此需要使用回调函数来处理处理后的图片。详细使用方法可以查看React Native官方文档。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值