【问题标题】:Invariant Violation: Listener is not supported for native driven events on Snap Carousel不变违规:Snap Carousel 上的本机驱动事件不支持侦听器
【发布时间】:2018-03-21 06:27:28
【问题描述】:

我一直在尝试使用我的应用实现 Snap Carousel。但它会给出以下警告并且不会加载。

错误:本机驱动的事件不支持侦听器。 在不变(invariant.js:38) 在新的 AnimatedEvent (AnimatedImplementation.js:2126) 在 Object.event (AnimatedImplementation.js:2230) 在新的轮播 (Carousel.js:147) 在 ReactCompositeComponentWrapper._constructComponentWithoutOwner (ReactCompositeComponent.js:296) 在 ReactCompositeComponentWrapper._constructComponent (ReactCompositeComponent.js:278) 在 ReactCompositeComponentWrapper.mountComponent (ReactCompositeComponent.js:190) 在 Object.mountComponent (ReactReconciler.js:47) 在 Constructor.mountChildren (ReactMultiChild.js:240) 在 Constructor.initializeChildren (ReactNativeBaseComponent.js:69)

有轮播的类如下。

'use strict';

const styles = require('./Styles');
import React, {Component} from 'react';
import {
    View
} from 'react-native';

import Carousel from 'react-native-snap-carousel';

export default class CarouselCard extends Component {

    static renderItem({item, index}) {
        console.log(item);
        return item;
    }

    render() {
        return (
            <View key={this.props.cardKey}
                  style={[styles.cardContainer, {padding: 0, borderWidth: 0, marginRight: -10, marginLeft: -10}]}>
                <Carousel
                    ref={(c) => {
                        this._carousel = c;
                    }}
                    data={this.props.cardsList}
                    renderItem={CampaignCard.renderItem}
                    sliderWidth={this.props.sliderWidth}
                    itemWidth={this.props.itemWidth}
                    useScrollView={true}
                />
            </View>)
    }
}

这个组件在父类中如下使用。

renderCarouselCards() {
        let topCardsList = [];

        for(let x = 0; x < this.state.campaigns.length; x++) {
            topCardsList.push(
                <CarouselCard
                    key={x}
                    cardKey={x}
                    cardsList={this.getTopCards(this.state.data[x])}
                    sliderWidth={Dimensions.get('window').width}
                    itemWidth={Dimensions.get('window').width - 20}
                />
            )
        }

        return topCardsList;
    }

//

render() {
return (
                <ScrollView
                    contentInset={{top: 0}}
                    automaticallyAdjustContentInsets={false}
                    contentContainerStyle={styles.contentContainer}>
                    {this.renderCarouselCards()}
                </ScrollView>
            )
}

环境: 反应:15.3.1 反应原生:0.37.0 反应原生快照轮播:3.6.0

目标平台: iOS (11.2)

有什么解决方法吗?谢谢。

【问题讨论】:

  • 现在有同样的问题,使用 RN 0.39。该版本可能比框架测试的版本旧。

标签: javascript reactjs react-native react-native-snap-carousel


【解决方案1】:

为了修复错误,我分叉了react-native-snap-carousel npm 模块。在/src/carousel/Carousel.js 内部,我将scrollEventConfig 中的useNativeDriver 参数更改为false。

【讨论】:

    猜你喜欢
    • 2019-11-08
    • 2022-08-08
    • 1970-01-01
    • 2018-05-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多