Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not rendering items when horizontal #757

Closed
gabrielbarbosanascimento opened this issue Feb 7, 2023 · 5 comments
Closed

Not rendering items when horizontal #757

gabrielbarbosanascimento opened this issue Feb 7, 2023 · 5 comments
Labels
bug Something isn't working

Comments

@gabrielbarbosanascimento
Copy link

gabrielbarbosanascimento commented Feb 7, 2023

Current behavior

I'm implementing a horizontal ruler, so the user can set they height. But the initial render is empty (of the ruler steps). If I scroll slow, it stills, but when I scroll fast, they finally appear

<FlashList
          ref={ref}
          horizontal
          estimatedItemSize={STEP_SIZE}
          estimatedListSize={{ height: STEP_SIZE * 2, width: WIDTH }}
          bounces={false}
          keyExtractor={(item) => `${item}`}
          removeClippedSubviews={true}
          contentContainerStyle={{
            paddingLeft: WIDTH / 2 - 10,
            paddingRight: WIDTH / 2
          }}
          showsHorizontalScrollIndicator={false}
          data={values}
          onScroll={(e) => {
            onScroll(e.nativeEvent.contentOffset.x);
          }}
          onMomentumScrollEnd={(e) =>
            scrollToNearbyPosition(e.nativeEvent.contentOffset.x)
          }
          renderItem={({ index }) => (
            <View style={styles.step_container}>
              <View style={index % 5 === 0 ? styles.step : styles.step_small} />
            </View>
          )}
        />

Expected behavior

This doesn't happen when its vertically. I double checked the sizes (they are all fixed values)

To Reproduce

I recorded a video of this behavior

Screen_Recording_20230207_170855_Expo.Go_1.mp4

Environment

"@shopify/flash-list": "1.3.1"
"expo": "~47.0.7",

@gabrielbarbosanascimento gabrielbarbosanascimento added the bug Something isn't working label Feb 7, 2023
@frankbaele
Copy link

frankbaele commented Feb 20, 2023

I had a similar issue with the horizontal mode of flashlist. Figured out that the initial length of my array was 0. This was my quick fix-> only render the flashlist if there are items. Hope this helps you out.

  if (values.length == 0) {
    return (
      <View>
        <Text>{'test'}</Text>
      </View>
    );
  }
  return <FlashList data={values} horizontal={true} />;

@gabrielbarbosanascimento
Copy link
Author

@frankbaele I just tested it, your workaround is working like a charm. Thank you!

@mduc-dev
Copy link

I had a similar issue with the horizontal mode of flashlist. Figured out that the initial length of my array was 0. This was my quick fix-> only render the flashlist if there are items. Hope this helps you out.

  if (values.length == 0) {
    return (
      <View>
        <Text>{'test'}</Text>
      </View>
    );
  }
  return <FlashList data={values} horizontal={true} />;

i have same issue here and i try it, but don't work for me

@mduc-dev
Copy link

Does anyone have another solution?

@fortmarek
Copy link
Contributor

Hey,

This is a specific variant of this issue where the initial height is 0 and then non-zero. I will close this a duplicate, for now, we recommend using the suggested workaround.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants