import React from 'react';
import { StyleSheet } from 'react-native';
import Example from '../../shared/example';
import { FlatList, Text, TouchableOpacity, View } from 'react-native-web';
const multiSelectData = ['First', 'Second', 'Third'].map((title, id) => ({
id,
title
}));
const minimalData = ['a', 'b', 'c', 'd', 'e'].map((key) => ({ key }));
const pageExamplesData = ['minimal', 'multiSelect'].map((type) => ({ type }));
class MyListItem extends React.PureComponent {
_onPress = () => {
this.props.onPressItem(this.props.id);
};
render() {
const textColor = this.props.selected ? 'red' : 'black';
return (
{this.props.title}
);
}
}
class MultiSelectList extends React.PureComponent {
state = { selected: new Map() };
_keyExtractor = (item, index) => item.id;
_onPressItem = (id) => {
// updater functions are preferred for transactional updates
this.setState((state) => {
// copy the map rather than modifying state.
const selected = new Map(state.selected);
selected.set(id, !selected.get(id)); // toggle
return { selected };
});
};
_renderItem = ({ item }) => (
);
render() {
return (
);
}
}
function renderExampleItem({ item }) {
switch (item.type) {
case 'minimal':
// Example Minimal FlatList, directly from FlatList's own JSDoc details.
// Appending our own view as a header to keep this example itself tightly matching the JSDoc.
return (
Minimal FlatList:
(
{item.key}
)}
/>
);
case 'multiSelect':
// Example Multi-Select FlatList, directly from FlatList's own JSDoc details.
// Appending our own view as a header to keep this example itself tightly matching the JSDoc.
return (
Multi-Select FlatList:
);
default:
throw new Error('Unexpected Item Type');
}
}
export default function FlatListPage() {
return (
(Example ListFooterComponent Here)
}
ListHeaderComponent={
(Example ListHeaderComponent Here)
}
data={pageExamplesData}
renderItem={renderExampleItem}
/>
);
}
const styles = StyleSheet.create({
allExamplesFooter: { fontSize: 22 },
allExamplesHeader: { fontSize: 22, marginBottom: 20 },
exampleContainer: { marginBottom: 20 },
exampleHeaderText: { fontSize: 18, fontWeight: 'bold' },
listItemText: { fontSize: 16 }
});