0
I 확장하고 내가 다른 화면에서 새 항목을 추가 할 때 onPress
이FlatList 렌더링 행하지만 표시되지 항목
그러나, 다음 SearchListScreen
로 돌아가 축소 할 수 있습니다 항목과 FlatList를 만들기 위해 노력하고, 그것을 것 만 표시 2 개 항목이지만 FlatList
은 올바른 행 수를 렌더링합니다.
예 :
내가 항목을 제거하거나 항목을 확장 할 때 같은 일이 발생
새 항목을 추가 한 후 새 항목을
을 추가하기 전에.
여기 내 코드입니다 : 고민의 시간 후
SearchList.js
import React, { Component } from 'react'
import { Text, View, FlatList, StyleSheet } from 'react-native'
import SearchCard from './SearchCard'
export default class SearchList extends Component {
wrapperStyle (index) {
return index > 0 ? styles.listItemWrapper : [styles.listItemWrapper, styles.wrapperFirst]
}
_renderItem = ({item, index}) => (
<View style={this.wrapperStyle(index)}>
<SearchCard
search={item}
id={item.id}
filterAttributes={this.props.filterAttributes}
onSearch={this.props.onSearch}
onFavorite={this.props.onFavorite}
favorites={this.props.favorites}
/>
</View>
)
render() {
const { searches, filterAttributes, onSearch, onFavorite, favorites } = this.props
return (
<FlatList
data={searches}
extraData={{ filterAttributes: filterAttributes, onSearch: onSearch, onFavorite: onFavorite, favorites: favorites, searches: searches }}
keyExtractor={item => item.id}
renderItem={this._renderItem}
enableEmptySections
style={{backgroundColor: 'red'}}
/>
)
}
}
const styles = StyleSheet.create({
wrapperFirst: {
marginTop: 20
},
listItemWrapper: {
marginLeft: 20,
marginRight: 20,
marginBottom: 20
}
})