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

infinite FlatList with inverted prop becomes crazy #1254

Closed
Sharcoux opened this issue Feb 21, 2019 · 15 comments
Closed

infinite FlatList with inverted prop becomes crazy #1254

Sharcoux opened this issue Feb 21, 2019 · 15 comments
Labels
bug: react-native Bug associated with upstream React Native vendor code project:react-native-web Issue associated with react-native-web

Comments

@Sharcoux
Copy link

Sharcoux commented Feb 21, 2019

The problem

When loading many items in a FlatList with the inverted prop, the list gets weird behaviours. The scroll moves on its own. It is also reverted whereas it shouldn't, and to top it all, some elements of the list gets inaccessible...

How to reproduce

Simplified test case

Steps to reproduce:

  1. just go to the top of the list to load more messages.
  2. repeat the process a few time, and things should start to become weird.

Expected behavior

If you remove the inverted prop, you get the expected behaviour. inverted should just make the items of the list to be displayed from bottom to top and onEndReached to be called when reaching the top.

Environment (include versions). Did this work in previous versions?

  • React Native for Web (version): 0.10.0
  • React (version): 16.5.1
  • Browser: Chrome 72.0.3626.109
@Sharcoux
Copy link
Author

Sharcoux commented Feb 23, 2019

  verticallyInverted: {
    transform: [{scaleY: -1}],
  },
  horizontallyInverted: {
    transform: [{scaleX: -1}],
  },

Ouch! I don't think that this is a great way to handle the inverted property!
Replacing flex-direction: column by flex-direction: column-reverse would probably do a much better job, no?

@necolas
Copy link
Owner

necolas commented Feb 23, 2019

FlatList is a copy of what's in React Native

@Sharcoux
Copy link
Author

Then how come it behave so differently in the browser?
Using this mirror trick is responsible for the scroll to go in the opposite way, which is very unnatural. Moreover, the onEndReach events firing become completely broken...

@Sharcoux
Copy link
Author

Ok, I think I can fix it. I'll make a PR.

@Sharcoux
Copy link
Author

Sharcoux commented Feb 25, 2019

This is the pending PR. I will try to fix this problem directly with RN team with this discussion.

@necolas
Copy link
Owner

necolas commented Mar 5, 2019

Linking the related issue @Sharcoux created for Yoga facebook/yoga#866

@sdcooke
Copy link

sdcooke commented Mar 6, 2019

I had this issue - some very confusing behaviour with an inverted FlatList on web only. For anyone looking for a workaround disableVirtualization={true} seems to stop the weird behaviour for me, although it's obviously not an ideal solution.

@ghost
Copy link

ghost commented Sep 17, 2019

@sdcooke disableVirtualization={true} works for me too. But it is deprecated and will not be on Expo either in the near future. What can we do next?

@azesmway
Copy link

I solved this problem as follows
#1579 (comment)

@marcaaron
Copy link

Experienced something similar to this. The weird scrolling issue seemed to go away after using the getItemLayout prop or having fixed heights on all items. Unfortunately, we are trying to get variable height items to work with FlatList (they work well enough on native, but on web behave erratically after a certain length). One workaround is to cache the length + offset of each renderItem just once via onLayout and then reference this value again later.

@necolas necolas added the bug: react-native Bug associated with upstream React Native vendor code label Feb 2, 2021
@jgo80
Copy link

jgo80 commented Dec 6, 2021

I actually found a pretty neat workaround making "inverted lists" work nicely with RNW - even in a shared code environment along with RN.

The solution is to achieve the inverted style in a different way with the very same effect.
I hope this helps some of you:

  const isWeb = Platform.OS === 'web';

  const listStyle: ViewStyle | undefined = isWeb
    ? { flexDirection: 'column-reverse' }
    : undefined;

  const contentContainerStyle: ViewStyle | undefined = isWeb
    ? { flexDirection: 'column-reverse' }
    : undefined;

        <SectionList
          {...otherListProps}
          inverted={!isWeb} // <-- do not invert to prevent transform: [{scaleY: -1}]
          contentContainerStyle={contentContainerStyle} // <-- 'column-reverse' to make it scroll to the bottom
          style={listStyle} // <-- 'column-reverse' to reverse you list array
        />

@CoinCoderBuffalo
Copy link

CoinCoderBuffalo commented Jan 11, 2022

@mrsimply onEndReached is not called with this approach.

I ended doing this for now:

<SectionList
  ...
  disableVirtualization={Platform.OS == "web"}
/>

@LucioChavezFuentes
Copy link
Contributor

Hey guys! I found the problems that cause this issue and also made PRs to fix them. Check them out and let me know what you think.

@willbach
Copy link

I encountered this issue in an Expo app. When I inspected the element(s) I saw that the list had 2 nested div elements with the same classes applied (i.e. <div classes> <div classes> {children} </div> </div>), so the individual list elements were being transformed (inverted) once but the list itself was being transformed twice and so still displayed top-to-bottom. I fixed by wrapping the list in a RN View with transform: [{ scaleY: -1 }]. Very hacky but it's working nicely.

@necolas
Copy link
Owner

necolas commented Mar 27, 2023

Closing this old issue because VirtualizedList/FlatList will be developed exclusively out of the RN monorepo in the future. An open PR will be the last list-related change to be made to RNW, and should fix this. There may still be an issue in other code that's part of RNW, so feel free to create a new issue with latest info if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug: react-native Bug associated with upstream React Native vendor code project:react-native-web Issue associated with react-native-web
Projects
None yet
Development

No branches or pull requests

9 participants