Mor*_*ton 9 react-native react-native-flatlist react-native-sectionlist
我想用来getItemLayout让<FlatList />效率更高。
但是当用于onLayout获取不稳定的列表高度时,可能是 128 或 230 或 183。
所以设置itemHeight为128进getItemLayout是不能正常工作的。
有没有其他方法可以让我itemHeight的动态高度进入我的getItemLayout?
onLayout(event) {
const {x, y, height, width} = event.nativeEvent.layout;
console.log('height:', height); // the height is dynamic
}
renderItem = ({ item }) => {
return (
<View onLayout={(event) => this.onLayout(event)} style={styles.floorView} style={styles.itemView}>
<Text>{item.name}</Text>
</View>
);
}
<FlatList
data={DUMMY_LIST}
ref={(ref) => { this.flatListRef = ref; }}
renderItem={this.renderItem}
numColumns={1}
keyExtractor={(item, index) => index.toString()}
getItemLayout={(data, index)=> {
return { length: itemHeight, offset: itemHeight * index , index };
}}
/>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1204 次 |
| 最近记录: |