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

FlashList errs when rotating the device with dynamic numColumns and ListEmptyComponent #1032

Open
2 tasks done
JulienFremyMP opened this issue Jan 19, 2024 · 6 comments
Open
2 tasks done
Labels
bug Something isn't working

Comments

@JulienFremyMP
Copy link

Current behavior

I have the following code:

import { Text, useWindowDimensions } from 'react-native';

import { FlashList } from '@shopify/flash-list';

function App(): JSX.Element {
    const { width } = useWindowDimensions();
    const columnsCount = width / 100;

    const EmptyState = () => {
        return <Text>Wow such empty!</Text>;
    };

    return (
        <FlashList
            data={[]}
            renderItem={(_) => {
                return <></>;
            }}
            numColumns={Math.floor(columnsCount)}
            estimatedItemSize={200}
            ListEmptyComponent={EmptyState}
        />
    );
}

export default App;

I run it on an android real tablet device, specifically a Galaxy Tab S5e (SM-T720)

I rotate the device.

There is an error displayed when I do it:

 ERROR  TypeError: Cannot read property 'y' of undefined

This error is located at:
    in ProgressiveListView (created by StickyContainer)
    in RCTView (created by View)
    in View (created by StickyContainer)
    in StickyContainer (created by FlashList)
    in FlashList (created by App)
    in App
    in RCTView (created by View)
    in View (created by AppContainer)
    in RCTView (created by View)
    in View (created by AppContainer)
    in AppContainer
    in example(RootComponent), js engine: hermes
 ERROR  TypeError: Cannot read property 'y' of undefined

This error is located at:
    in ProgressiveListView (created by StickyContainer)
    in RCTView (created by View)
    in View (created by StickyContainer)
    in StickyContainer (created by FlashList)
    in FlashList (created by App)
    in App
    in RCTView (created by View)
    in View (created by AppContainer)
    in RCTView (created by View)
    in View (created by AppContainer)
    in AppContainer
    in example(RootComponent), js engine: hermes

Screenshot_20240119-155247_example

I would expect to have the view properly rotated instead.

To Reproduce

Use react-native to initialize an empty project, add flashlist to it, and replace the default App code by the one I posted above.

Platform:

  • iOS
  • Android

It also occurs on iPad (be sure to display the app in the whole screen, https://stackoverflow.com/questions/74907554/ipad-pro-not-showing-full-screen-content-in-react-native-xcode-14-0-1)

IMG_CBFA800B9235-1

Environment

I'm on @shopify/flash-list": "^1.6.3"

@JulienFremyMP JulienFremyMP added the bug Something isn't working label Jan 19, 2024
@JulienFremyMP JulienFremyMP changed the title FlashList errs when rotating the device with numColumns and ListEmptyComponent FlashList errs when rotating the device with dynamic numColumns and ListEmptyComponent Jan 19, 2024
@JulienFremyMP
Copy link
Author

This only happens when I use a numColumns parameter that depends on the width of the device and a ListEmptyComponent, to help you narrow the bug's origin.

And thanks for this project by the way!

@nguyenductoan1995
Copy link

i got same issue pls help me way for resolve it

@jkinggg
Copy link

jkinggg commented Apr 25, 2024

Same issue here

@ldalzottomp
Copy link

I don't reproduce anymore with FlashList 1.6.3 and react-native 0.73.6

@asleepace
Copy link

I was able to fix the issue by changing the FlashList key when the list is empty and the number of columns changes. Note that this will completely destroy the list and re-create a new one.

// change the key when the list is empty & numCols changes
const listKey = data?.length === 0 ? `empty-list-${numCols}-cols` : "normal-list"

// be sure to include key={listKey} when rendering
return (
   <FlashList
      key={listKey}
      ListEmptyComponent={
        <MyEmptyComponent />
      }
      numCols={numCols}
      data={data}
   />
)

It's a bit hacky, but it works 🤷‍♂

@Abdulazeez-98
Copy link

When using <FlatList> with dynamic numColumns I get the error:

Changing numColumns on the fly is not supported. Change the key prop on FlatList when changing the number of columns to force a fresh render of the component.

However, this error doesn't occur in FlashList.

Regarding FlashList, I get the same error of "Cannot read property 'y' of undefined" when the list is empty and numColumns is changed (e.g. the devices is rotated while still fetching the data).
The problem was solved by the solution suggested by @asleepace .

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

6 participants