import * as React from 'react' import PropTypes from 'prop-types' import { StyleSheet, Text, View, StyleProp, ViewStyle, TextStyle, TextProps, } from 'react-native' import dayjs from 'dayjs' import Color from './Color' import { StylePropType, isSameDay } from './utils' import { DATE_FORMAT } from './Constant' import { IMessage } from './Models' import { useChatContext } from './GiftedChatContext' const styles = StyleSheet.create({ container: { alignItems: 'center', justifyContent: 'center', marginTop: 5, marginBottom: 10, }, text: { backgroundColor: Color.backgroundTransparent, color: Color.defaultColor, fontSize: 12, fontWeight: '600', }, }) export interface DayProps { currentMessage?: TMessage nextMessage?: TMessage previousMessage?: TMessage containerStyle?: StyleProp wrapperStyle?: StyleProp textStyle?: StyleProp textProps?: TextProps dateFormat?: string inverted?: boolean } export function Day ({ dateFormat = DATE_FORMAT, currentMessage, previousMessage, containerStyle, wrapperStyle, textStyle, }: DayProps) { const { getLocale } = useChatContext() if (currentMessage == null || isSameDay(currentMessage, previousMessage)) return null return ( {dayjs(currentMessage.createdAt) .locale(getLocale()) .format(dateFormat)} ) } Day.propTypes = { currentMessage: PropTypes.object, previousMessage: PropTypes.object, nextMessage: PropTypes.object, inverted: PropTypes.bool, containerStyle: StylePropType, wrapperStyle: StylePropType, textStyle: StylePropType, dateFormat: PropTypes.string, }