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
+3 -6
View File
@@ -103,9 +103,7 @@ export function ThemeProvider({
}) })
}, []) }, [])
return ( const value = React.useMemo<Alf>(
<Context.Provider
value={React.useMemo<Alf>(
() => ({ () => ({
themes, themes,
themeName: themeName, themeName: themeName,
@@ -128,10 +126,9 @@ export function ThemeProvider({
setFontFamilyAndPersist, setFontFamilyAndPersist,
fontScaleMultiplier, 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) {