嗨,我是本机反应新手,我正在尝试禁用周日以及今天之前的所有日期,但我正在使用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} />;
}}
/>
````
答案 0 :(得分:1)
您可以尝试吗?
react-native-calendars
具有默认事件集。但是,当值为true
时,将不指定值false
和disabled
。
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>