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

2
  • Have you tried setting flexGrow: 1 on the ScrollView style prop (not contentContainerStyle)? Commented Jun 1, 2022 at 0:21
  • I tried using flexGrow: 1 and did not solve it. I just added an updated one and still same issue Commented Jun 1, 2022 at 0:27

2 Answers 2

2

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%",
  },
Sign up to request clarification or add additional context in comments.

4 Comments

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?
@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.
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!
@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.
0

For me ScrollView was not working because it was for some reasons wrapped by <TouchableWithoutFeedback></TouchableWithoutFeedback> tags.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.