2022-08-09 00:44:56 +02:00
|
|
|
import { displayMessage } from '@components/Message'
|
|
|
|
import Clipboard from '@react-native-clipboard/clipboard'
|
|
|
|
import { useTheme } from '@utils/styles/ThemeManager'
|
2022-06-06 22:49:43 +02:00
|
|
|
import { useTranslation } from 'react-i18next'
|
|
|
|
import { Platform, Share } from 'react-native'
|
|
|
|
|
2022-12-03 01:08:38 +01:00
|
|
|
const menuShare = (
|
|
|
|
params:
|
|
|
|
| {
|
|
|
|
visibility?: Mastodon.Status['visibility']
|
|
|
|
copiableContent?: React.MutableRefObject<{
|
|
|
|
content?: string | undefined
|
|
|
|
complete: boolean
|
|
|
|
}>
|
|
|
|
type: 'status'
|
|
|
|
url?: string
|
|
|
|
}
|
|
|
|
| {
|
|
|
|
type: 'account'
|
|
|
|
url: string
|
|
|
|
}
|
|
|
|
): ContextMenu[][] => {
|
|
|
|
if (params.type === 'status' && params.visibility === 'direct') return []
|
2022-06-06 22:49:43 +02:00
|
|
|
|
2022-08-09 00:44:56 +02:00
|
|
|
const { theme } = useTheme()
|
2022-06-06 22:49:43 +02:00
|
|
|
const { t } = useTranslation('componentContextMenu')
|
|
|
|
|
2022-12-03 01:08:38 +01:00
|
|
|
const menus: ContextMenu[][] = [[]]
|
2022-06-06 22:49:43 +02:00
|
|
|
|
2022-12-03 01:08:38 +01:00
|
|
|
if (params.url) {
|
|
|
|
const url = params.url
|
|
|
|
menus[0].push({
|
|
|
|
key: 'share',
|
|
|
|
item: {
|
|
|
|
onSelect: () => {
|
|
|
|
switch (Platform.OS) {
|
|
|
|
case 'ios':
|
|
|
|
Share.share({ url })
|
|
|
|
break
|
|
|
|
case 'android':
|
|
|
|
Share.share({ message: url })
|
|
|
|
break
|
|
|
|
}
|
|
|
|
},
|
|
|
|
disabled: false,
|
|
|
|
destructive: false,
|
|
|
|
hidden: false
|
|
|
|
},
|
|
|
|
title: t(`share.${params.type}.action`),
|
|
|
|
icon: 'square.and.arrow.up'
|
|
|
|
})
|
2022-06-06 22:49:43 +02:00
|
|
|
}
|
2022-12-03 01:08:38 +01:00
|
|
|
if (params.type === 'status' && Platform.OS === 'ios')
|
|
|
|
menus[0].push({
|
|
|
|
key: 'copy',
|
|
|
|
item: {
|
|
|
|
onSelect: () => {
|
|
|
|
Clipboard.setString(params.copiableContent?.current.content || '')
|
|
|
|
displayMessage({
|
|
|
|
theme,
|
|
|
|
type: 'success',
|
|
|
|
message: t(`copy.succeed`)
|
|
|
|
})
|
|
|
|
},
|
|
|
|
disabled: false,
|
|
|
|
destructive: false,
|
|
|
|
hidden: !params.copiableContent?.current.content?.length
|
|
|
|
},
|
|
|
|
title: t('copy.action'),
|
|
|
|
icon: 'doc.on.doc'
|
|
|
|
})
|
|
|
|
|
|
|
|
return menus
|
2022-06-06 22:49:43 +02:00
|
|
|
}
|
|
|
|
|
2022-12-03 01:08:38 +01:00
|
|
|
export default menuShare
|