2019-08-27 12:25:38 +00:00
|
|
|
import React from 'react';
|
2021-07-21 15:15:13 +00:00
|
|
|
import { ScrollView, TouchableOpacity, View, Text } from 'react-native';
|
2019-08-27 12:25:38 +00:00
|
|
|
|
|
|
|
import { CELL_WIDTH } from './TableCell';
|
|
|
|
import styles from './styles';
|
|
|
|
import Navigation from '../../lib/Navigation';
|
|
|
|
import I18n from '../../i18n';
|
2019-12-04 16:39:53 +00:00
|
|
|
import { themes } from '../../constants/colors';
|
2019-08-27 12:25:38 +00:00
|
|
|
|
2021-07-21 15:15:13 +00:00
|
|
|
interface ITable {
|
|
|
|
children: JSX.Element;
|
|
|
|
numColumns: number;
|
|
|
|
theme: string;
|
|
|
|
}
|
|
|
|
|
2019-08-27 12:25:38 +00:00
|
|
|
const MAX_HEIGHT = 300;
|
|
|
|
|
2021-07-21 15:15:13 +00:00
|
|
|
const Table = React.memo(({ children, numColumns, theme }: ITable) => {
|
2019-08-27 12:25:38 +00:00
|
|
|
const getTableWidth = () => numColumns * CELL_WIDTH;
|
|
|
|
|
2021-07-21 15:15:13 +00:00
|
|
|
const renderRows = (drawExtraBorders: boolean = true) => {
|
2019-12-04 16:39:53 +00:00
|
|
|
const tableStyle = [styles.table, { borderColor: themes[theme].borderColor }];
|
2019-08-27 12:25:38 +00:00
|
|
|
if (drawExtraBorders) {
|
|
|
|
tableStyle.push(styles.tableExtraBorders);
|
|
|
|
}
|
|
|
|
|
2021-07-21 15:15:13 +00:00
|
|
|
const rows: any = React.Children.toArray(children);
|
2019-08-27 12:25:38 +00:00
|
|
|
rows[rows.length - 1] = React.cloneElement(rows[rows.length - 1], {
|
|
|
|
isLastRow: true
|
|
|
|
});
|
|
|
|
|
|
|
|
return (
|
|
|
|
<View style={tableStyle}>
|
|
|
|
{rows}
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2020-02-12 17:21:11 +00:00
|
|
|
const onPress = () => Navigation.navigate('MarkdownTableView', { renderRows, tableWidth: getTableWidth() });
|
2019-08-27 12:25:38 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<TouchableOpacity onPress={onPress}>
|
|
|
|
<ScrollView
|
|
|
|
contentContainerStyle={{ width: getTableWidth() }}
|
|
|
|
scrollEnabled={false}
|
|
|
|
showsVerticalScrollIndicator={false}
|
2019-12-04 16:39:53 +00:00
|
|
|
style={[styles.containerTable, { maxWidth: getTableWidth(), maxHeight: MAX_HEIGHT, borderColor: themes[theme].borderColor }]}
|
2019-08-27 12:25:38 +00:00
|
|
|
>
|
|
|
|
{renderRows(false)}
|
|
|
|
</ScrollView>
|
2019-12-04 16:39:53 +00:00
|
|
|
<Text style={[styles.textInfo, { color: themes[theme].auxiliaryText }]}>{I18n.t('Full_table')}</Text>
|
2019-08-27 12:25:38 +00:00
|
|
|
</TouchableOpacity>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
export default Table;
|