import React, { useState, useEffect } from 'react' import { FlatList, StyleSheet, View } from 'react-native' import PropTypes from 'prop-types' import { useTranslation } from 'react-i18next' import AppModal from '../common/app-modal' import AppText from '../common/app-text' import cycleModule from '../../lib/cycle' import { Spacing, Typography, Colors } from '../../styles' import { humanizeDate } from '../helpers/format-date' import LoadingMoreView from '../chart/loading-more' const Item = ({ data }) => { const { t } = useTranslation(null, { keyPrefix: 'plurals' }) if (!data) return false const { date, cycleLength, bleedingLength } = data return ( {humanizeDate(date)} {t('day', { count: cycleLength })} {t('day', { count: bleedingLength })} ) } Item.propTypes = { data: PropTypes.object.isRequired, } const PeriodDetailsModal = ({ onClose }) => { const renderItem = ({ item }) => const data = cycleModule().getStats() const [endReached, setEndReached] = useState(false) if (!data || data.length === 0) return false // const ITEM_HEIGHT = 50; // const getItemLayout = (data, index) => ({ // length: ITEM_HEIGHT, // offset: ITEM_HEIGHT * index, // index // }); return ( item.date} ItemSeparatorComponent={ItemDivider} ListHeaderComponent={FlatListHeader} ListHeaderComponentStyle={styles.headerDivider} stickyHeaderIndices={[0]} windowSize={4} contentContainerStyle={styles.container} onEndReached={() => setEndReached(true)} onEndReachedThreshold={0.1} ListFooterComponent={} updateCellsBatchingPeriod={100} /> ) } PeriodDetailsModal.propTypes = { onClose: PropTypes.func, } const ItemDivider = () => const FlatListHeader = () => ( {'Cycle Start'} {'Cycle Length'} {'Bleeding'} ) const styles = StyleSheet.create({ divider: { height: 1, width: '100%', backgroundColor: Colors.grey, }, header: { ...Typography.accentOrange, paddingVertical: Spacing.small, }, headerDivider: { borderBottomColor: Colors.purple, borderBottomWidth: 2, }, row: { flexDirection: 'row', justifyContent: 'space-between', paddingVertical: Spacing.tiny, backgroundColor: 'white', }, cell: { flex: 2, justifyContent: 'center', }, accentCell: { flex: 3, justifyContent: 'center', }, container: { minHeight: '40%', minWidth: '95%', paddingHorizontal: Spacing.base, }, }) export default PeriodDetailsModal