2020-03-10 17:08:57 +01:00
|
|
|
import * as React from 'react';
|
|
|
|
import {FlatList} from "react-native";
|
|
|
|
|
2020-03-10 17:18:02 +01:00
|
|
|
type Props = {
|
|
|
|
data: Array<Object>,
|
|
|
|
keyExtractor: Function,
|
|
|
|
renderItem: Function,
|
|
|
|
updateData: number,
|
|
|
|
}
|
2020-03-10 17:08:57 +01:00
|
|
|
|
2020-03-10 17:18:02 +01:00
|
|
|
/**
|
2020-03-29 14:46:44 +02:00
|
|
|
* FlatList implementing PureComponent for increased performance.
|
|
|
|
*
|
2020-03-10 17:18:02 +01:00
|
|
|
* This is a pure component, meaning it will only update if a shallow comparison of state and props is different.
|
|
|
|
* To force the component to update, change the value of updateData.
|
|
|
|
*/
|
2020-03-29 14:46:44 +02:00
|
|
|
export default class PureFlatList extends React.PureComponent<Props> {
|
2020-03-10 17:08:57 +01:00
|
|
|
|
2020-03-10 17:18:02 +01:00
|
|
|
static defaultProps = {
|
|
|
|
updateData: null,
|
|
|
|
};
|
|
|
|
|
2020-03-10 17:08:57 +01:00
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<FlatList
|
|
|
|
data={this.props.data}
|
|
|
|
keyExtractor={this.props.keyExtractor}
|
|
|
|
style={{minHeight: 300, width: '100%'}}
|
|
|
|
renderItem={this.props.renderItem}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|