[Neue] Ligatures & composer (#5427)

* Disable contextual ligatures

* Ensure new type styles are applied to the composer

* Clean up using real devices

* Feedback
This commit is contained in:
Eric Bailey
2024-09-19 14:41:31 -05:00
committed by GitHub
parent 1523160467
commit 8a7fc9ad3f
5 changed files with 66 additions and 25 deletions
+34 -19
View File
@@ -19,6 +19,7 @@ import PasteInput, {
PasteInputRef,
} from '@mattermost/react-native-paste-input'
import {isAndroid} from '#/platform/detection'
import {POST_IMG_MAX} from 'lib/constants'
import {usePalette} from 'lib/hooks/usePalette'
import {downloadAndResize} from 'lib/media/manip'
@@ -26,12 +27,13 @@ import {isUriImage} from 'lib/media/util'
import {cleanError} from 'lib/strings/errors'
import {getMentionAt, insertMentionAt} from 'lib/strings/mention-manip'
import {useTheme} from 'lib/ThemeContext'
import {isIOS} from 'platform/detection'
import {
LinkFacetMatch,
suggestLinkCardUri,
} 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 {normalizeTextStyles} from '#/components/Typography'
import {Autocomplete} from './mobile/Autocomplete'
export interface TextInputRef {
@@ -67,6 +69,7 @@ export const TextInput = forwardRef(function TextInputImpl(
}: TextInputProps,
ref,
) {
const {theme: t, fonts} = useAlf()
const pal = usePalette('default')
const textInput = useRef<PasteInputRef>(null)
const textInputSelection = useRef<Selection>({start: 0, end: 0})
@@ -180,6 +183,33 @@ export const TextInput = forwardRef(function TextInputImpl(
[onChangeText, richtext, setAutocompletePrefix],
)
const inputTextStyle = React.useMemo(() => {
const style = normalizeTextStyles(
[a.text_xl, a.leading_snug, t.atoms.text],
{
fontScale: fonts.scaleMultiplier,
fontFamily: fonts.family,
flags: {},
},
)
/*
* `PasteInput` appears to prefer no `lineHeight`
*/
style.lineHeight = undefined
/*
* Android impl of `PasteInput` doesn't support the array syntax for `fontVariant`
*/
if (isAndroid) {
// @ts-ignore
style.fontVariant = style.fontVariant
? style.fontVariant.join(' ')
: undefined
}
return style
}, [t, fonts])
const textDecorated = useMemo(() => {
let i = 0
@@ -187,15 +217,12 @@ export const TextInput = forwardRef(function TextInputImpl(
return (
<Text
key={i++}
style={[
segment.facet ? pal.link : pal.text,
styles.textInputFormatting,
]}>
style={[inputTextStyle, segment.facet ? pal.link : pal.text]}>
{segment.text}
</Text>
)
})
}, [richtext, pal.link, pal.text])
}, [richtext, pal.link, pal.text, inputTextStyle])
return (
<View style={styles.container}>
@@ -213,12 +240,7 @@ export const TextInput = forwardRef(function TextInputImpl(
multiline
scrollEnabled={false}
numberOfLines={4}
style={[
pal.text,
styles.textInput,
styles.textInputFormatting,
{textAlignVertical: 'top'},
]}
style={[inputTextStyle, styles.textInput, {textAlignVertical: 'top'}]}
{...props}>
{textDecorated}
</PasteInput>
@@ -242,11 +264,4 @@ const styles = StyleSheet.create({
marginLeft: 8,
alignSelf: 'flex-start',
},
textInputFormatting: {
fontSize: 18,
letterSpacing: 0.2,
fontWeight: '400',
// This is broken on ios right now, so don't set it there.
lineHeight: isIOS ? undefined : 23.4, // 1.3*16
},
})