Fix composer jumpiness on native

This commit is contained in:
Eric Bailey
2024-09-24 16:27:00 -05:00
parent 4f0217403d
commit 022f16ab61
+20 -30
View File
@@ -8,7 +8,7 @@ import React, {
} from 'react' } from 'react'
import { import {
NativeSyntheticEvent, NativeSyntheticEvent,
StyleSheet, Text as RNText,
TextInput as RNTextInput, TextInput as RNTextInput,
TextInputSelectionChangeEventData, TextInputSelectionChangeEventData,
View, View,
@@ -20,18 +20,16 @@ import PasteInput, {
} from '@mattermost/react-native-paste-input' } from '@mattermost/react-native-paste-input'
import {POST_IMG_MAX} from '#/lib/constants' import {POST_IMG_MAX} from '#/lib/constants'
import {usePalette} from '#/lib/hooks/usePalette'
import {downloadAndResize} from '#/lib/media/manip' import {downloadAndResize} from '#/lib/media/manip'
import {isUriImage} from '#/lib/media/util' import {isUriImage} from '#/lib/media/util'
import {cleanError} from '#/lib/strings/errors' import {cleanError} from '#/lib/strings/errors'
import {getMentionAt, insertMentionAt} from '#/lib/strings/mention-manip' import {getMentionAt, insertMentionAt} from '#/lib/strings/mention-manip'
import {useTheme} from '#/lib/ThemeContext' import {useTheme} from '#/lib/ThemeContext'
import {isAndroid} from '#/platform/detection' import {isAndroid, isNative} from '#/platform/detection'
import { import {
LinkFacetMatch, LinkFacetMatch,
suggestLinkCardUri, suggestLinkCardUri,
} from '#/view/com/composer/text-input/text-input-util' } from '#/view/com/composer/text-input/text-input-util'
import {Text} from '#/view/com/util/text/Text'
import {atoms as a, useAlf} from '#/alf' import {atoms as a, useAlf} from '#/alf'
import {normalizeTextStyles} from '#/components/Typography' import {normalizeTextStyles} from '#/components/Typography'
import {Autocomplete} from './mobile/Autocomplete' import {Autocomplete} from './mobile/Autocomplete'
@@ -70,7 +68,6 @@ export const TextInput = forwardRef(function TextInputImpl(
ref, ref,
) { ) {
const {theme: t, fonts} = useAlf() const {theme: t, fonts} = useAlf()
const pal = usePalette('default')
const textInput = useRef<PasteInputRef>(null) const textInput = useRef<PasteInputRef>(null)
const textInputSelection = useRef<Selection>({start: 0, end: 0}) const textInputSelection = useRef<Selection>({start: 0, end: 0})
const theme = useTheme() const theme = useTheme()
@@ -193,10 +190,12 @@ export const TextInput = forwardRef(function TextInputImpl(
}, },
) )
/* /**
* `PasteInput` appears to prefer no `lineHeight` * PasteInput doesn't like `lineHeight`, results in jumpiness
*/ */
style.lineHeight = undefined if (isNative) {
style.lineHeight = undefined
}
/* /*
* Android impl of `PasteInput` doesn't support the array syntax for `fontVariant` * Android impl of `PasteInput` doesn't support the array syntax for `fontVariant`
@@ -215,18 +214,23 @@ export const TextInput = forwardRef(function TextInputImpl(
return Array.from(richtext.segments()).map(segment => { return Array.from(richtext.segments()).map(segment => {
return ( return (
<Text <RNText
emoji
key={i++} key={i++}
style={[inputTextStyle, segment.facet ? pal.link : pal.text]}> style={[
inputTextStyle,
{
color: segment.facet ? t.palette.primary_500 : t.atoms.text.color,
marginTop: -1,
},
]}>
{segment.text} {segment.text}
</Text> </RNText>
) )
}) })
}, [richtext, pal.link, pal.text, inputTextStyle]) }, [t, richtext, inputTextStyle])
return ( return (
<View style={styles.container}> <View style={[a.flex_1, a.pl_md, a.pb_2xl]}>
<PasteInput <PasteInput
testID="composerTextInput" testID="composerTextInput"
ref={textInput} ref={textInput}
@@ -234,14 +238,14 @@ export const TextInput = forwardRef(function TextInputImpl(
onPaste={onPaste} onPaste={onPaste}
onSelectionChange={onSelectionChange} onSelectionChange={onSelectionChange}
placeholder={placeholder} placeholder={placeholder}
placeholderTextColor={pal.colors.textLight} placeholderTextColor={t.atoms.text_contrast_medium.color}
keyboardAppearance={theme.colorScheme} keyboardAppearance={theme.colorScheme}
autoFocus={true} autoFocus={true}
allowFontScaling allowFontScaling
multiline multiline
scrollEnabled={false} scrollEnabled={false}
numberOfLines={4} numberOfLines={4}
style={[inputTextStyle, styles.textInput, {textAlignVertical: 'top'}]} style={[inputTextStyle, a.w_full, {textAlignVertical: 'top'}]}
{...props}> {...props}>
{textDecorated} {textDecorated}
</PasteInput> </PasteInput>
@@ -252,17 +256,3 @@ export const TextInput = forwardRef(function TextInputImpl(
</View> </View>
) )
}) })
const styles = StyleSheet.create({
container: {
flex: 1,
},
textInput: {
flex: 1,
width: '100%',
padding: 5,
paddingBottom: 20,
marginLeft: 8,
alignSelf: 'flex-start',
},
})