react-native-flatlist

React Native FlatList load more when we get to the bottom of the list

。_饼干妹妹 提交于 2019-12-06 04:05:19
How to make load more with FlatList of React Native (Not infinite) I've done this, but unfortunately it loads as infinitely. This is my code snippet <FlatList data={this.props.data} renderItem={({ item, separators }) => ( <TouchableHighlight onPress={() => this._onPress(item)} onShowUnderlay={separators.highlight} onHideUnderlay={separators.unhighlight} > <Text> {item.title} </Text> </TouchableHighlight> )} keyExtractor={item => item.id} ListFooterComponent={this.renderFooter} onEndReached={this.props.handleLoadMore} onEndThreshold={0} /> And my handleLoadMore handleLoadMore = () => { console

React Native nested ListView triggers onEndReached multiple times on loading

眉间皱痕 提交于 2019-12-05 13:04:10
Here's the code: <ScrollView> { tree.myPoiComments.CommentInfo && tree.myPoiComments.CommentInfo.length>0 && <FlatList data={tree.myPoiComments.CommentInfo} keyExtractor = {(item, index) => item.CommentId} ListHeaderComponent = {() => <View> <Text style={styles.listHeader}>My Comments</Text> </View>} renderItem= {({item}) => <CommentItem comment={item} owner={1} />} /> } { tree.poiComments.CommentInfo && tree.poiComments.CommentInfo.length>0 && <FlatList data={tree.poiComments.CommentInfo} keyExtractor = {(item, index) => item.CommentId} onEndReachedThreshold={1} onEndReached={(info) => {

How do I alternate colors in Flat List (React Native)

丶灬走出姿态 提交于 2019-12-05 10:18:45
Trying to alternate colors in React Natives Flatlist . I believe I need rowID or something similar to do it. This is what I've got so far: let colors = ['#123456', '#654321', '#fdecba', '#abcdef']; <View > <FlatList style={{backgroundColor: colors[this.index % colors.length]}} data={this.state.dataSource} renderItem={({item}) => <Text style={styles.listStyle}>{item.title}, {item.releaseYear}</Text>} keyExtractor={(item, index) => index} /> </View> Any ideas? The renderItem callback argument has a property index that allows you to access the row index for the current row: <View > <FlatList data

React Native: Can't fix FlatList keys warning

南笙酒味 提交于 2019-12-05 09:46:58
I'm trying to render a FlatList from json fetched from an api, but I keep getting this error: Warning: Each child in an array or iterator should have a unique "key" prop. Check the render method of `VirtualizedList`. Relevant code: <FlatList data={this.props.tunes} keyExtractor={(item, index) => item.id} renderItem={({item}) => { <Item key={item.id} title={item.title} composer={item.composer} year={item.year} /> }} /> I'm sure there is a simple fix for this, but after a few days of trying different things I haven't found it. Thanks for your help! Looks like you need to change key to id as you

React Native FlatList vs ListView

此生再无相见时 提交于 2019-12-04 23:43:16
问题 "Use the new FlatList or SectionList component instead. Besides simplifying the API, the new list components also have significant performance enhancements, the main one being nearly constant memory usage for any number of rows." This is stated on React Native's official docs. However, no matter how hard I try, FlatList memory uses just keeps sky rocketing when scrolling down. Compared to ListView component which uses way less memory. 回答1: TLDR Create a PureComponent to use in renderItem:

ReactNative FlatList render all items at once?

天涯浪子 提交于 2019-12-04 19:28:57
问题 I'm using ReactNative's new List component - FlatList. It seems like FlatList renders all items at once even though the cell isn't actually visible on the screen. <FlatList data={this.props.items} keyExtractor={(item, index) => generateKey()} renderItem={this.renderStrip}/> renderItem = ({item}) => { console.warn('rendered!'); return <View style={{height:200, height: 100}} /> } Setting 30 items and seems like 'rendered' warning was called according to the total number of the items. I thought

React Native FlatList onPress for child

爷,独闯天下 提交于 2019-12-04 16:53:36
I'm trying to wire up a press handler for an image that's nested within a React Native FlatList. I've verified that the function is being passed in via props, by calling the function directly inside my component and that worked fine. Below is a reduced test case. I've also tried setting the onPress on the Image, with identical results. const PostList = ({posts, onActLike, currentUser}) => { return ( <FlatList data={ posts } keyExtractor={ (item) => item.id } renderItem={ ({item}) => { return ( <View> <Image source={ {uri: item.media.url} } resizeMode="cover" /> <View> <View onPress={ (item) =>

How to select item(s) out of a FlatList?

为君一笑 提交于 2019-12-04 16:37:04
I want to select items using FlatList like when you select multiple photos on your photo galery (in this case, I am using a flatlist with 2 rows like a grid of 2x10). I want to select (for example) 3 items using onLongPress. Something like this, but with 2 rows. What about this: Every item rendered would have an onLongPress , and an isPicked property. Initially, and in renderItem() , you would implement an if statement that either renders checked square or empty square every time an item executes executes; To indicate if the item is selected or not (based on isPicked ). onLongPress invokes

React Native - Use a keyExtractor with FlatList

倖福魔咒の 提交于 2019-12-03 15:14:07
问题 I have been getting the: "VirtualizedList: missing keys for items, make sure to specify a key property on an item or provide a custom keyExtractor" pretty confusing..., the array i am passing it has a key property defined in each object in the array. I have that array defined in this.state. I ran a quick print out in the console to be sure: print out of array Each object in array is defined as: var obj = {key: doc.id, value: doc.data()}; (doc and data being from another part of my app, but I

ReactNative FlatList render all items at once?

扶醉桌前 提交于 2019-12-03 13:00:10
I'm using ReactNative's new List component - FlatList. It seems like FlatList renders all items at once even though the cell isn't actually visible on the screen. <FlatList data={this.props.items} keyExtractor={(item, index) => generateKey()} renderItem={this.renderStrip}/> renderItem = ({item}) => { console.warn('rendered!'); return <View style={{height:200, height: 100}} /> } Setting 30 items and seems like 'rendered' warning was called according to the total number of the items. I thought FlatList is similar to the way RecycleView in Android works, render an item only when it's about to be