嗨,我刚开始使用react native,我正在尝试禁用周日和今天日期之前的所有日期,我正在使用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} />;
}}
/>发布于 2019-05-20 10:06:44
你能试试这个吗?
react-native-calendars有一个默认的事件集。但是,当值为disabled时,不指定值true和false。
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} />;
}
}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>https://stackoverflow.com/questions/56213273
复制相似问题