反应本机Listview禁用回收
这个问题可能有点离经叛道,或者与一些最佳实践背道而驰,但我想在我的react native listview中谈谈细胞回收 我会解释我的问题 我在react native中过滤100行。如果我在5个初始行渲染后不滚动(所有行都有网络图像),我的过滤方法就可以正常工作。这5个人的表现都很好。但是,如果我滚动并查看30行,并更改数据源状态,listview只会在几秒钟内重复使用单元格及其糟糕的性能。(也就是说,事情变得不稳定,我的模式关闭动画不流畅) 因此,简而言之,我想在数据源更改或禁用回收部分时完全重置listview组件。这可能吗 代码 列表视图反应本机Listview禁用回收,listview,reactjs,react-native,Listview,Reactjs,React Native,这个问题可能有点离经叛道,或者与一些最佳实践背道而驰,但我想在我的react native listview中谈谈细胞回收 我会解释我的问题 我在react native中过滤100行。如果我在5个初始行渲染后不滚动(所有行都有网络图像),我的过滤方法就可以正常工作。这5个人的表现都很好。但是,如果我滚动并查看30行,并更改数据源状态,listview只会在几秒钟内重复使用单元格及其糟糕的性能。(也就是说,事情变得不稳定,我的模式关闭动画不流畅) 因此,简而言之,我想在数据源更改或禁用回收部分时
<ListView
dataSource={this.state.dataSource}
removeClippedSubviews={true}
ref={'listview'}
initialListSize={5}
onEndReachedThreshold={1}
scrollRenderAheadDistance={1}
pageSize={1}
enableEmptySections={true}
renderRow={this._renderItem.bind(this)}
/>
不熟悉本机,但我想如果你改变了这个组件的关键道具,你会得到一个新的。考虑用你的实际代码更新你的问题。我猜你不需要做你要求的事情,实际上你在其他地方有问题。我已经包括了我的代码@RobLynch,如何更改组件上的键属性?您是否尝试调用此.setState({dataSource:newArray});在requestAnimationFrame函数中。此外,您应该尝试调用St.Stase.DATABOCECE.CURONE ROWS,而不是新的ListVIEW.DATAURCE EVYTIME。不熟悉本机,但我认为如果您更改组件上的密钥支柱,您将得到一个新的。请考虑用您的实际代码更新您的问题。我猜你不需要做你要求的事情,实际上你在其他地方有问题。我已经包括了我的代码@RobLynch,如何更改组件上的键属性?您是否尝试调用此.setState({dataSource:newArray});在requestAnimationFrame函数中。另外,您应该尝试在筛选代码上调用this.state.dataSource.cloneWithRows,而不是new ListView.dataSource eveytime。
return (
<View style={{backgroundColor:"#ffffff",marginTop:1,overflow:'hidden'}}>
<TouchableOpacity onPress={() => Actions.DirectoryDetail({title:item.title,item})}>
<View style={{backgroundColor:'white',flexDirection:'row',paddingLeft:5,}}>
<View style={{alignItems:'flex-start',flex:3,}}>
<Text style={{fontFamily:'oswald-bold',fontSize:screenWidth/15,color:"#000000"}}>{item.title}</Text>
<View style={{flexDirection:'row'}}>
<Text style={{paddingBottom:2,fontFamily:'oswald-regular',color:'#c0392b',paddingRight:10,fontSize:screenWidth/23}}>
{item.category}
</Text>
<StarRating
disabled={true}
maxStars={5}
rating={item.rate}
starColor={'#FFD700'}
emptyStarColor={'#bdc3c7'}
starSize={20}
selectedStar={(rating) => this.onStarRatingPress(rating)}
/>
</View>
<Text>{newDescriptionString}</Text>
</View>
<View style={{alignItems:'flex-end',flex:2,paddingRight:5}}>
<Image
onLoad={() => this.setState({loading:false})}
style={{width: screenWidth / 3,height: screenWidth / 3}}
source={{uri: item.profile}}
resizeMode={'contain'}>
</Image>
</View>
</View>
</TouchableOpacity>
</View>
);
//itemsString is my object that I stringify
var itemsString = JSON.parse(this.state.itemsString);
var all = itemsString.filter(function(d){
return d.active === true
})
let newArray = new ListView.DataSource({
rowHasChanged: (row1, row2) => row1 !== row2,
}).cloneWithRows(all)
this.setState({
dataSource: newArray
});