首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >react本机日历在周日禁用触摸事件

react本机日历在周日禁用触摸事件
EN

Stack Overflow用户
提问于 2019-05-20 09:07:56
回答 1查看 3K关注 0票数 2

嗨,我刚开始使用react native,我正在尝试禁用周日和今天日期之前的所有日期,我正在使用react-native-calendars,我设法禁用了所有周日,但触摸事件仍然有效,有什么帮助吗?

代码语言:javascript
复制
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} />;
  }
}
代码语言:javascript
复制
<Calendar
  dayComponent={props => {
    return <CustomDay {...props} />;
  }}
/>
代码语言:javascript
复制
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-05-20 10:06:44

你能试试这个吗?

react-native-calendars有一个默认的事件集。但是,当值为disabled时,不指定值truefalse

代码语言:javascript
复制
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的定义

代码语言:javascript
复制
 <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>
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56213273

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档