more memoization

This commit is contained in:
Hailey
2024-11-09 15:54:42 -08:00
parent 9f5661bfb1
commit f7ffc3c06f
2 changed files with 32 additions and 35 deletions
+25 -28
View File
@@ -103,35 +103,32 @@ export function ThemeProvider({
})
}, [])
return (
<Context.Provider
value={React.useMemo<Alf>(
() => ({
themes,
themeName: themeName,
theme: themes[themeName],
fonts: {
scale: fontScale,
scaleMultiplier: fontScaleMultiplier,
family: fontFamily,
setFontScale: setFontScaleAndPersist,
setFontFamily: setFontFamilyAndPersist,
},
flags: {},
}),
[
themeName,
themes,
fontScale,
setFontScaleAndPersist,
fontFamily,
setFontFamilyAndPersist,
fontScaleMultiplier,
],
)}>
{children}
</Context.Provider>
const value = React.useMemo<Alf>(
() => ({
themes,
themeName: themeName,
theme: themes[themeName],
fonts: {
scale: fontScale,
scaleMultiplier: fontScaleMultiplier,
family: fontFamily,
setFontScale: setFontScaleAndPersist,
setFontFamily: setFontFamilyAndPersist,
},
flags: {},
}),
[
themeName,
themes,
fontScale,
setFontScaleAndPersist,
fontFamily,
setFontFamilyAndPersist,
fontScaleMultiplier,
],
)
return <Context.Provider value={value}>{children}</Context.Provider>
}
export function useAlf() {
+7 -7
View File
@@ -44,8 +44,6 @@ export function Text({
...props
}: React.PropsWithChildren<CustomTextProps>) {
const theme = useTheme()
const typography = theme.typography[type]
const lineHeightStyle = lineHeight ? lh(theme, type, lineHeight) : undefined
const {fonts} = useAlf()
if (IS_DEV) {
@@ -61,6 +59,9 @@ export function Text({
}
const textProps = React.useMemo(() => {
const typography = theme.typography[type]
const lineHeightStyle = lineHeight ? lh(theme, type, lineHeight) : undefined
const flattened = StyleSheet.flatten([
s.black,
typography,
@@ -80,25 +81,24 @@ export function Text({
)
}
const shared = {
return {
uiTextView: selectable && isIOS,
selectable,
style: flattened,
dataSet: Object.assign({tooltip: title}, dataSet || {}),
...props,
}
return shared
}, [
dataSet,
fonts.family,
fonts.scaleMultiplier,
lineHeightStyle,
lineHeight,
props,
selectable,
style,
theme,
title,
typography,
type,
])
if (selectable && isIOS) {