2019-09-03 19:27:57 +00:00
|
|
|
import { PropTypes } from 'prop-types';
|
|
|
|
import React from 'react';
|
|
|
|
import {
|
|
|
|
ScrollView,
|
|
|
|
TouchableOpacity,
|
|
|
|
View,
|
|
|
|
Text
|
|
|
|
} from 'react-native';
|
|
|
|
|
|
|
|
import { CELL_WIDTH } from './TableCell';
|
|
|
|
import styles from './styles';
|
|
|
|
import Navigation from '../../lib/Navigation';
|
|
|
|
import I18n from '../../i18n';
|
2019-12-11 23:01:12 +00:00
|
|
|
import { themes } from '../../constants/colors';
|
2019-09-03 19:27:57 +00:00
|
|
|
|
|
|
|
const MAX_HEIGHT = 300;
|
|
|
|
|
|
|
|
const Table = React.memo(({
|
2019-12-11 23:01:12 +00:00
|
|
|
children, numColumns, theme
|
2019-09-03 19:27:57 +00:00
|
|
|
}) => {
|
|
|
|
const getTableWidth = () => numColumns * CELL_WIDTH;
|
|
|
|
|
|
|
|
const renderRows = (drawExtraBorders = true) => {
|
2019-12-11 23:01:12 +00:00
|
|
|
const tableStyle = [styles.table, { borderColor: themes[theme].borderColor }];
|
2019-09-03 19:27:57 +00:00
|
|
|
if (drawExtraBorders) {
|
|
|
|
tableStyle.push(styles.tableExtraBorders);
|
|
|
|
}
|
|
|
|
|
|
|
|
const rows = React.Children.toArray(children);
|
|
|
|
rows[rows.length - 1] = React.cloneElement(rows[rows.length - 1], {
|
|
|
|
isLastRow: true
|
|
|
|
});
|
|
|
|
|
|
|
|
return (
|
|
|
|
<View style={tableStyle}>
|
|
|
|
{rows}
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2020-02-19 19:43:47 +00:00
|
|
|
const onPress = () => Navigation.navigate('MarkdownTableView', { renderRows, tableWidth: getTableWidth() });
|
2019-09-03 19:27:57 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<TouchableOpacity onPress={onPress}>
|
|
|
|
<ScrollView
|
|
|
|
contentContainerStyle={{ width: getTableWidth() }}
|
|
|
|
scrollEnabled={false}
|
|
|
|
showsVerticalScrollIndicator={false}
|
2019-12-11 23:01:12 +00:00
|
|
|
style={[styles.containerTable, { maxWidth: getTableWidth(), maxHeight: MAX_HEIGHT, borderColor: themes[theme].borderColor }]}
|
2019-09-03 19:27:57 +00:00
|
|
|
>
|
|
|
|
{renderRows(false)}
|
|
|
|
</ScrollView>
|
2019-12-11 23:01:12 +00:00
|
|
|
<Text style={[styles.textInfo, { color: themes[theme].auxiliaryText }]}>{I18n.t('Full_table')}</Text>
|
2019-09-03 19:27:57 +00:00
|
|
|
</TouchableOpacity>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
Table.propTypes = {
|
|
|
|
children: PropTypes.node.isRequired,
|
2019-12-11 23:01:12 +00:00
|
|
|
numColumns: PropTypes.number.isRequired,
|
|
|
|
theme: PropTypes.string
|
2019-09-03 19:27:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export default Table;
|