VirtualizedLists should never be nested inside plain ScrollViews React Native - react-native

hi i'm getting this error i don't know how to fix it
error type : "VirtualizedLists should never be nested inside plain
ScrollViews with the same orientation because it can
break windowing and other functionality - use another
VirtualizedList-backed container instead."
my code
return (
<View style={{flex: 1}}>
<SwipeListView
data={listData}
renderItem={renderItem}
renderHiddenItem={renderHiddenItem}
/>
</View>
);

Related

VirtualizedLists should never be nested inside plain ScrollViews by using react native SearchableDropdown

How to use scrollview over package like react-native-autocomplete-input? Basically I have a form in my react native package in which there are multiple input fields including autocomplete so I need a scroll over my screen so how should I achieve that?My code looks like that
<ScrollView>
<Card>
<TextInput />
<SearchableDropdown />
<TextInput />
<Picker />
</Card>
</Scrollview>
It gives me that error
VirtualizedLists should never be nested inside plain ScrollViews with the same orientation because it can break windowing and other functionality

TouchableHighlight not working although using the source code from official react native documentation

I'm a new react native developer and I have an issue with TouchableHighlight where it always shows an error "Error: React.Children.only expected to receive a single React element child." in addition while I remove it is work as usual and I assume if this issue come from my device/vscode/browser. Because I already follow the source code from https://reactnative.dev/docs/touchablehighlight but still show that error.
Error image
Image without TouchableHighlight tag
Here my code
render() {
return (
<View style={styles.container}>
<TouchableHighlight onPress={this.onPress}>
<View style={styles.button}>
<Text>Touch Here</Text>
</View>
</TouchableHighlight>
<View style={[styles.countContainer]}>
<Text style={[styles.countText]}>
{this.state.count ? this.state.count : null}
</Text>
</View>
</View>
);}
From the error message, the issue might happen if you pass Mutlipe child components to TouchableHighlight
From the docs:
TouchableHighlight must have one child (not zero or more than one). If you wish to have several child components, wrap them in a View
<TouchableHighlight onPress={onPress}>
<View style={styles.button}> // Mutlipe child components are wrapped in a View
<Text>Touch</Text> // component 1
<Text>Here</Text> // component 2
</View>
</TouchableHighlight>

React Native Base Picker displaying Warning : VirtualizedLists should never be nested inside plain ScrollViews

I'm using Native base's Picker component and rendering using .map:
Tried everything the Internet has suggested!! Didn't get it fixed yet
<Item rounded style={{marginBottom:20}}>
<Picker selectedValue={this.state.district} onValueChange={(val)=>this.setDistrict(val)}>
<Picker.Item label='Select District' value='0'/>
{this.state.districtsList.map((item,index) => {
return (<Picker.Item label={item.name} value={item.id} key={index+1}/>) //if you have a bunch of keys value pair
})}
</Picker>
Experiencing the same thing!
You can use like this:
<SafeAreaView> Your code block </SafeAreaView>

How to fix this warning: VirtualizedLists should never be nested inside plain ScrollViews with the same orientation

When I use FlatList component inside ScrollView I see a warning:
VirtualizedLists should never be nested inside plain ScrollViews with the same orientation - use another VirtualizedList-backed container instead.
Before and after FlatList I use a lot of other components and my screen is long.
I tried to wrap content with SafeAreaView and it doesn't help me, because in this case I can't scroll the content. I also tried to use ListHeaderComponent={SafeAreaView} and ListFooterComponent={SafeAreaView} in <FlatList>.
I use:
"react": "16.9.0",
"react-native": "0.61.5",
Here is a VirutalizedList -backed container implementation using FlatList:
import React from 'react';
import { FlatList } from 'react-native';
export default function VirtualizedView(props: any) {
return (
<FlatList
data={[]}
ListEmptyComponent={null}
keyExtractor={() => "dummy"}
renderItem={null}
ListHeaderComponent={() => (
<React.Fragment>{props.children}</React.Fragment>
)}
/>
);
}
Usage:
<VirtualizedView>
<Text>Anything goes here, even FlatList works good</Text>
<View style={{minHeight: 480}}> // leave enough space for better user experience
<FlatList
data={data}
keyExtractor={keyExtractor}
renderItem={({item}) => <Item data={item} />}
onRefresh={refetch}
refreshing={loading}
onEndReached={concatData}
/>
</View>
</VirtualizedView>
This will show scrollbar when your screen is too long and also remove the pesky warning message and performance will be saved without any problem.
There is a simpler solution using https://facebook.github.io/react-native/docs/scrollview#nestedscrollenabled
This is only required for Android (iOS works as expected even without it).
Just make sure to enable this prop in both parent and child ScrollViews (or child FlatLists).
What I've done in my case is something along the lines of this:
render() {
return (
<SafeAreaView style={{ flex: 1 }}>
...
<ScrollView>
...
<FlatList
scrollEnabled={false} // this line is important
...
</FlatList>
...
</ScrollView>
</SafeAreaView>
);
}
It doesn't remove the warning, but it does work as I want it to, as I need a ScrollView and a FlatList.

React Native "keyboardDismissMode" at FlatList

Is there any possibility to prevent the keyboard from dismissing when scrolling a FlatList?
When using a ScrollView setting the prop "keyboardDismissMode" to "none" is the solution to this problem, but this doesn't work for me at a FlatList...
I use the FlatList inside a self-made component, that is in a Stack-Navigator, while there is a focussed TextInput in its header. I render the FlatList like this:
<View style={{flex: 1}}>
<FlatList
style={{flex: 1}}
data={this.props.data}
keyExtractor={(item, index) => item.id}
renderItem={this.renderItem}
/>
</View>
The renderItem() function:
renderItem = ({item, index}) => (
<TouchableHighlight
style={{paddingVertical: 10}}
onPress={() => {
this.props.onChooseItem(item);
}}
>
<Text numberOfLines={1} >
{item.text}
</Text>
</TouchableHighlight>
)
The docs at the beginning of the reference section says that FlatList "Inherits ScrollView Props, unless it is nested in another FlatList of same orientation."
So I think you can just do use that keyboardDismissMode without encapsulation in a scrollview.
No need of scrollview inside flatlist it will create performance issue.
just add onScrollBeginDrag={Keyboard.dismiss} in flatlist. it will work in android as well iOS while keyboardDismissMode='on-drag' will work only in iOS
You might think about to encapsulate your FlatList in a ScrollView?
Even if this seems to solve the issue, it's NOT a recommended way!
That's because if it force rerendering the whole flatlist, each time you scroll the screen.
You might better try a component like react-native-keyboard-aware-scroll-view
I've found this article with some alternate Ideas to fix it:
How to use KeyboardAvoidingView with FlatList?
Check: https://facebook.github.io/react-native/docs/scrollview#keyboarddismissmode