tooot/src/screens/Shared/Compose/EditAttachment/Root.tsx

113 lines
3.4 KiB
TypeScript
Raw Normal View History

2020-12-30 00:56:25 +01:00
import AttachmentVideo from '@components/Timelines/Timeline/Shared/Attachment/Video'
import { StyleConstants } from '@utils/styles/constants'
import { useTheme } from '@utils/styles/ThemeManager'
import React, {
Dispatch,
MutableRefObject,
SetStateAction,
useContext,
useMemo
} from 'react'
import { ScrollView, StyleSheet, Text, TextInput, View } from 'react-native'
2021-01-01 17:52:14 +01:00
import ComposeContext from '../utils/createContext'
2020-12-30 00:56:25 +01:00
import ComposeEditAttachmentImage from './Image'
export interface Props {
index: number
focus: MutableRefObject<{
x: number
y: number
}>
altText: string | undefined
setAltText: Dispatch<SetStateAction<string | undefined>>
}
const ComposeEditAttachmentRoot: React.FC<Props> = ({
index,
focus,
altText,
setAltText
}) => {
const { theme } = useTheme()
const { composeState } = useContext(ComposeContext)
const theAttachment = composeState.attachments.uploads[index].remote!
const mediaDisplay = useMemo(() => {
switch (theAttachment.type) {
case 'image':
return <ComposeEditAttachmentImage index={index} focus={focus} />
case 'video':
case 'gifv':
2021-01-04 14:55:34 +01:00
const video = composeState.attachments.uploads[index]
2020-12-30 00:56:25 +01:00
return (
<AttachmentVideo
sensitiveShown={false}
2021-01-04 14:55:34 +01:00
video={
video.local
? ({
url: video.local.uri,
preview_url: video.local.local_thumbnail,
blurhash: video.remote?.blurhash
} as Mastodon.AttachmentVideo)
: (video.remote! as Mastodon.AttachmentVideo)
}
2020-12-30 00:56:25 +01:00
/>
)
}
return null
}, [])
return (
<ScrollView>
{mediaDisplay}
<View style={styles.altTextContainer}>
<Text style={[styles.altTextInputHeading, { color: theme.primary }]}>
</Text>
<TextInput
style={[styles.altTextInput, { borderColor: theme.border }]}
autoCapitalize='none'
autoCorrect={false}
maxLength={1500}
multiline
onChangeText={e => setAltText(e)}
placeholder={
'你可以为附件添加文字说明,以便更多人可以查看他们(包括视力障碍或视力受损人士)。\n\n优质的描述应该简洁明了但要准确地描述照片中的内容以便用户理解其含义。'
}
placeholderTextColor={theme.secondary}
scrollEnabled
value={altText}
/>
<Text style={[styles.altTextLength, { color: theme.secondary }]}>
{altText?.length || 0} / 1500
</Text>
</View>
</ScrollView>
)
}
const styles = StyleSheet.create({
altTextContainer: { padding: StyleConstants.Spacing.Global.PagePadding },
altTextInputHeading: {
...StyleConstants.FontStyle.M,
fontWeight: StyleConstants.Font.Weight.Bold
},
altTextInput: {
height: 200,
...StyleConstants.FontStyle.M,
marginTop: StyleConstants.Spacing.M,
marginBottom: StyleConstants.Spacing.S,
padding: StyleConstants.Spacing.Global.PagePadding,
paddingTop: StyleConstants.Spacing.S * 1.5,
borderWidth: StyleSheet.hairlineWidth
},
altTextLength: {
textAlign: 'right',
marginRight: StyleConstants.Spacing.S,
...StyleConstants.FontStyle.S,
marginBottom: StyleConstants.Spacing.M
}
})
export default ComposeEditAttachmentRoot