show message info on press
This commit is contained in:
@@ -1,5 +1,11 @@
|
|||||||
import React, {useCallback, useMemo, useRef} from 'react'
|
import React, {useCallback, useMemo, useRef, useState} from 'react'
|
||||||
import {LayoutAnimation, StyleProp, TextStyle, View} from 'react-native'
|
import {
|
||||||
|
LayoutAnimation,
|
||||||
|
Pressable,
|
||||||
|
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'
|
||||||
@@ -24,14 +30,24 @@ export let MessageItem = ({
|
|||||||
}): React.ReactNode => {
|
}): React.ReactNode => {
|
||||||
const t = useTheme()
|
const t = useTheme()
|
||||||
const {currentAccount} = useSession()
|
const {currentAccount} = useSession()
|
||||||
|
const [hasBeenPressed, setHasBeenPressed] = useState(false)
|
||||||
|
|
||||||
const isFromSelf = item.sender?.did === currentAccount?.did
|
const isFromSelf = item.sender?.did === currentAccount?.did
|
||||||
|
|
||||||
|
const handlePress = useCallback(() => {
|
||||||
|
setHasBeenPressed(p => !p)
|
||||||
|
}, [])
|
||||||
|
|
||||||
const isNextFromSelf =
|
const isNextFromSelf =
|
||||||
ChatBskyConvoDefs.isMessageView(next) &&
|
ChatBskyConvoDefs.isMessageView(next) &&
|
||||||
next.sender?.did === currentAccount?.did
|
next.sender?.did === currentAccount?.did
|
||||||
|
|
||||||
const isLastInGroup = useMemo(() => {
|
const isLastInGroup = useMemo(() => {
|
||||||
|
// override showing date if the message has been pressed
|
||||||
|
if (hasBeenPressed) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
// TODO this means it's a placeholder. Let's figure out the right way to do this though!
|
// TODO this means it's a placeholder. Let's figure out the right way to do this though!
|
||||||
if (item.id.length > 13) {
|
if (item.id.length > 13) {
|
||||||
return false
|
return false
|
||||||
@@ -54,7 +70,14 @@ export let MessageItem = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}, [item, next, isFromSelf, isNextFromSelf])
|
}, [
|
||||||
|
hasBeenPressed,
|
||||||
|
item.id.length,
|
||||||
|
item.sentAt,
|
||||||
|
isFromSelf,
|
||||||
|
isNextFromSelf,
|
||||||
|
next,
|
||||||
|
])
|
||||||
|
|
||||||
const lastInGroupRef = useRef(isLastInGroup)
|
const lastInGroupRef = useRef(isLastInGroup)
|
||||||
if (lastInGroupRef.current !== isLastInGroup) {
|
if (lastInGroupRef.current !== isLastInGroup) {
|
||||||
@@ -68,6 +91,10 @@ export let MessageItem = ({
|
|||||||
return (
|
return (
|
||||||
<View>
|
<View>
|
||||||
<ActionsWrapper isFromSelf={isFromSelf} message={item}>
|
<ActionsWrapper isFromSelf={isFromSelf} message={item}>
|
||||||
|
<Pressable
|
||||||
|
accessibilityRole="none"
|
||||||
|
accessibilityHint="Show message info"
|
||||||
|
onPress={handlePress}>
|
||||||
<View
|
<View
|
||||||
style={[
|
style={[
|
||||||
a.py_sm,
|
a.py_sm,
|
||||||
@@ -97,6 +124,7 @@ export let MessageItem = ({
|
|||||||
{item.text}
|
{item.text}
|
||||||
</Text>
|
</Text>
|
||||||
</View>
|
</View>
|
||||||
|
</Pressable>
|
||||||
</ActionsWrapper>
|
</ActionsWrapper>
|
||||||
<MessageItemMetadata
|
<MessageItemMetadata
|
||||||
message={item}
|
message={item}
|
||||||
|
|||||||
Reference in New Issue
Block a user