import { IBubble } from '../../store/bubbles/types'; import React, { FunctionComponent } from 'react'; import { ViewStyle, View, StyleSheet, TextStyle, Text, Dimensions, RefreshControlProps } from 'react-native'; import { Strings } from '../../resources/localization/Strings'; import { IStyledProps } from '../common/types'; import { DataProvider, LayoutProvider, RecyclerListView } from 'recyclerlistview'; interface IBubbleProps extends IStyledProps { bubbles: IBubble[]; cellWidth?: number; cellHeight?: number; refreshControl?: React.ReactElement; renderItems: (bubble: IBubble) => React.ReactElement; renderListEmpty?: () => React.ReactElement; } export interface IBubbleStyleProps { listContainer?: ViewStyle; containerStyle?: ViewStyle; noDataMessageText?: TextStyle; noDataMessageView?: ViewStyle; } export const BubblesContainer: FunctionComponent = (props: IBubbleProps) => { const width = props.cellWidth ? props.cellWidth : Dimensions.get('window').width; const height = props.cellHeight ? props.cellHeight : 80; const mergedStyle = { ...defaultStyle, ...props.style }; const dataProvider = new DataProvider((r1: any, r2: any) => { return r1 !== r2; }).cloneWithRows(props.bubbles); const layoutProvider = new LayoutProvider(() => 'BUBBLES', (type: any, dim: { width: number; height: number }) => { switch (type) { case 'BUBBLES': dim.width = width; dim.height = height; break; default: dim.width = width; dim.height = 0; } } ); const renderEmptyList = () => { if (props.renderListEmpty) { return props.renderListEmpty; } else { return ( {Strings.noDataFound} ); } }; const renderItems = (type: string | number, item: IBubble) => { return props.renderItems(item); }; const renderBubblesListContent = () => { if (props.bubbles.length === 0) { return renderEmptyList(); } else { return ( ); } } return ( {renderBubblesListContent()} ); } const defaultStyle: IBubbleStyleProps = StyleSheet.create({ noDataMessageView: { fontSize: 25, justifyContent: 'center', flex: 1, marginTop: 100, }, noDataMessageText: { textAlign: 'center', }, containerStyle: { flex: 1, backgroundColor: '#ffffff', height: 'auto', }, listContainer: { flex: 1, flexDirection: 'row', minHeight: 1, } });