-
Notifications
You must be signed in to change notification settings - Fork 24.3k
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
Grid layout using FlatList not rendering properly for IOS #13939
Comments
|
But |
Is there a reason why Is there a way to dynamically specify the number of columns so that it mimics the behavior of |
Because there has not been sufficient demand to justify the effort and complexity of building it. You can use flexWrap inside of rows in your FlatList, or you can just use a ScrollView instead of FlatList. Depends on what you need. |
|
@sahrens I think that a grid with dynamic columns (resize depending of the width of the device) is very very important (iPhone, iPad, etc), for example: idibidiart/react-native-responsive-grid#15 (comment)
Any solution that works with multiple devices, changing the orientation and supports infinite scrolling? For example, with NativeScript is very easy => http://docs.telerik.com/devtools/nativescript-ui/Controls/Angular/ListView/overview#different-layouts Thanks in advance! |
Can you measure (e.g. with onLayout) and use that to specify numColumns? Or you can use ScrollView with flexWrap and build infinite scrolling logic yourself without too much trouble. |
@sahrens You can't specify |
onLayout will fire with new measurements when the orientation updates and you can update numColumns at that point. You’ll need to also change the key on the list for force a full re-render, and might want to scroll back to where the user was before as well. |
ohh any example to change the key? I'm learning React Native and scroll back to where the user was before looks complicated |
With the ScrollView I can only find an example with the |
ok, looks perfect using the onLayout, example:
Thanks @sahrens! |
I'm glad that worked, but you should probably use the width that's passed into your
|
How would you calculate numColumns if the width of the items are dynamic (ie the width of each items are difference from each other and we don't know the width until runtime)? The width size is dependent on the text. @sahrens |
That’s not supported by FlatList, you’ll need to use ScrollView or something else. |
I'm currently able to setup a wrappable list of equally-sized items inside a This solution works for me, and my basic case. There seems to be a degree of support already, so how "unsupported" is it truly? I'm guessing it breaks when dealing with multiple sized items, but I'd like some clarification if possible. |
Many features of FlatList will break, such as virtualization, viewability callbacks, scroll to index, etc. You should just use a ScrollView in that case. You can even make your own simple wrapper component that copies the FlatList API if you want. |
@sahrens are there any plans of adding this?
works as it should. |
No plans. Please just use a ScrollView. |
Description
I am trying to make grid view where items have a minimum and a maximum width. The number of items on grid scale according to screen size.
I was able to achieve this with ListView, but same is not happening with FlatList. The items in the FlatList are sticking to minimum width, even though extra space is available.
Here is an example at Snack. You can check yourself the issue. The issue is only for ios, on Android it is running fine.
https://snack.expo.io/SywBhpMgW
Code to reproduce
import React, { Component } from 'react';
import {View, StyleSheet, FlatList } from 'react-native';
export default class App extends Component {
renderItem({ item, index }) {
return <View style={{
flex: 1,
margin: 5,
minWidth: 170,
maxWidth: 223,
height: 304,
maxHeight:304,
backgroundColor: '#CCC',
}}/>
}
render () {
return (<FlatList
contentContainerStyle={styles.list}
data={[{key: 'a'}, {key: 'b'},{key: 'c'},{key: 'd'}, {key: 'e'},{key: 'f'},{key: 'g'}, {key: 'h'},{key: 'i'},{key: 'j'}]}
renderItem={this.renderItem}
/>);
}
}
const styles = StyleSheet.create({
list: {
justifyContent: 'center',
flexDirection: 'row',
flexWrap: 'wrap',
}
});
Additional Information
The text was updated successfully, but these errors were encountered: