Spoiler now supports emoji as well

This commit is contained in:
xmflsct 2022-09-19 22:01:13 +02:00
parent 2df23a8a2e
commit b44370d3ec
5 changed files with 37 additions and 37 deletions

View File

@ -362,8 +362,20 @@ const ScreenCompose: React.FC<RootStackScreenProps<'Screen-Compose'>> = ({
composeState.text.selection, composeState.text.selection,
selection => composeDispatch({ type: 'text', payload: { selection } }) selection => composeDispatch({ type: 'text', payload: { selection } })
], ],
isFocused: useRef<boolean>(composeState.textInputFocus.current === 'text'), isFocused: composeState.textInputFocus.isFocused.text,
maxLength: maxTootChars maxLength: maxTootChars - (composeState.spoiler.active ? composeState.spoiler.count : 0)
},
{
value: [
composeState.spoiler.raw,
content => formatText({ textInput: 'spoiler', composeDispatch, content })
],
selection: [
composeState.spoiler.selection,
selection => composeDispatch({ type: 'spoiler', payload: { selection } })
],
isFocused: composeState.textInputFocus.isFocused.spoiler,
maxLength: maxTootChars - composeState.text.count
} }
] ]

View File

@ -16,14 +16,8 @@ const ComposeSpoilerInput: React.FC = () => {
const { colors, mode } = useTheme() const { colors, mode } = useTheme()
const adaptiveFontsize = useSelector(getSettingsFontsize) const adaptiveFontsize = useSelector(getSettingsFontsize)
const adaptedFontsize = adaptiveScale( const adaptedFontsize = adaptiveScale(StyleConstants.Font.Size.M, adaptiveFontsize)
StyleConstants.Font.Size.M, const adaptedLineheight = adaptiveScale(StyleConstants.Font.LineHeight.M, adaptiveFontsize)
adaptiveFontsize
)
const adaptedLineheight = adaptiveScale(
StyleConstants.Font.LineHeight.M,
adaptiveFontsize
)
return ( return (
<TextInput <TextInput
@ -65,12 +59,16 @@ const ComposeSpoilerInput: React.FC = () => {
}) })
}} }}
scrollEnabled={false} scrollEnabled={false}
onFocus={() => onFocus={() => {
composeDispatch({ composeDispatch({
type: 'textInputFocus', type: 'textInputFocus',
payload: { current: 'spoiler' } payload: { current: 'spoiler' }
}) })
} composeState.textInputFocus.isFocused.spoiler.current = true
}}
onBlur={() => {
composeState.textInputFocus.isFocused.spoiler.current = false
}}
> >
<CustomText>{composeState.spoiler.formatted}</CustomText> <CustomText>{composeState.spoiler.formatted}</CustomText>
</TextInput> </TextInput>

View File

@ -18,20 +18,11 @@ const ComposeTextInput: React.FC = () => {
const { t } = useTranslation('screenCompose') const { t } = useTranslation('screenCompose')
const { colors, mode } = useTheme() const { colors, mode } = useTheme()
const maxAttachments = useSelector( const maxAttachments = useSelector(getInstanceConfigurationStatusMaxAttachments, () => true)
getInstanceConfigurationStatusMaxAttachments,
() => true
)
const adaptiveFontsize = useSelector(getSettingsFontsize) const adaptiveFontsize = useSelector(getSettingsFontsize)
const adaptedFontsize = adaptiveScale( const adaptedFontsize = adaptiveScale(StyleConstants.Font.Size.M, adaptiveFontsize)
StyleConstants.Font.Size.M, const adaptedLineheight = adaptiveScale(StyleConstants.Font.LineHeight.M, adaptiveFontsize)
adaptiveFontsize
)
const adaptedLineheight = adaptiveScale(
StyleConstants.Font.LineHeight.M,
adaptiveFontsize
)
return ( return (
<PasteInput <PasteInput
@ -59,12 +50,16 @@ const ComposeTextInput: React.FC = () => {
content content
}) })
} }
onFocus={() => onFocus={() => {
composeDispatch({ composeDispatch({
type: 'textInputFocus', type: 'textInputFocus',
payload: { current: 'text' } payload: { current: 'text' }
}) })
} composeState.textInputFocus.isFocused.text.current = true
}}
onBlur={() => {
composeState.textInputFocus.isFocused.text.current = false
}}
onSelectionChange={({ onSelectionChange={({
nativeEvent: { nativeEvent: {
selection: { start, end } selection: { start, end }
@ -79,20 +74,13 @@ const ComposeTextInput: React.FC = () => {
scrollEnabled={false} scrollEnabled={false}
disableCopyPaste={false} disableCopyPaste={false}
onPaste={(error: string | null | undefined, files: PastedFile[]) => { onPaste={(error: string | null | undefined, files: PastedFile[]) => {
if ( if (composeState.attachments.uploads.length + files.length > maxAttachments) {
composeState.attachments.uploads.length + files.length >
maxAttachments
) {
Alert.alert( Alert.alert(
t( t('content.root.header.textInput.keyboardImage.exceedMaximum.title'),
'content.root.header.textInput.keyboardImage.exceedMaximum.title'
),
undefined, undefined,
[ [
{ {
text: t( text: t('content.root.header.textInput.keyboardImage.exceedMaximum.OK'),
'content.root.header.textInput.keyboardImage.exceedMaximum.OK'
),
style: 'default' style: 'default'
} }
] ]

View File

@ -39,7 +39,8 @@ const composeInitialState: Omit<ComposeState, 'timestamp'> = {
replyToStatus: undefined, replyToStatus: undefined,
textInputFocus: { textInputFocus: {
current: 'text', current: 'text',
refs: { text: createRef() } refs: { text: createRef() },
isFocused: { text: createRef(), spoiler: createRef() }
} }
} }

View File

@ -59,6 +59,7 @@ export type ComposeState = {
textInputFocus: { textInputFocus: {
current: 'text' | 'spoiler' current: 'text' | 'spoiler'
refs: { text: RefObject<TextInput> } refs: { text: RefObject<TextInput> }
isFocused: { text: MutableRefObject<boolean>, spoiler: MutableRefObject<boolean> }
} }
} }