weg dropdown menu
This commit is contained in:
@@ -7,22 +7,26 @@ import Animated, {
|
|||||||
useSharedValue,
|
useSharedValue,
|
||||||
withTiming,
|
withTiming,
|
||||||
} from 'react-native-reanimated'
|
} from 'react-native-reanimated'
|
||||||
|
import {ChatBskyConvoDefs} from '@atproto-labs/api'
|
||||||
|
|
||||||
import {useHaptics} from 'lib/haptics'
|
import {useHaptics} from 'lib/haptics'
|
||||||
import {atoms as a} from '#/alf'
|
import {atoms as a} from '#/alf'
|
||||||
|
import {MessageMenu} from '#/components/dms/MessageMenu'
|
||||||
|
import {useMenuControl} from '#/components/Menu'
|
||||||
|
|
||||||
const AnimatedPressable = Animated.createAnimatedComponent(Pressable)
|
const AnimatedPressable = Animated.createAnimatedComponent(Pressable)
|
||||||
|
|
||||||
export const ActionsWrapper = function GrowWrapper({
|
export const ActionsWrapper = function GrowWrapper({
|
||||||
|
message,
|
||||||
isFromSelf,
|
isFromSelf,
|
||||||
onOpenMenu,
|
|
||||||
children,
|
children,
|
||||||
}: {
|
}: {
|
||||||
|
message: ChatBskyConvoDefs.MessageView
|
||||||
isFromSelf: boolean
|
isFromSelf: boolean
|
||||||
onOpenMenu: () => unknown
|
|
||||||
children: React.ReactNode
|
children: React.ReactNode
|
||||||
}) {
|
}) {
|
||||||
const playHaptic = useHaptics()
|
const playHaptic = useHaptics()
|
||||||
|
const menuControl = useMenuControl()
|
||||||
|
|
||||||
const scale = useSharedValue(1)
|
const scale = useSharedValue(1)
|
||||||
const animationDidComplete = useSharedValue(false)
|
const animationDidComplete = useSharedValue(false)
|
||||||
@@ -45,11 +49,11 @@ export const ActionsWrapper = function GrowWrapper({
|
|||||||
if (!finished) return
|
if (!finished) return
|
||||||
animationDidComplete.value = true
|
animationDidComplete.value = true
|
||||||
runOnJS(playHaptic)()
|
runOnJS(playHaptic)()
|
||||||
runOnJS(onOpenMenu)()
|
runOnJS(menuControl.open)()
|
||||||
|
|
||||||
shrink()
|
shrink()
|
||||||
})
|
})
|
||||||
}, [scale, animationDidComplete, playHaptic, onOpenMenu, shrink])
|
}, [scale, animationDidComplete, playHaptic, shrink, menuControl])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View
|
<View
|
||||||
@@ -66,6 +70,7 @@ export const ActionsWrapper = function GrowWrapper({
|
|||||||
onTouchEnd={shrink}>
|
onTouchEnd={shrink}>
|
||||||
{children}
|
{children}
|
||||||
</AnimatedPressable>
|
</AnimatedPressable>
|
||||||
|
<MessageMenu message={message} control={menuControl} hideTrigger={true} />
|
||||||
</View>
|
</View>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,75 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import {View} from 'react-native'
|
import {View} from 'react-native'
|
||||||
|
import {ChatBskyConvoDefs} from '@atproto-labs/api'
|
||||||
|
|
||||||
|
import {atoms as a} from '#/alf'
|
||||||
|
import {MessageMenu} from '#/components/dms/MessageMenu'
|
||||||
|
import {useMenuControl} from '#/components/Menu'
|
||||||
|
import {Text} from '#/components/Typography'
|
||||||
|
|
||||||
export function ActionsWrapper({
|
export function ActionsWrapper({
|
||||||
|
message,
|
||||||
isFromSelf,
|
isFromSelf,
|
||||||
onOpenMenu,
|
|
||||||
children,
|
children,
|
||||||
}: {
|
}: {
|
||||||
|
message: ChatBskyConvoDefs.MessageView
|
||||||
isFromSelf: boolean
|
isFromSelf: boolean
|
||||||
onOpenMenu: () => unknown
|
|
||||||
children: React.ReactNode
|
children: React.ReactNode
|
||||||
}) {
|
}) {
|
||||||
return <View>{children}</View>
|
const [showActions, setShowActions] = React.useState(false)
|
||||||
|
|
||||||
|
const menuControl = useMenuControl()
|
||||||
|
|
||||||
|
const onMouseEnter = React.useCallback(() => {
|
||||||
|
setShowActions(true)
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
const onMouseLeave = React.useCallback(() => {
|
||||||
|
setShowActions(false)
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
return (
|
||||||
|
<View
|
||||||
|
onMouseEnter={onMouseEnter}
|
||||||
|
onMouseLeave={onMouseLeave}
|
||||||
|
style={[a.flex_1, a.flex_row]}>
|
||||||
|
{isFromSelf && (
|
||||||
|
<View
|
||||||
|
style={[
|
||||||
|
{
|
||||||
|
width: 100,
|
||||||
|
marginLeft: 'auto',
|
||||||
|
alignItems: 'flex-end',
|
||||||
|
},
|
||||||
|
]}>
|
||||||
|
<ActionBar control={menuControl} message={message} />
|
||||||
|
</View>
|
||||||
|
)}
|
||||||
|
<View
|
||||||
|
style={[
|
||||||
|
{
|
||||||
|
maxWidth: '65%',
|
||||||
|
},
|
||||||
|
]}>
|
||||||
|
{children}
|
||||||
|
</View>
|
||||||
|
{!isFromSelf && (
|
||||||
|
<View style={[{width: 100}]}>{showActions && <Text>Hello</Text>}</View>
|
||||||
|
)}
|
||||||
|
</View>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function ActionBar({
|
||||||
|
control,
|
||||||
|
message,
|
||||||
|
}: {
|
||||||
|
control: Menu.MenuControlProps
|
||||||
|
message: ChatBskyConvoDefs.MessageView
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<View style={[a.flex_row, a.mx_md]}>
|
||||||
|
<MessageMenu message={message} control={control} />
|
||||||
|
</View>
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,8 +6,6 @@ import {useSession} from 'state/session'
|
|||||||
import {atoms as a, useTheme} from '#/alf'
|
import {atoms as a, useTheme} from '#/alf'
|
||||||
import {ActionsWrapper} from '#/components/dms/ActionsWrapper'
|
import {ActionsWrapper} from '#/components/dms/ActionsWrapper'
|
||||||
import {MessageItemMetadata} from '#/components/dms/MesageItemMetadata'
|
import {MessageItemMetadata} from '#/components/dms/MesageItemMetadata'
|
||||||
import {MessageMenu} from '#/components/dms/MessageMenu'
|
|
||||||
import {useMenuControl} from '#/components/Menu'
|
|
||||||
import {Text} from '#/components/Typography'
|
import {Text} from '#/components/Typography'
|
||||||
|
|
||||||
export function MessageItem({
|
export function MessageItem({
|
||||||
@@ -23,8 +21,6 @@ export function MessageItem({
|
|||||||
const t = useTheme()
|
const t = useTheme()
|
||||||
const {currentAccount} = useSession()
|
const {currentAccount} = useSession()
|
||||||
|
|
||||||
const menuControl = useMenuControl()
|
|
||||||
|
|
||||||
const isFromSelf = item.sender?.did === currentAccount?.did
|
const isFromSelf = item.sender?.did === currentAccount?.did
|
||||||
|
|
||||||
const isNextFromSelf =
|
const isNextFromSelf =
|
||||||
@@ -51,12 +47,8 @@ export function MessageItem({
|
|||||||
return true
|
return true
|
||||||
}, [item, next, isFromSelf, isNextFromSelf])
|
}, [item, next, isFromSelf, isNextFromSelf])
|
||||||
|
|
||||||
const onOpenMenu = React.useCallback(() => {
|
|
||||||
menuControl.open()
|
|
||||||
}, [menuControl])
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ActionsWrapper onOpenMenu={onOpenMenu} isFromSelf={isFromSelf}>
|
<ActionsWrapper isFromSelf={isFromSelf} message={item}>
|
||||||
<View
|
<View
|
||||||
style={[
|
style={[
|
||||||
a.py_sm,
|
a.py_sm,
|
||||||
@@ -87,7 +79,6 @@ export function MessageItem({
|
|||||||
isLastInGroup={isLastInGroup}
|
isLastInGroup={isLastInGroup}
|
||||||
style={isFromSelf ? a.text_right : a.text_left}
|
style={isFromSelf ? a.text_right : a.text_left}
|
||||||
/>
|
/>
|
||||||
<MessageMenu message={item} control={menuControl} />
|
|
||||||
</ActionsWrapper>
|
</ActionsWrapper>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
|
import {Pressable} 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'
|
||||||
|
|
||||||
import {useSession} from 'state/session'
|
import {useSession} from 'state/session'
|
||||||
|
import {atoms as a, useTheme} from '#/alf'
|
||||||
|
import {DotGrid_Stroke2_Corner0_Rounded as DotsHorizontal} from '#/components/icons/DotGrid'
|
||||||
import {Trash_Stroke2_Corner0_Rounded as Trash} from '#/components/icons/Trash'
|
import {Trash_Stroke2_Corner0_Rounded as Trash} from '#/components/icons/Trash'
|
||||||
import {Warning_Stroke2_Corner0_Rounded as Warning} from '#/components/icons/Warning'
|
import {Warning_Stroke2_Corner0_Rounded as Warning} from '#/components/icons/Warning'
|
||||||
import * as Menu from '#/components/Menu'
|
import * as Menu from '#/components/Menu'
|
||||||
@@ -13,11 +16,14 @@ import {usePromptControl} from '#/components/Prompt'
|
|||||||
export let MessageMenu = ({
|
export let MessageMenu = ({
|
||||||
message,
|
message,
|
||||||
control,
|
control,
|
||||||
|
hideTrigger,
|
||||||
}: {
|
}: {
|
||||||
|
hideTrigger?: boolean
|
||||||
message: ChatBskyConvoDefs.MessageView
|
message: ChatBskyConvoDefs.MessageView
|
||||||
control: Menu.MenuControlProps
|
control: Menu.MenuControlProps
|
||||||
}): React.ReactNode => {
|
}): React.ReactNode => {
|
||||||
const {_} = useLingui()
|
const {_} = useLingui()
|
||||||
|
const t = useTheme()
|
||||||
const {currentAccount} = useSession()
|
const {currentAccount} = useSession()
|
||||||
const deleteControl = usePromptControl()
|
const deleteControl = usePromptControl()
|
||||||
|
|
||||||
@@ -34,6 +40,24 @@ export let MessageMenu = ({
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Menu.Root control={control}>
|
<Menu.Root control={control}>
|
||||||
|
{!hideTrigger && (
|
||||||
|
<Menu.Trigger label={_(msg`Chat settings`)}>
|
||||||
|
{({props, state}) => (
|
||||||
|
<Pressable
|
||||||
|
{...props}
|
||||||
|
style={[
|
||||||
|
a.p_sm,
|
||||||
|
a.rounded_full,
|
||||||
|
(state.hovered || state.pressed) && t.atoms.bg_contrast_25,
|
||||||
|
// make sure pfp is in the middle
|
||||||
|
{marginLeft: -10},
|
||||||
|
]}>
|
||||||
|
<DotsHorizontal size="sm" style={t.atoms.text} />
|
||||||
|
</Pressable>
|
||||||
|
)}
|
||||||
|
</Menu.Trigger>
|
||||||
|
)}
|
||||||
|
|
||||||
<Menu.Outer>
|
<Menu.Outer>
|
||||||
<Menu.Group>
|
<Menu.Group>
|
||||||
<Menu.Item
|
<Menu.Item
|
||||||
|
|||||||
Reference in New Issue
Block a user