0

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

错误:本机驱动的事件不支持侦听器。在 invariant (invariant.js:38) at new AnimatedEvent (AnimatedImplementation.js:2126) at Object.event (AnimatedImplementation.js:2230) at new Carousel (Carousel.js:147) at 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>
            )
}

环境:React:15.3.1 React Native:0.37.0 react-native-snap-carousel:3.6.0

目标平台:iOS (11.2)

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

4

1 回答 1

0

为了修复错误,我分叉了react-native-snap-carouselnpm 模块。在里面/src/carousel/Carousel.js,我已将useNativeDriverscrollEventConfig 中的参数更改为 false。

于 2018-04-10T03:02:09.000 回答