加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

react-native – undefined不是和object(评估’_props [registra

发布时间:2020-12-15 20:43:27 所属栏目:百科 来源:网络整理
导读:反应天然:0.43.3 问题只出现在Android系统中,iOS很好. 当我触摸TouchableOpacity组件时,将不会执行onTouch功能. 有人发现这个问题吗? 我用RN建了一个日历.问题是,当我点击Android设备或模拟器上的Day单元时,我将得到错误undefined不是和object(评估’_prop
反应天然:0.43.3

问题只出现在Android系统中,iOS很好.
当我触摸TouchableOpacity组件时,将不会执行onTouch功能.

有人发现这个问题吗?

我用RN建了一个日历.问题是,当我点击Android设备或模拟器上的Day单元时,我将得到错误undefined不是和object(评估’_props [registrationName]’).但是可以在iOS设备和模拟器上单击它. Day组件的代码如下:

<TouchableOpacity style={styles.calendarRowUnit} onPress={() => this.props.onSelect(this.props.date)}>
            <View style={dateWrapperStyle}>
                <Text style={dateTextStyle}>{dateString}</Text>
            </View>
        </TouchableOpacity>

和错误图像:
error info iamge

我发现只有当我触摸文本区域时才会出现错误.
我不知道这是一个反应原生的错误或我的错.在将react-native版本更新为0.43.3之前,错误从未发生过.

/**
   * @param {object} inst The instance,which is the source of events.
   * @param {string} registrationName Name of listener (e.g. `onClick`).
   * @return {?function} The stored callback.
   */
  getListener: function(inst,registrationName) {
    var listener;

    // TODO: shouldPreventMouseEvent is DOM-specific and definitely should not
    // live here; needs to be moved to a better place soon
    if (typeof inst.tag === 'number') {
      const props = EventPluginUtils.getFiberCurrentPropsFromNode(
        inst.stateNode
      );
      if (!props) {
        // Work in progress.
        return null;
      }
      listener = props[registrationName];
      if (shouldPreventMouseEvent(registrationName,inst.type,props)) {
        return null;
      }
    } else {
      if (typeof inst._currentElement === 'string') {
        // Text node,let it bubble through.
        return null;
      }
      if (!inst._rootNodeID) {
        // If the instance is already unmounted,we have no listeners.
        return null;
      }
      const props = inst._currentElement.props;
      listener = props[registrationName];
      if (shouldPreventMouseEvent(registrationName,inst._currentElement.type,props)) {
        return null;
      }
    }

    invariant(
      !listener || typeof listener === 'function','Expected %s listener to be a function,instead got type %s',registrationName,typeof listener
    );
    return listener;
  },

目前存在一个错误,如果TouchableOpacity中的文本有一个数字,它将会出错.目前修复它的方法是将数字转换为字符串,它将触发String检查并适当地抛出null.

EX:

之前:<文字> 16< / Text>之后:< Text> String(16)< / Text>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读