android scroll performance fixes pt. 1 (#6196)
This commit is contained in:
+25
-28
@@ -103,35 +103,32 @@ export function ThemeProvider({
|
|||||||
})
|
})
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
return (
|
const value = React.useMemo<Alf>(
|
||||||
<Context.Provider
|
() => ({
|
||||||
value={React.useMemo<Alf>(
|
themes,
|
||||||
() => ({
|
themeName: themeName,
|
||||||
themes,
|
theme: themes[themeName],
|
||||||
themeName: themeName,
|
fonts: {
|
||||||
theme: themes[themeName],
|
scale: fontScale,
|
||||||
fonts: {
|
scaleMultiplier: fontScaleMultiplier,
|
||||||
scale: fontScale,
|
family: fontFamily,
|
||||||
scaleMultiplier: fontScaleMultiplier,
|
setFontScale: setFontScaleAndPersist,
|
||||||
family: fontFamily,
|
setFontFamily: setFontFamilyAndPersist,
|
||||||
setFontScale: setFontScaleAndPersist,
|
},
|
||||||
setFontFamily: setFontFamilyAndPersist,
|
flags: {},
|
||||||
},
|
}),
|
||||||
flags: {},
|
[
|
||||||
}),
|
themeName,
|
||||||
[
|
themes,
|
||||||
themeName,
|
fontScale,
|
||||||
themes,
|
setFontScaleAndPersist,
|
||||||
fontScale,
|
fontFamily,
|
||||||
setFontScaleAndPersist,
|
setFontFamilyAndPersist,
|
||||||
fontFamily,
|
fontScaleMultiplier,
|
||||||
setFontFamilyAndPersist,
|
],
|
||||||
fontScaleMultiplier,
|
|
||||||
],
|
|
||||||
)}>
|
|
||||||
{children}
|
|
||||||
</Context.Provider>
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
return <Context.Provider value={value}>{children}</Context.Provider>
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useAlf() {
|
export function useAlf() {
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import {UITextView} from 'react-native-uitextview'
|
|||||||
import {lh, s} from '#/lib/styles'
|
import {lh, s} from '#/lib/styles'
|
||||||
import {TypographyVariant, useTheme} from '#/lib/ThemeContext'
|
import {TypographyVariant, useTheme} from '#/lib/ThemeContext'
|
||||||
import {logger} from '#/logger'
|
import {logger} from '#/logger'
|
||||||
import {isIOS} from '#/platform/detection'
|
import {isIOS, isWeb} from '#/platform/detection'
|
||||||
import {applyFonts, useAlf} from '#/alf'
|
import {applyFonts, useAlf} from '#/alf'
|
||||||
import {
|
import {
|
||||||
childHasEmoji,
|
childHasEmoji,
|
||||||
@@ -44,8 +44,6 @@ export function Text({
|
|||||||
...props
|
...props
|
||||||
}: React.PropsWithChildren<CustomTextProps>) {
|
}: React.PropsWithChildren<CustomTextProps>) {
|
||||||
const theme = useTheme()
|
const theme = useTheme()
|
||||||
const typography = theme.typography[type]
|
|
||||||
const lineHeightStyle = lineHeight ? lh(theme, type, lineHeight) : undefined
|
|
||||||
const {fonts} = useAlf()
|
const {fonts} = useAlf()
|
||||||
|
|
||||||
if (IS_DEV) {
|
if (IS_DEV) {
|
||||||
@@ -60,7 +58,10 @@ export function Text({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (selectable && isIOS) {
|
const textProps = React.useMemo(() => {
|
||||||
|
const typography = theme.typography[type]
|
||||||
|
const lineHeightStyle = lineHeight ? lh(theme, type, lineHeight) : undefined
|
||||||
|
|
||||||
const flattened = StyleSheet.flatten([
|
const flattened = StyleSheet.flatten([
|
||||||
s.black,
|
s.black,
|
||||||
typography,
|
typography,
|
||||||
@@ -74,49 +75,47 @@ export function Text({
|
|||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
if (flattened.fontSize) {
|
if (flattened.fontSize) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
flattened.fontSize = flattened.fontSize * fonts.scaleMultiplier
|
flattened.fontSize = Math.round(
|
||||||
|
// @ts-ignore
|
||||||
|
flattened.fontSize * fonts.scaleMultiplier,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const shared = {
|
return {
|
||||||
uiTextView: true,
|
uiTextView: selectable && isIOS,
|
||||||
selectable,
|
selectable,
|
||||||
style: flattened,
|
style: flattened,
|
||||||
|
dataSet: isWeb
|
||||||
|
? Object.assign({tooltip: title}, dataSet || {})
|
||||||
|
: undefined,
|
||||||
...props,
|
...props,
|
||||||
}
|
}
|
||||||
|
}, [
|
||||||
|
dataSet,
|
||||||
|
fonts.family,
|
||||||
|
fonts.scaleMultiplier,
|
||||||
|
lineHeight,
|
||||||
|
props,
|
||||||
|
selectable,
|
||||||
|
style,
|
||||||
|
theme,
|
||||||
|
title,
|
||||||
|
type,
|
||||||
|
])
|
||||||
|
|
||||||
|
if (selectable && isIOS) {
|
||||||
return (
|
return (
|
||||||
<UITextView {...shared}>
|
<UITextView {...textProps}>
|
||||||
{isIOS && emoji ? renderChildrenWithEmoji(children, shared) : children}
|
{isIOS && emoji
|
||||||
|
? renderChildrenWithEmoji(children, textProps)
|
||||||
|
: children}
|
||||||
</UITextView>
|
</UITextView>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const flattened = StyleSheet.flatten([
|
|
||||||
s.black,
|
|
||||||
typography,
|
|
||||||
lineHeightStyle,
|
|
||||||
style,
|
|
||||||
])
|
|
||||||
|
|
||||||
applyFonts(flattened, fonts.family)
|
|
||||||
|
|
||||||
// should always be defined on `typography`
|
|
||||||
// @ts-ignore
|
|
||||||
if (flattened.fontSize) {
|
|
||||||
// @ts-ignore
|
|
||||||
flattened.fontSize = flattened.fontSize * fonts.scaleMultiplier
|
|
||||||
}
|
|
||||||
|
|
||||||
const shared = {
|
|
||||||
selectable,
|
|
||||||
style: flattened,
|
|
||||||
dataSet: Object.assign({tooltip: title}, dataSet || {}),
|
|
||||||
...props,
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<RNText {...shared}>
|
<RNText {...textProps}>
|
||||||
{isIOS && emoji ? renderChildrenWithEmoji(children, shared) : children}
|
{isIOS && emoji ? renderChildrenWithEmoji(children, textProps) : children}
|
||||||
</RNText>
|
</RNText>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user