1
0
mirror of https://github.com/tooot-app/app synced 2025-06-05 22:19:13 +02:00

Upload GIF using Android keyboard

https://github.com/tooot-app/app/issues/261
This commit is contained in:
Zhiyuan Zheng
2022-05-08 12:15:16 +02:00
parent ed531d7371
commit 8c2004fe6c
9 changed files with 69 additions and 8 deletions

View File

@ -1,17 +1,25 @@
import CustomText from '@components/Text'
import { getInstanceConfigurationStatusMaxAttachments } from '@utils/slices/instancesSlice'
import { StyleConstants } from '@utils/styles/constants'
import { useTheme } from '@utils/styles/ThemeManager'
import React, { useContext } from 'react'
import { useTranslation } from 'react-i18next'
import { TextInput } from 'react-native'
import { Alert, TextInput } from 'react-native'
import { useSelector } from 'react-redux'
import formatText from '../../formatText'
import ComposeContext from '../../utils/createContext'
import { uploadAttachment } from '../Footer/addAttachment'
const ComposeTextInput: React.FC = () => {
const { composeState, composeDispatch } = useContext(ComposeContext)
const { t } = useTranslation('screenCompose')
const { colors, mode } = useTheme()
const maxAttachments = useSelector(
getInstanceConfigurationStatusMaxAttachments,
() => true
)
return (
<TextInput
keyboardAppearance={mode}
@ -54,6 +62,36 @@ const ComposeTextInput: React.FC = () => {
}}
ref={composeState.textInputFocus.refs.text}
scrollEnabled={false}
onImageChange={({ nativeEvent }) => {
if (composeState.attachments.uploads.length >= maxAttachments) {
Alert.alert(
t(
'content.root.header.textInput.keyboardImage.exceedMaximum.title'
),
undefined,
[
{
text: t(
'content.root.header.textInput.keyboardImage.exceedMaximum.OK'
),
style: 'default'
}
]
)
return
}
if (nativeEvent.linkUri) {
uploadAttachment({
composeDispatch,
imageInfo: {
uri: nativeEvent.linkUri,
type: 'image',
width: 100,
height: 100
}
})
}
}}
>
<CustomText>{composeState.text.formatted}</CustomText>
</TextInput>