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 ( 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() {
+7 -7
View File
@@ -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) {
@@ -61,6 +59,9 @@ export function Text({
} }
const textProps = React.useMemo(() => { 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,
@@ -80,25 +81,24 @@ export function Text({
) )
} }
const shared = { return {
uiTextView: selectable && isIOS, uiTextView: selectable && isIOS,
selectable, selectable,
style: flattened, style: flattened,
dataSet: Object.assign({tooltip: title}, dataSet || {}), dataSet: Object.assign({tooltip: title}, dataSet || {}),
...props, ...props,
} }
return shared
}, [ }, [
dataSet, dataSet,
fonts.family, fonts.family,
fonts.scaleMultiplier, fonts.scaleMultiplier,
lineHeightStyle, lineHeight,
props, props,
selectable, selectable,
style, style,
theme,
title, title,
typography, type,
]) ])
if (selectable && isIOS) { if (selectable && isIOS) {