0

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: screenshot for ScrollView

TylerH
  • 20,799
  • 66
  • 75
  • 101
Recursive
  • 211
  • 3
  • 10
  • Have you tried setting `flexGrow: 1` on the ScrollView style prop (not contentContainerStyle)? – Abe Jun 01 '22 at 00:21
  • I tried using flexGrow: 1 and did not solve it. I just added an updated one and still same issue – Recursive Jun 01 '22 at 00:27

1 Answers1

1

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%",
  },
2xSamurai
  • 1,221
  • 12
  • 18
  • Woooow, I'm stunned! That actually fixed my issue. Is there a reason why it does not work with width: '100%', or that is actually incorrect to do? – Recursive Jun 01 '22 at 05:18
  • 1
    @Jerry310 I'm guessing "contentContainerStyle" is the container that holds all the items. Its width should be something like - no of items*width of each item. When there are more items to enable scrolling. This width would be more than the screen width(100%). So when you set it to 100% nothing is going to happen. Hope you get what I mean. – 2xSamurai Jun 01 '22 at 05:23
  • Thank you so much! Oh that makes so much sense, thanks a lot for your help! I'm actually impressed because I sadly spent 3-4 hours trying to figure why is not scrolling lol Thanks a lot again! – Recursive Jun 01 '22 at 05:46
  • @Jerry310 You are welcome. Sometimes we end up spending a lot of time on simple problems. I too have been there and done that. That's how we learn and move forward. So don't worry about it. – 2xSamurai Jun 01 '22 at 05:54