如何控制在 react-native 中单击轮播按钮时的交换?

How to control swapping on click of button in carousel in react-native?

当我单击按钮时,我想控制轮播的交换幻灯片。这意味着如果我单击按钮,则新幻灯片将出现在轮播中。

我正在使用 'react-native-snap-carousel' 包来实现我在 react 中的功能-native.so 请帮助我如何实现这个 functionality.Thank 你提前。

     SwapSlide = (value) => {
                    this.setState({ indexvalue: value }, () => {
                        console.log("get swapindex ===>>>", this.state.indexvalue)
                    })
                }
onPressAnswer = (item) => {
        console.log("run increase method===>>>", this.increase('progress', 10));
        console.log("run swapslide method===>>>", this.SwapSlide.snapToNext());
        this.AddQuestionAnswer(item)
    }

 renderItemAnswer = ({ item, index }) => {

        return (
            <View>
                <TouchableOpacity style={styles.answerTouchable} onPress={() =>this.onPressAnswer(item)}>
                    <Text style={styles.answerText}>{item.answer}</Text>
                </TouchableOpacity>
            </View>
        )
    }

         <Carousel
                                data={questionList}
                                renderItem={this.renderItemQuestion}
                                hasParallaxImages={true}
                                itemWidth={wp('100%')}
                                sliderWidth={wp('100%')}
                                ref={(value)=>{this.SwapSlide=value}}    
                            />



        <TouchableOpacity onPress={() => { this.setState({ indexvalue: indexvalue + 1 }) }}><Text style={styles.skiptext}>Skip</Text></TouchableOpacity>

为下一张幻灯片使用方法 snapToNext()

<TouchableOpacity onPress={() => this.SwapSlide.snapToNext()}><Text style={styles.skiptext}>Skip</Text></TouchableOpacity>

对于上一张幻灯片,您可以使用 this.SwapSlide.snapToPrev()