[Clipclops] Pending message style with layout animation (#3844)
* decrease group gap to 3 mins * pending style with layout animation * make pending state lighterzio/stable
parent
55f3df5596
commit
6a4199febb
|
@ -1,5 +1,5 @@
|
||||||
import React, {useCallback, useMemo} from 'react'
|
import React, {useCallback, useMemo, useRef} from 'react'
|
||||||
import {StyleProp, TextStyle, View} from 'react-native'
|
import {LayoutAnimation, StyleProp, TextStyle, View} from 'react-native'
|
||||||
import {ChatBskyConvoDefs} from '@atproto-labs/api'
|
import {ChatBskyConvoDefs} from '@atproto-labs/api'
|
||||||
import {msg} from '@lingui/macro'
|
import {msg} from '@lingui/macro'
|
||||||
import {useLingui} from '@lingui/react'
|
import {useLingui} from '@lingui/react'
|
||||||
|
@ -13,12 +13,14 @@ import {Text} from '#/components/Typography'
|
||||||
export function MessageItem({
|
export function MessageItem({
|
||||||
item,
|
item,
|
||||||
next,
|
next,
|
||||||
|
pending,
|
||||||
}: {
|
}: {
|
||||||
item: ChatBskyConvoDefs.MessageView
|
item: ChatBskyConvoDefs.MessageView
|
||||||
next:
|
next:
|
||||||
| ChatBskyConvoDefs.MessageView
|
| ChatBskyConvoDefs.MessageView
|
||||||
| ChatBskyConvoDefs.DeletedMessageView
|
| ChatBskyConvoDefs.DeletedMessageView
|
||||||
| null
|
| null
|
||||||
|
pending?: boolean
|
||||||
}) {
|
}) {
|
||||||
const t = useTheme()
|
const t = useTheme()
|
||||||
const {currentAccount} = useSession()
|
const {currentAccount} = useSession()
|
||||||
|
@ -35,20 +37,26 @@ export function MessageItem({
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// or, if there's a 10 minute gap between this message and the next
|
// or, if there's a 3 minute gap between this message and the next
|
||||||
if (ChatBskyConvoDefs.isMessageView(next)) {
|
if (ChatBskyConvoDefs.isMessageView(next)) {
|
||||||
const thisDate = new Date(item.sentAt)
|
const thisDate = new Date(item.sentAt)
|
||||||
const nextDate = new Date(next.sentAt)
|
const nextDate = new Date(next.sentAt)
|
||||||
|
|
||||||
const diff = nextDate.getTime() - thisDate.getTime()
|
const diff = nextDate.getTime() - thisDate.getTime()
|
||||||
|
|
||||||
// 10 minutes
|
// 3 minutes
|
||||||
return diff > 10 * 60 * 1000
|
return diff > 3 * 60 * 1000
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}, [item, next, isFromSelf, isNextFromSelf])
|
}, [item, next, isFromSelf, isNextFromSelf])
|
||||||
|
|
||||||
|
const lastInGroupRef = useRef(isLastInGroup)
|
||||||
|
if (lastInGroupRef.current !== isLastInGroup) {
|
||||||
|
LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut)
|
||||||
|
lastInGroupRef.current = isLastInGroup
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View>
|
<View>
|
||||||
<ActionsWrapper isFromSelf={isFromSelf} message={item}>
|
<ActionsWrapper isFromSelf={isFromSelf} message={item}>
|
||||||
|
@ -60,7 +68,9 @@ export function MessageItem({
|
||||||
a.rounded_md,
|
a.rounded_md,
|
||||||
{
|
{
|
||||||
backgroundColor: isFromSelf
|
backgroundColor: isFromSelf
|
||||||
? t.palette.primary_500
|
? pending
|
||||||
|
? t.palette.primary_200
|
||||||
|
: t.palette.primary_500
|
||||||
: t.palette.contrast_50,
|
: t.palette.contrast_50,
|
||||||
borderRadius: 17,
|
borderRadius: 17,
|
||||||
},
|
},
|
||||||
|
|
|
@ -57,7 +57,13 @@ function RetryButton({onPress}: {onPress: () => unknown}) {
|
||||||
|
|
||||||
function renderItem({item}: {item: ConvoItem}) {
|
function renderItem({item}: {item: ConvoItem}) {
|
||||||
if (item.type === 'message' || item.type === 'pending-message') {
|
if (item.type === 'message' || item.type === 'pending-message') {
|
||||||
return <MessageItem item={item.message} next={item.nextMessage} />
|
return (
|
||||||
|
<MessageItem
|
||||||
|
item={item.message}
|
||||||
|
next={item.nextMessage}
|
||||||
|
pending={item.type === 'pending-message'}
|
||||||
|
/>
|
||||||
|
)
|
||||||
} else if (item.type === 'deleted-message') {
|
} else if (item.type === 'deleted-message') {
|
||||||
return <Text>Deleted message</Text>
|
return <Text>Deleted message</Text>
|
||||||
} else if (item.type === 'pending-retry') {
|
} else if (item.type === 'pending-retry') {
|
||||||
|
|
Loading…
Reference in New Issue