Created
August 11, 2017 06:41
-
-
Save cyio/82473ed2f8e92468be8817f063369d9b to your computer and use it in GitHub Desktop.
Migrating from ListView to FlatList in React Native. Raw
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/app/containers/Search.js b/app/containers/Search.js | |
index 6a742f5..d75a738 100644 | |
--- a/app/containers/Search.js | |
+++ b/app/containers/Search.js | |
@@ -7,6 +7,7 @@ import { | |
Dimensions, | |
TouchableOpacity, | |
ListView, | |
+ FlatList, | |
ScrollView | |
} from 'react-native'; | |
import { observable, computed } from 'mobx'; | |
@@ -242,14 +243,14 @@ export default class Search extends React.Component { | |
{this.state.loading ? (<Loading zIndex={102} top={200}/>) : ( | |
<View> | |
{this.state.data && this.state.data.items.length > 0 ? ( | |
- <ListView | |
+ <FlatList | |
contentContainerStyle={styles.contentBlock} | |
- dataSource={this.dataSource.cloneWithRows(this.state.data.items)} | |
+ data={this.state.data.items} | |
+ keyExtractor={item => item.id} | |
onEndReached={this.onEndReach.bind(this)} | |
- onEndReachedThreshold={10} | |
- renderFooter={this._renderMoreFooter()} | |
- enableEmptySections={true} | |
- renderRow={(data) => this._renderItem(data, navigate)} | |
+ onEndReachedThreshold={1} | |
+ ListFooterCompontent={this._renderMoreFooter()} | |
+ renderItem={(data) => this._renderItem(data.item, navigate)} | |
/> | |
) : ( | |
<View style={[styles.searchTips, !this.state.showSelect && styles.showSearchContent]}> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
有两个问题: