UNPKG

2.01 kBJavaScriptView Raw
1import * as React from 'react';
2import PropTypes from 'prop-types';
3import { StyleSheet, Text, View } from 'react-native';
4import dayjs from 'dayjs';
5import Color from './Color';
6import { TIME_FORMAT } from './Constant';
7import { StylePropType } from './utils';
8import { useChatContext } from './GiftedChatContext';
9const { containerStyle } = StyleSheet.create({
10 containerStyle: {
11 marginLeft: 10,
12 marginRight: 10,
13 marginBottom: 5,
14 },
15});
16const { textStyle } = StyleSheet.create({
17 textStyle: {
18 fontSize: 10,
19 backgroundColor: 'transparent',
20 textAlign: 'right',
21 },
22});
23const styles = {
24 left: StyleSheet.create({
25 container: {
26 ...containerStyle,
27 },
28 text: {
29 color: Color.timeTextColor,
30 ...textStyle,
31 },
32 }),
33 right: StyleSheet.create({
34 container: {
35 ...containerStyle,
36 },
37 text: {
38 color: Color.white,
39 ...textStyle,
40 },
41 }),
42};
43export function Time({ position = 'left', containerStyle, currentMessage, timeFormat = TIME_FORMAT, timeTextStyle, }) {
44 const { getLocale } = useChatContext();
45 if (currentMessage == null) {
46 return null;
47 }
48 return (<View style={[
49 styles[position].container,
50 containerStyle && containerStyle[position],
51 ]}>
52 <Text style={[
53 styles[position].text,
54 timeTextStyle && timeTextStyle[position],
55 ]}>
56 {dayjs(currentMessage.createdAt).locale(getLocale()).format(timeFormat)}
57 </Text>
58 </View>);
59}
60Time.propTypes = {
61 position: PropTypes.oneOf(['left', 'right']),
62 currentMessage: PropTypes.object,
63 containerStyle: PropTypes.shape({
64 left: StylePropType,
65 right: StylePropType,
66 }),
67 timeFormat: PropTypes.string,
68 timeTextStyle: PropTypes.shape({
69 left: StylePropType,
70 right: StylePropType,
71 }),
72};
73//# sourceMappingURL=Time.js.map
\No newline at end of file