简体   繁体   中英

React native ScrollView is not scrolling

I tried using Flatlist and it did not work either. On FlatList it will not display the images, so I was not able to test it. On ScrollView it is displaying, but it does not scroll. Here is the code that I have, please help:

import { ScrollView, StyleSheet, View, Image } from "react-native";
import React from "react";

const StylistFeatures = ({ businessFeatures }) => {
  const { wifi, walkIn, appointments, toHome, celebrityStylist, covidMask } =
    businessFeatures;
  return (
    <View
      style={{
        alignSelf: "center",
        flexDirection: "row",
        width: "100%",
        height: "14%",
      }}
    >
      <ScrollView
        horizontal
        scrollEnabled
        showsHorizontalScrollIndicator={false}
        contentContainerStyle={styles.contentContainerFlatListStyle}
        style={{ flexGrow: 1, padding: 10 }}
      >
        <View style={styles.imageContainerStyle}>
          {wifi ? (
            <Image
              source={require("../assets/images/design-icon/wifi.png")}
              style={styles.imageStyle}
            />
          ) : null}
        </View>
        <View style={styles.imageContainerStyle}>
          {walkIn ? (
            <Image
              source={require("../assets/images/design-icon/walk.png")}
              style={styles.imageStyle}
            />
          ) : null}
        </View>
        <View style={styles.imageContainerStyle}>
          {appointments ? (
            <Image
              source={require("../assets/images/design-icon/calendar.png")}
              style={styles.imageStyle}
            />
          ) : null}
        </View>
        <View style={styles.imageContainerStyle}>
          {toHome ? (
            <Image
              source={require("../assets/images/design-icon/car.png")}
              style={styles.imageStyle}
            />
          ) : null}
        </View>
        <View style={styles.imageContainerStyle}>
          {celebrityStylist ? (
            <Image
              source={require("../assets/images/design-icon/celebrity.png")}
              style={styles.imageStyle}
            />
          ) : null}
        </View>
        <View style={styles.imageContainerStyle}>
          {covidMask ? (
            <Image
              source={require("../assets/images/design-icon/safety-mask.png")}
              style={styles.imageStyle}
            />
          ) : (
            <Image
              source={require("../assets/images/design-icon/no-mask.png")}
              style={styles.imageStyle}
            />
          )}
        </View>
      </ScrollView>
    </View>
  );
};

export default StylistFeatures;

const styles = StyleSheet.create({
  contentContainerFlatListStyle: {
    width: "100%",
    alignItems: "center",
    height: "100%",
  },
  imageStyle: {
    width: 40,
    height: 40,
    margin: 5,
  },
  imageContainerStyle: {
    marginRight: 12,
    borderColor: "black",
    borderWidth: 1,
    borderRadius: 10,
  },
});

Please help me, is there a reason why? Is it something bad creating the no scroll?

Here is a screenshot: 滚动视图的屏幕截图

Try removing the "contentContainerFlatListStyle" width property and try again. Like below. It should work. Let me know how it goes.

contentContainerFlatListStyle: {
    alignItems: "center",
    height: "100%",
  },

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM