不变违规:Snap Carousel上的本机驱动事件不支持侦听器

时间:2018-03-21 06:27:29

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

我一直在尝试使用我的应用程序实现Snap Carousel。但它会发出以下警告,但不会加载。

  

错误:本机驱动事件不支持侦听器。       在不变量(invariant.js:38)       在新的AnimatedEvent(AnimatedImplementation.js:2126)       at Object.event(AnimatedImplementation.js:2230)       在新的Carousel(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 react-native-snap-carousel:3.6.0

目标平台: iOS(11.2)

对此有何解决方法?谢谢。

1 个答案:

答案 0 :(得分:0)

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