import { emojis } from '@components/Emojis' import EmojisContext from '@components/Emojis/Context' import Icon from '@components/Icon' import { MAX_MEDIA_ATTACHMENTS } from '@components/mediaSelector' import { useActionSheet } from '@expo/react-native-action-sheet' import { androidActionSheetStyles } from '@utils/helpers/androidActionSheetStyles' import layoutAnimation from '@utils/styles/layoutAnimation' import { useTheme } from '@utils/styles/ThemeManager' import React, { useContext } from 'react' import { useTranslation } from 'react-i18next' import { Keyboard, Pressable, StyleSheet, View } from 'react-native' import ComposeContext from '../utils/createContext' import chooseAndUploadAttachment from './Footer/addAttachment' const ComposeActions: React.FC = () => { const { showActionSheetWithOptions } = useActionSheet() const { composeState, composeDispatch } = useContext(ComposeContext) const { t } = useTranslation(['common', 'screenCompose']) const { colors } = useTheme() const attachmentColor = () => { if (composeState.poll.active) return colors.disabled if (composeState.attachments.uploads.length) { return colors.primaryDefault } else { return colors.secondary } } const attachmentOnPress = () => { if (composeState.poll.active) return if (composeState.attachments.uploads.length < MAX_MEDIA_ATTACHMENTS) { return chooseAndUploadAttachment({ composeDispatch, showActionSheetWithOptions }) } } const pollColor = () => { if (composeState.attachments.uploads.length) return colors.disabled if (composeState.poll.active) { return colors.primaryDefault } else { return colors.secondary } } const pollOnPress = () => { if (!composeState.attachments.uploads.length) { layoutAnimation() composeDispatch({ type: 'poll', payload: { ...composeState.poll, active: !composeState.poll.active } }) } if (composeState.poll.active) { composeState.textInputFocus.refs.text.current?.focus() } } const visibilityIcon = () => { switch (composeState.visibility) { case 'public': return 'Globe' case 'unlisted': return 'Unlock' case 'private': return 'Lock' case 'direct': return 'Mail' } } const visibilityOnPress = () => { if (!composeState.visibilityLock) { showActionSheetWithOptions( { title: t('screenCompose:content.root.actions.visibility.title'), options: [ t('screenCompose:content.root.actions.visibility.options.public'), t('screenCompose:content.root.actions.visibility.options.unlisted'), t('screenCompose:content.root.actions.visibility.options.private'), t('screenCompose:content.root.actions.visibility.options.direct'), t('common:buttons.cancel') ], cancelButtonIndex: 4, ...androidActionSheetStyles(colors) }, buttonIndex => { switch (buttonIndex) { case 0: composeDispatch({ type: 'visibility', payload: 'public' }) break case 1: composeDispatch({ type: 'visibility', payload: 'unlisted' }) break case 2: composeDispatch({ type: 'visibility', payload: 'private' }) break case 3: composeDispatch({ type: 'visibility', payload: 'direct' }) break } } ) } } const spoilerOnPress = () => { if (composeState.spoiler.active) { composeState.textInputFocus.refs.text.current?.focus() } layoutAnimation() composeDispatch({ type: 'spoiler', payload: { active: !composeState.spoiler.active } }) } const { emojisState, emojisDispatch } = useContext(EmojisContext) const emojiColor = () => { if (!emojis.current?.length) return colors.disabled if (emojisState.targetIndex !== -1) { return colors.primaryDefault } else { return colors.secondary } } const emojiOnPress = () => { if (emojisState.targetIndex === -1) { Keyboard.dismiss() const focusedPropsIndex = emojisState.inputProps?.findIndex(props => props.isFocused.current) if (focusedPropsIndex === -1) return emojisDispatch({ type: 'target', payload: focusedPropsIndex }) } else { emojisDispatch({ type: 'target', payload: -1 }) return } } return ( } /> } /> } /> } /> } /> ) } const styles = StyleSheet.create({ button: { flex: 1, justifyContent: 'center', alignItems: 'center', height: '100%' } }) export default ComposeActions