@janiscommerce/ui-native
Version:
components library for Janis app
17 lines (16 loc) • 726 B
JavaScript
import React from 'react';
import { FlatList, ScrollView } from 'react-native';
export var TypeList;
(function (TypeList) {
TypeList["FlatList"] = "flatList";
TypeList["ScrollView"] = "scrollView";
})(TypeList || (TypeList = {}));
const List = ({ data, renderComponent, type = TypeList.FlatList, ...props }) => {
if (!data?.length) {
return null;
}
const FlatListComponent = () => <FlatList data={data} renderItem={renderComponent} {...props}/>;
const ScrollViewComponent = () => (<ScrollView {...props}>{data.map((item, index) => renderComponent({ item, index }))}</ScrollView>);
return type === TypeList.FlatList ? <FlatListComponent /> : <ScrollViewComponent />;
};
export default List;