微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

react-native – undefined不是和object(评估’_props [registrationName]’)

反应天然: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>

原文地址:https://www.jb51.cc/react/300781.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐