[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:
@@ -149,7 +149,6 @@
|
|||||||
|
|
||||||
/* ProseMirror */
|
/* ProseMirror */
|
||||||
.ProseMirror {
|
.ProseMirror {
|
||||||
font: 18px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Liberation Sans", Helvetica, Arial, sans-serif;
|
|
||||||
min-height: 140px;
|
min-height: 140px;
|
||||||
}
|
}
|
||||||
.ProseMirror-dark {
|
.ProseMirror-dark {
|
||||||
|
|||||||
@@ -108,4 +108,10 @@ export function applyFonts(
|
|||||||
style.fontFamily = style.fontFamily || FAMILIES
|
style.fontFamily = style.fontFamily || FAMILIES
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Disable contextual ligatures
|
||||||
|
* {@link https://developer.mozilla.org/en-US/docs/Web/CSS/font-variant}
|
||||||
|
*/
|
||||||
|
style.fontVariant = ['no-contextual']
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import PasteInput, {
|
|||||||
PasteInputRef,
|
PasteInputRef,
|
||||||
} from '@mattermost/react-native-paste-input'
|
} from '@mattermost/react-native-paste-input'
|
||||||
|
|
||||||
|
import {isAndroid} from '#/platform/detection'
|
||||||
import {POST_IMG_MAX} from 'lib/constants'
|
import {POST_IMG_MAX} from 'lib/constants'
|
||||||
import {usePalette} from 'lib/hooks/usePalette'
|
import {usePalette} from 'lib/hooks/usePalette'
|
||||||
import {downloadAndResize} from 'lib/media/manip'
|
import {downloadAndResize} from 'lib/media/manip'
|
||||||
@@ -26,12 +27,13 @@ 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 {isIOS} 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 {Text} from 'view/com/util/text/Text'
|
||||||
|
import {atoms as a, useAlf} from '#/alf'
|
||||||
|
import {normalizeTextStyles} from '#/components/Typography'
|
||||||
import {Autocomplete} from './mobile/Autocomplete'
|
import {Autocomplete} from './mobile/Autocomplete'
|
||||||
|
|
||||||
export interface TextInputRef {
|
export interface TextInputRef {
|
||||||
@@ -67,6 +69,7 @@ export const TextInput = forwardRef(function TextInputImpl(
|
|||||||
}: TextInputProps,
|
}: TextInputProps,
|
||||||
ref,
|
ref,
|
||||||
) {
|
) {
|
||||||
|
const {theme: t, fonts} = useAlf()
|
||||||
const pal = usePalette('default')
|
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})
|
||||||
@@ -180,6 +183,33 @@ export const TextInput = forwardRef(function TextInputImpl(
|
|||||||
[onChangeText, richtext, setAutocompletePrefix],
|
[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(() => {
|
const textDecorated = useMemo(() => {
|
||||||
let i = 0
|
let i = 0
|
||||||
|
|
||||||
@@ -187,15 +217,12 @@ export const TextInput = forwardRef(function TextInputImpl(
|
|||||||
return (
|
return (
|
||||||
<Text
|
<Text
|
||||||
key={i++}
|
key={i++}
|
||||||
style={[
|
style={[inputTextStyle, segment.facet ? pal.link : pal.text]}>
|
||||||
segment.facet ? pal.link : pal.text,
|
|
||||||
styles.textInputFormatting,
|
|
||||||
]}>
|
|
||||||
{segment.text}
|
{segment.text}
|
||||||
</Text>
|
</Text>
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
}, [richtext, pal.link, pal.text])
|
}, [richtext, pal.link, pal.text, inputTextStyle])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={styles.container}>
|
<View style={styles.container}>
|
||||||
@@ -213,12 +240,7 @@ export const TextInput = forwardRef(function TextInputImpl(
|
|||||||
multiline
|
multiline
|
||||||
scrollEnabled={false}
|
scrollEnabled={false}
|
||||||
numberOfLines={4}
|
numberOfLines={4}
|
||||||
style={[
|
style={[inputTextStyle, styles.textInput, {textAlignVertical: 'top'}]}
|
||||||
pal.text,
|
|
||||||
styles.textInput,
|
|
||||||
styles.textInputFormatting,
|
|
||||||
{textAlignVertical: 'top'},
|
|
||||||
]}
|
|
||||||
{...props}>
|
{...props}>
|
||||||
{textDecorated}
|
{textDecorated}
|
||||||
</PasteInput>
|
</PasteInput>
|
||||||
@@ -242,11 +264,4 @@ const styles = StyleSheet.create({
|
|||||||
marginLeft: 8,
|
marginLeft: 8,
|
||||||
alignSelf: 'flex-start',
|
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
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -22,7 +22,9 @@ import {
|
|||||||
LinkFacetMatch,
|
LinkFacetMatch,
|
||||||
suggestLinkCardUri,
|
suggestLinkCardUri,
|
||||||
} from 'view/com/composer/text-input/text-input-util'
|
} from 'view/com/composer/text-input/text-input-util'
|
||||||
|
import {atoms as a, useAlf} from '#/alf'
|
||||||
import {Portal} from '#/components/Portal'
|
import {Portal} from '#/components/Portal'
|
||||||
|
import {normalizeTextStyles} from '#/components/Typography'
|
||||||
import {Text} from '../../util/text/Text'
|
import {Text} from '../../util/text/Text'
|
||||||
import {createSuggestion} from './web/Autocomplete'
|
import {createSuggestion} from './web/Autocomplete'
|
||||||
import {Emoji} from './web/EmojiPicker.web'
|
import {Emoji} from './web/EmojiPicker.web'
|
||||||
@@ -58,6 +60,7 @@ export const TextInput = React.forwardRef(function TextInputImpl(
|
|||||||
TextInputProps,
|
TextInputProps,
|
||||||
ref,
|
ref,
|
||||||
) {
|
) {
|
||||||
|
const {theme: t, fonts} = useAlf()
|
||||||
const autocomplete = useActorAutocompleteFn()
|
const autocomplete = useActorAutocompleteFn()
|
||||||
const pal = usePalette('default')
|
const pal = usePalette('default')
|
||||||
const modeClass = useColorSchemeStyle('ProseMirror-light', 'ProseMirror-dark')
|
const modeClass = useColorSchemeStyle('ProseMirror-light', 'ProseMirror-dark')
|
||||||
@@ -247,13 +250,32 @@ export const TextInput = React.forwardRef(function TextInputImpl(
|
|||||||
},
|
},
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
const inputStyle = React.useMemo(() => {
|
||||||
|
const style = normalizeTextStyles(
|
||||||
|
[a.text_lg, a.leading_snug, t.atoms.text],
|
||||||
|
{
|
||||||
|
fontScale: fonts.scaleMultiplier,
|
||||||
|
fontFamily: fonts.family,
|
||||||
|
flags: {},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
/*
|
||||||
|
* TipTap component isn't a RN View and while it seems to convert
|
||||||
|
* `fontSize` to `px`, it doesn't convert `lineHeight`.
|
||||||
|
*
|
||||||
|
* `lineHeight` should always be defined here, this is defensive.
|
||||||
|
*/
|
||||||
|
style.lineHeight = style.lineHeight
|
||||||
|
? ((style.lineHeight + 'px') as unknown as number)
|
||||||
|
: undefined
|
||||||
|
return style
|
||||||
|
}, [t, fonts])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<View style={styles.container}>
|
<View style={styles.container}>
|
||||||
<EditorContent
|
{/* @ts-ignore inputStyle is fine */}
|
||||||
editor={editor}
|
<EditorContent editor={editor} style={inputStyle} />
|
||||||
style={{color: pal.text.color as string}}
|
|
||||||
/>
|
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
{isDropping && (
|
{isDropping && (
|
||||||
|
|||||||
@@ -153,7 +153,6 @@
|
|||||||
|
|
||||||
/* ProseMirror */
|
/* ProseMirror */
|
||||||
.ProseMirror {
|
.ProseMirror {
|
||||||
font: 18px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Liberation Sans", Helvetica, Arial, sans-serif;
|
|
||||||
min-height: 140px;
|
min-height: 140px;
|
||||||
}
|
}
|
||||||
.ProseMirror-dark {
|
.ProseMirror-dark {
|
||||||
|
|||||||
Reference in New Issue
Block a user