-
Notifications
You must be signed in to change notification settings - Fork 24.4k
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
"VirtualizedLists should never be nested inside plain ScrollViews with the same orientation" error in console for FlatList/SectionList with scrollEnabled={false} #31697
Comments
Have you fixed it? I got it too. Everything worked well, but it shows errors in the console. |
I built a wrapper component to un-virtualize the list when scrollEnabled={false} to get around this, eg:
And for SectionList:
(this is TypeScript - I'm not sure about the separators implementation but this seems to circumvent the issue) I'd still rather have the framework take care of this for me. |
@beingArkReal raised issue tagged under question #28080, @CostachescuCristinel #27945 both issue are closed by the bot without any solution???? There is a question in StackOverflow all of these not giving any clarity about this Error. My case is
How to handle this case? |
@KarthikeyanM28 I have read a number of posts on the web, and kind of found some explanation for this warning. I am typing from what I can remember. I think I have found at some point someone pointing to the native source code of the scrollable component behind the ScrollView and FlatList components and explaining what happens, but I cannot find that post right now... Before I start, I haven't found an official RN team answer as to why this warning and what the actual reason is for it. Anyway, the story was something like this: The difficulty of the scrollable component when nesting multiple instances in sub-branches is that the instances will fight each other as to which one is eligible for stealing the touch events. Usually, this is resolved according to the event bubbling phase order (which flows bottom-up, child-to-parent), but the Due to this flaw in the scrollable component, many issues arise:
There are also many component layout and sizing issues due to this. The nature of the scrollable components is to render dynamically sized content. This makes layout calculations hard for RN since it has to continuously bounce between parents and childs to calculate the layouts, until all resolved dimensions will stabilize. The issue is somewhat non-conflicting when limiting nested scrollables to 2 instances and using different scrollable directions. Scrollables have a gesture distance activation threshold (if I remember correctly, there must be a delta of +/-10dp) in the direction observed before the scrollable will deem itself eligible for stealing the touch events. Since the horizontal and vertical directions look for deltas on different axes, they do not interfere with each other that much. As far as I could conclude from my findings on the web, the React Native team solution was... well, this warning. It is worth mentioning however that nesting scrollables with a different orientation is a supported use case, as also confirmed by the So, if you're wondering about possible solutions:
class AutoDisableScrollable extends React.PureComponent {
state = { container: 0, content: 0 };
onLayout = (layoutEvent) => {
const { nativeEvent: { layout: { width, height } } } = layoutEvent;
this.setSize("container", width, height, () => {
if (typeof (this.props.onLayout) === "function") {
this.props.onLayout(layoutEvent);
}
});
}
onContentSizeChange = (width, height) => {
this.setSize("content", width, height, () => {
if (typeof (this.props.onLayout) === "function") {
this.props.onContentSizeChange(width, height);
}
});
}
setSize = (ofItem, width, height, callback) => {
const currentSize = this.state[ofItem];
const newSize = (this.props.horizontal !== true) ? height : width;
if (newSize !== currentSize) {
this.setState({ [ofItem]: newSize }, callback);
} else {
callback();
}
}
render = () => {
const {
__ref, // Use this instead of the "ref" prop
ScrollableComponent, // ScrollView, FlatList, SectionList, VirtualizedList
scrollEnabled, bounces, onLayout, onContentSizeChange, children, ...props
} = this.props;
const { container, content } = this.state;
const __scrollEnabled = ((scrollEnabled !== false) && (content > container));
const __bounces = ((bounces !== false) && (__scrollEnabled === true));
return <ScrollableComponent
ref={__ref}
scrollEnabled={__scrollEnabled}
bounces={__bounces}
onLayout={this.onLayout}
onContentSizeChange={this.onContentSizeChange}
{...props}
>
{children}
</ScrollableComponent>;
}
} <AutoDisableScrollable
ScrollableComponent={ScrollView}
style={{ flex: 1 }}
...
>
...
</AutoDisableScrollable> I hope that this wall of text helps you and others to get scrollables working correctly. I do have ideas for a custom scrollable component that uses |
I am receiving the same error |
1 same issue |
same issue for me |
Hello, I have the same error, and the proposed solutions do not suit me very well... |
any solution this error occurs only after 0.61 to 0.64 upgrade till it was fine now I cant change to each and every pages |
I personnaly changed
|
I have found a solution for this. You can wrap your Component inside a frame and pass it to renderItem in your FlatList. Then you can use as many FlatList inside FlatList but eliminate the use of ScrollView , if you don't wnat to see this warning again. |
Can you give us the sample code? |
Same error here, using a scrollview as parent view, and nesting a SelectBox from react-native-multi-selectbox package. Any update on this? Update 1:
the error still present but scrolling within SelectBox works as well as within the parent scrollview. I also do have to suppress the error with LogBox. I don't know if there are any drawbacks to this but I'll try to test this more. |
Directly find the source code and comment out the console error path: react-native/Libraries/Lists/VirtualizedList.js line: 1135
|
Any update on this issue? |
Before version 0.63, it was only a warning, and then it became an error. If you have a better way, I am not willing to change the source code |
Summary: Nested `VirtualizedList` is now an [error](646605b), instead of a warning. Issues [here](#31697) and [here](#33024) outline the concern. ## Changelog [General] [Added] - Added a check to if `scrollEnabled` is not false, if so then fire the `VirtualizedList` error Pull Request resolved: #34560 Test Plan: Passes all provided automatic tests. In a personal app, there is a situation of nested ScrollViews that had triggered the error. After defining `scrollEnabled={false}` and adding the check, the error no longer appears. Reviewed By: yungsters Differential Revision: D39283866 Pulled By: NickGerleman fbshipit-source-id: 16ae6bbe6bb8b01a54ae18f9e6abf75d11c21c29
A solution for me was to create a custom FlatList component, something like this
|
As far as I see it this is fixed in RN 0.71 Changelog Plain view of the changelog with line reference: |
Yes the fix is here: 62f83a9 One-liner to just supress the error when thanks for the fix @annepham25 |
Solution: |
Summary: Nested `VirtualizedList` is now an [error](facebook@646605b), instead of a warning. Issues [here](facebook#31697) and [here](facebook#33024) outline the concern. ## Changelog [General] [Added] - Added a check to if `scrollEnabled` is not false, if so then fire the `VirtualizedList` error Pull Request resolved: facebook#34560 Test Plan: Passes all provided automatic tests. In a personal app, there is a situation of nested ScrollViews that had triggered the error. After defining `scrollEnabled={false}` and adding the check, the error no longer appears. Reviewed By: yungsters Differential Revision: D39283866 Pulled By: NickGerleman fbshipit-source-id: 16ae6bbe6bb8b01a54ae18f9e6abf75d11c21c29
🎖 Simple Solution To Fix It: 100% works 🤩 1- Add nestedScrollEnabled={true} to ScrollView
|
This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days. |
This issue was closed because it has been stalled for 7 days with no activity. |
How is adding Furthermore, I've seen sooo many people recommend The only solution I can see, so far, (which also seems strange) is rendering all of an app's main content in a Or a new prop for We need a legit solution here. |
Description
We use
FlatList
andSectionList
in various sub-components which we embed into a master component in two ways:FlatList
orSectionList
so has the benefit of using virtualization - we ensurescrollEnabled={true}
in this case,ScrollView
- we ensurescrollEnabled={false}
in this case,We get the "VirtualizedLists should never be nested inside plain ScrollViews with the same orientation" console error repeatedly in the case of 2. I think when
scrollEnabled={false}
it should turn off virtualization and suppress this console error, and render the list internally using standard maps. Yes I can build my own wrapper components to do this, but I think the framework should do it naturally.React Native version:
System:
OS: macOS 11.3.1
CPU: (8) x64 Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz
Memory: 388.60 MB / 16.00 GB
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 15.1.0 - /usr/local/bin/node
Yarn: 1.19.1 - ~/.yarn/bin/yarn
npm: 7.0.8 - /usr/local/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
Managers:
CocoaPods: 1.10.1 - /usr/local/bin/pod
SDKs:
iOS SDK:
Platforms: iOS 14.5, DriverKit 20.4, macOS 11.3, tvOS 14.5, watchOS 7.4
Android SDK:
API Levels: 23, 28, 29, 30
Build Tools: 23.0.1, 23.0.2, 25.0.0, 25.0.1, 25.0.2, 26.0.2, 26.0.3, 27.0.0, 27.0.3, 28.0.2, 28.0.3, 29.0.2, 29.0.3
System Images: android-16 | Google APIs Intel x86 Atom, android-22 | Google APIs Intel x86 Atom, android-28 | Google APIs Intel x86 Atom, android-29 | Google APIs Intel x86 Atom, android-29 | Google APIs Intel x86 Atom_64
Android NDK: Not Found
IDEs:
Android Studio: 4.1 AI-201.8743.12.41.7199119
Xcode: 12.5/12E262 - /usr/bin/xcodebuild
Languages:
Java: 1.8.0_271 - /Library/Java/JavaVirtualMachines/jdk1.8.0_271.jdk/Contents/Home/bin/javac
npmPackages:
@react-native-community/cli: Not Found
react: 17.0.1 => 17.0.1
react-native: 0.64.1 => 0.64.1
react-native-macos: Not Found
npmGlobalPackages:
react-native: Not Found
Steps To Reproduce
As per the description.
Expected Results
Would expect not to see the console error on a FlatList or SectionList which has
scrollEnabled={false}
.The text was updated successfully, but these errors were encountered: