2022-06-06 22:49:43 +02:00
|
|
|
import analytics from '@components/analytics'
|
|
|
|
import { useTranslation } from 'react-i18next'
|
|
|
|
import { Platform, Share } from 'react-native'
|
|
|
|
import { ContextMenuAction } from 'react-native-context-menu-view'
|
|
|
|
|
|
|
|
export interface Props {
|
2022-06-07 20:07:14 +02:00
|
|
|
actions: ContextMenuAction[]
|
|
|
|
type: 'status' | 'account'
|
|
|
|
url: string
|
2022-06-06 22:49:43 +02:00
|
|
|
}
|
|
|
|
|
2022-06-07 20:07:14 +02:00
|
|
|
const contextMenuShare = ({ actions, type, url }: Props) => {
|
2022-06-06 22:49:43 +02:00
|
|
|
const { t } = useTranslation('componentContextMenu')
|
|
|
|
|
2022-06-07 20:07:14 +02:00
|
|
|
actions.push({
|
|
|
|
id: 'share',
|
|
|
|
title: t(`share.${type}.action`),
|
|
|
|
systemIcon: 'square.and.arrow.up'
|
|
|
|
})
|
2022-06-06 22:49:43 +02:00
|
|
|
|
|
|
|
return (id: string) => {
|
|
|
|
switch (id) {
|
|
|
|
case 'share':
|
|
|
|
analytics('timeline_shared_headeractions_share_press')
|
|
|
|
switch (Platform.OS) {
|
|
|
|
case 'ios':
|
|
|
|
Share.share({ url })
|
|
|
|
break
|
|
|
|
case 'android':
|
|
|
|
Share.share({ message: url })
|
|
|
|
break
|
|
|
|
}
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default contextMenuShare
|