Update styling & add onClose to StatsTable to make it modal

This commit is contained in:
MariaZ
2022-09-19 21:14:06 +02:00
parent 0c6c706274
commit 5a0321c5e5
+39 -14
View File
@@ -1,12 +1,13 @@
import React from 'react' import React from 'react'
import { FlatList, StyleSheet, View } from 'react-native' import { Dimensions, FlatList, StyleSheet, View } from 'react-native'
import PropTypes from 'prop-types' import PropTypes from 'prop-types'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import AppText from './app-text' import AppText from './app-text'
import CloseIcon from './close-icon'
import cycleModule from '../../lib/cycle' import cycleModule from '../../lib/cycle'
import { Spacing, Typography, Colors } from '../../styles' import { Sizes, Spacing, Typography, Colors } from '../../styles'
import { humanizeDate } from '../helpers/format-date' import { humanizeDate } from '../helpers/format-date'
const Item = ({ data }) => { const Item = ({ data }) => {
@@ -35,13 +36,17 @@ Item.propTypes = {
data: PropTypes.object.isRequired, data: PropTypes.object.isRequired,
} }
const StatsTable = () => { const StatsTable = ({ onClose }) => {
const renderItem = ({ item }) => <Item data={item} /> const renderItem = ({ item }) => <Item data={item} />
const data = cycleModule().getStats() const data = cycleModule().getStats()
if (!data || data.length === 0) return false if (!data || data.length === 0) return false
return ( return (
<View style={styles.modalContainer}>
<View style={styles.headerContainer}>
<CloseIcon onClose={onClose} />
</View>
<FlatList <FlatList
data={data} data={data}
renderItem={renderItem} renderItem={renderItem}
@@ -52,9 +57,14 @@ const StatsTable = () => {
stickyHeaderIndices={[0]} stickyHeaderIndices={[0]}
contentContainerStyle={styles.container} contentContainerStyle={styles.container}
/> />
</View>
) )
} }
StatsTable.propTypes = {
onClose: PropTypes.func,
}
const ItemDivider = () => <View style={styles.divider} /> const ItemDivider = () => <View style={styles.divider} />
const FlatListHeader = () => ( const FlatListHeader = () => (
@@ -72,6 +82,17 @@ const FlatListHeader = () => (
) )
const styles = StyleSheet.create({ const styles = StyleSheet.create({
accentCell: {
flex: 3,
justifyContent: 'center',
},
cell: {
flex: 2,
justifyContent: 'center',
},
container: {
paddingHorizontal: Spacing.base,
},
divider: { divider: {
height: 1, height: 1,
width: '100%', width: '100%',
@@ -81,27 +102,31 @@ const styles = StyleSheet.create({
...Typography.accentOrange, ...Typography.accentOrange,
paddingVertical: Spacing.small, paddingVertical: Spacing.small,
}, },
headerContainer: {
flexDirection: 'row',
justifyContent: 'flex-end',
paddingTop: Spacing.base,
paddingRight: Spacing.base,
},
headerDivider: { headerDivider: {
borderBottomColor: Colors.purple, borderBottomColor: Colors.purple,
borderBottomWidth: 2, borderBottomWidth: 2,
}, },
modalContainer: {
alignSelf: 'center',
backgroundColor: Colors.turquoiseLight,
marginTop: Sizes.huge * 2,
maxHeight: Dimensions.get('window').height * 0.7,
minHeight: '40%',
position: 'absolute',
width: '100%',
},
row: { row: {
flexDirection: 'row', flexDirection: 'row',
justifyContent: 'space-between', justifyContent: 'space-between',
paddingVertical: Spacing.tiny, paddingVertical: Spacing.tiny,
backgroundColor: Colors.turquoiseLight, backgroundColor: Colors.turquoiseLight,
}, },
cell: {
flex: 2,
justifyContent: 'center',
},
accentCell: {
flex: 3,
justifyContent: 'center',
},
container: {
paddingHorizontal: Spacing.base,
},
}) })
export default StatsTable export default StatsTable