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

MasonryFlashList doesn't always add new columns when data is added #927

Open
3 tasks done
laurence79 opened this issue Sep 29, 2023 · 7 comments
Open
3 tasks done
Labels
bug Something isn't working

Comments

@laurence79
Copy link

laurence79 commented Sep 29, 2023

Current behavior

MasonryFlashList.issue.mov

If numColumns={3} and MasonryFlatList is initially rendered with one item, when you add further items the additional necessary columns are not rendered. This is on all platforms

On iOS and Android, this happens if you start with 0 or 1 item, and use 2, 3, 5, or 6 as numColumns (4 works)

Expected behavior

Columns will be added for the new items.

To Reproduce

Reproduction: https://snack.expo.dev/@mrhartgill/masonry-layout-2nd-item-issue.

Platform:

  • iOS
  • Android
  • Web

Environment

This snack uses v1.4.0 because of the Expo SDK limitation, but I've reproduced the same thing with v1.6.1 locally.

@laurence79 laurence79 added the bug Something isn't working label Sep 29, 2023
@laurence79
Copy link
Author

Related #876, #627

@tanlucvo
Copy link

tanlucvo commented Oct 3, 2023

I have solution but I dont think it is the best solution, just change numColumns to double and each column flex is 2, have the same result

numColumns={6}
getColumnFlex={(items, index, maxColumns, extraData) => {
  return 2;
}}

@alex-trofimov
Copy link

Also experiencing this issue with MasonryFlashList on 1.6.3

@juanch0x
Copy link

juanch0x commented Jan 16, 2024

I know that's not a good solution, but it end up working for my just adding a key and force a rerender when the origin length changes

<MasonryFlashList
      showsVerticalScrollIndicator={false}
      data={deals}
      key={deals.length}
      keyExtractor={(item) => `${item.business_id}__${item.id}`}
      renderScrollComponent={ScrollView}
....../>

@anhChillLe
Copy link

I don't think changing key is good for rendering

  const key = `note-list-${notes.length >= numColumns}`

  return (
    <AnimatedMasonryNoteList
      key={key}
      data={notes}
      renderItem={renderItem}
      keyExtractor={keyExtractor}
      extraData={extraData}
      removeClippedSubviews
      numColumns={numColumns}
      contentContainerStyle={styles.list_content}
      estimatedItemSize={200}
      {...props}
    />
  )

Or you can add a null item to data if data.length < column and check null in render item

  const data = useMemo(() => {
    if (notes.length >= numColumns) {
      return notes
    } else {
      return [...notes, null]
    }
  }, [notes, numColumns])

  return (
    <AnimatedMasonryNoteList
      data={data as Note[]}
      renderItem={renderItem}
      keyExtractor={keyExtractor}
      extraData={extraData}
      removeClippedSubviews
      numColumns={numColumns}
      contentContainerStyle={styles.list_content}
      estimatedItemSize={200}
      {...props}
    />
  )
  const renderItem: MasonryListRenderItem<Note> = ({ item, columnIndex }) => {
    if (item === null) {
      return null
    }

@jerryphm
Copy link

facing same issue here, any update? in my case, numColumn=2 and going from 1 item to 2 items does not render the second one

@CrazyStoneJy
Copy link

facing same issue here, any update? in my case, numColumn=2 and going from 1 item to 2 items does not render the second one

same bug on 1.7.0

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

7 participants