在星期天响应本机日历禁用触摸事件

时间:2019-05-20 01:07:56

标签: react-native calendar expo

嗨,我是本机反应新手,我正在尝试禁用周日以及今天之前的所有日期,但我正在使用react-native-calendars,我设法禁用了所有周日,但是触摸事件仍然有效 有什么帮助吗?

here's the code to disable sundays
import React, {Component} from 'react';
import { isSunday } from "date-fns";
import Day from "react-native-calendars/src/calendar/day/basic";

export class CustomDay extends Component {
  render() {
    const { date, marking } = this.props;
    marking.disabled = isSunday(date.timestamp);
    return <Day {...this.props} />;
  }
}
<Calendar
  dayComponent={props => {
    return <CustomDay {...props} />;
  }}
/>
````

1 个答案:

答案 0 :(得分:1)

您可以尝试吗?

react-native-calendars具有默认事件集。但是,当值为true时,将不指定值falsedisabled

import React, {Component} from 'react';
import { isSunday } from "date-fns";
import Day from "react-native-calendars/src/calendar/day/basic";

export class CustomDay extends Component {
  render() {
    const { date, marking } = this.props;
    marking.disabled = isSunday(date.timestamp);
     marking.disableTouchEvent = marking.disabled === true ? true : false
    return <Day {...this.props} />;
  }
}

reference link

Day的定义

 <TouchableOpacity
        testID={this.props.testID}
        style={containerStyle}
        onPress={this.onDayPress}
        onLongPress={this.onDayLongPress}
        activeOpacity={marking.activeOpacity}
        disabled={marking.disableTouchEvent}
      >
        <Text allowFontScaling={false} style={textStyle}>{String(this.props.children)}</Text>
        {dot}
      </TouchableOpacity>