我想在react-Nativ中将react-native ListView迁移到FlatList

我想在react-Nativ中将react-native ListView迁移到FlatList,react-native,firebase-realtime-database,react-native-android,react-native-flatlist,React Native,Firebase Realtime Database,React Native Android,React Native Flatlist,我想在react native 0.60.5版本中将ListView迁移到FlatList。这是我的密码,请帮我 导出默认类配方扩展组件{ 建造师(道具){ 超级(道具) const ds=new ListView.DataSource({rowHasChanged:(r1,r2)=>r1!==r2}) 此.state={ uid:“”, 数据源:ds.cloneWithRows([]), 原始配方:“” } } 组件willmount(){ 试一试{ 让user=firebase.auth()

我想在react native 0.60.5版本中将ListView迁移到FlatList。这是我的密码,请帮我

导出默认类配方扩展组件{
建造师(道具){
超级(道具)
const ds=new ListView.DataSource({rowHasChanged:(r1,r2)=>r1!==r2})
此.state={
uid:“”,
数据源:ds.cloneWithRows([]),
原始配方:“”
}
}
组件willmount(){
试一试{
让user=firebase.auth().currentUser
这是我的国家({
uid:user.uid
})
Helpers.getAllRecipes((recipes)=>{
如果(食谱){
这是我的国家({
dataSource:this.state.dataSource.cloneWithRows(recipes),
菜谱:菜谱
})
}
})
}捕获(错误){
console.log(错误)
}
}
closeView(){
this.props.navigator.pop()
}
renderRow(行数据){
const img=rowData.image
返回(
{rowData.food}
{rowData.title}
通过{rowData.userName}
)
}
render(){
返回(
)
}
}
这是我的数据库助手代码

static getUserCategories(userId, callback) {
    let userNamePath = '/user/' + userId;
    firebase
      .database()
      .ref(userNamePath)
      .on('value', snapshot => {
        let data = snapshot.val();
        if (snapshot) {
          if (data.rcategories) {
            let obj = {
              category: data.rcategories.category,
            };
            callback(obj);
          }
        }
      });
  }

您需要将数据模型从数据源对象重构为常规数组。 之后,您需要在列表组件上重命名道具

数据源->数据

renderRow->renderItem

文档()中的示例:

(
)}
数据={[{title:'title Text',key:'item1'}]}
renderItem={({项,索引,分隔符})=>(
这个._onPress(项目)}
onShowUnderlay={separators.highlight}
onHideUnderlay={separators.unhighlight}>
{item.title}
)}
/>
<FlatList
  ItemSeparatorComponent={Platform.OS !== 'android' && ({highlighted}) => (
    <View style={[style.separator, highlighted && {marginLeft: 0}]} />
  )}
  data={[{title: 'Title Text', key: 'item1'}]}
  renderItem={({item, index, separators}) => (
    <TouchableHighlight
      onPress={() => this._onPress(item)}
      onShowUnderlay={separators.highlight}
      onHideUnderlay={separators.unhighlight}>
      <View style={{backgroundColor: 'white'}}>
        <Text>{item.title}</Text>
      </View>
    </TouchableHighlight>
  )}
/>