当放入 ScrollView React Native 中时,react-native-snap-carousel 在 Android 中不会滚动

问题描述 投票:0回答:1

我想在水平滚动的卡片内渲染react-native-snap-carousel,我正在使用ScrollView(horizontal),但是react-native-snap-carousel的“Carousel”不仅仅在android中滚动。 请在您的 Android 手机中运行此博览会小吃来重现问题 https://snack.expo.io/@sagar293/flatlist-inside-scrollview

import React from 'react';
import { StyleSheet, Text, View, Dimensions, SafeAreaView, TouchableHighlight, ScrollView, 
TouchableOpacity, TouchableWithoutFeedback, Image, Linking, Platform } from 'react-native';
import Carousel, { Pagination } from 'react-native-snap-carousel';
import { Input, Button, Divider, Card, Overlay } from 'react-native-elements';

export default class Cart extends React.Component {
  state = {
    data: [
        { title: 'a', url: require("./Light-Hover34x34.png") },
        { title: 'b', url: require("./Light-Hover34x34.png") },
        { title: 'c', url: require("./Light-Hover34x34.png") },
        { title: 'd', url: require("./Light-Hover34x34.png") },
        { title: 'e', url: require("./Light-Hover34x34.png") },
    ],
    activeSlide: 0,
    room: ["one", "two", "three"]
}

_renderItem = ({ item, index }) => {
    console.log("active slide", this.state.activeSlide)
    const isActive = index === this.state.activeSlide;

    return (
    <TouchableHighlight
        // onPress={() => Linking.openURL(item.url)}
        style={{
        backgroundColor: isActive ? '#FFD845' : null,
        width: 60,
        height: 60,
        borderRadius: 60/2,
        justifyContent: 'center',
        alignItems: 'center',
        }}>
        <Image
            source={item.url}
            style={{ width: '50%', height: '40%' }}
        />
    </TouchableHighlight>
    );
 };

render() {
    return (
        <View style={{alignItems: 'center', justifyContent: 'center', paddingVertical: 100}}>
          <ScrollView horizontal={true}>
            {
              this.state.room.map((r, i) => {
                return(
                  <View key={i}>
                    <TouchableWithoutFeedback>
                      <Card containerStyle={[styles.cardEleBig,]}>
                          <SafeAreaView style={{ height: 150 }}>
                              <Carousel
                                  data={this.state.data}
                                  renderItem={this._renderItem}
                                  sliderWidth={120}
                                  itemWidth={50}
                                  onSnapToItem={index => this.setState({ activeSlide: index })} //for pagination
                              />
                          </SafeAreaView>
                        </Card>
                    </TouchableWithoutFeedback>
                  </View>
                )
              })
            }
          </ScrollView>
        </View>
    );
  }
}

const styles = StyleSheet.create({
  cardCircleParking: {
    backgroundColor: "yellow",
    // marginBottom: 10,
    // marginLeft: '5%',
    width: 50,
    height: 50,
    borderRadius: 50/2,
    borderColor: 'white',
},
cardEleBig: {
  borderRadius: 20,
  borderBottomWidth: 0,
  borderColor: 'white',
  width: 159,
  height: Platform == "ios" ? 210 : 200,
  shadowColor: "#000",
  shadowOffset: {
      width: 0,
      height: 2,
  },
  shadowOpacity: 0.25,
  shadowRadius: 3.84,
  elevation: 5,
  marginLeft: 5,
  marginRight: 5,
  marginTop: 10,
  marginBottom: 2
},
})
react-native react-native-flatlist react-native-scrollview react-native-snap-carousel
1个回答
0
投票

Carousel本身就是一个scrollView,所以可以尝试设置overScrollMode='auto'

© www.soinside.com 2019 - 2024. All rights reserved.