From dac82ed07cbd97b365c0e04d8616f34c3ac0a39a Mon Sep 17 00:00:00 2001 From: Youssef Henna Date: Tue, 19 Nov 2024 19:14:53 +0100 Subject: [PATCH] Reapply "Remove zod parsing in creating values" This reverts commit 959f1d1a0945b024fa2c1df1fda25c48052fe0be. --- packages/theme/package.json | 3 ++- packages/theme/src/createThemeValuesProxy.ts | 18 +++++++++++++----- yarn.lock | 5 +++++ 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/packages/theme/package.json b/packages/theme/package.json index 29db15414..b2da2af1f 100644 --- a/packages/theme/package.json +++ b/packages/theme/package.json @@ -42,7 +42,8 @@ "@react-native-async-storage/async-storage": "1.21.0", "color": "^4.2.3", "react-native-typography": "^1.4.1", - "zod": "^3.23.8" + "zod": "^3.23.8", + "lodash.isobject": "^3.0.2" }, "eslintIgnore": [ "node_modules/", diff --git a/packages/theme/src/createThemeValuesProxy.ts b/packages/theme/src/createThemeValuesProxy.ts index ae9499dd8..1cee53636 100644 --- a/packages/theme/src/createThemeValuesProxy.ts +++ b/packages/theme/src/createThemeValuesProxy.ts @@ -1,6 +1,6 @@ import { ThemeValues, Breakpoints } from "./types"; import { Platform, TextStyle } from "react-native"; -import { asThemeValuesObject } from "./validators"; +import { isObject } from "lodash"; interface CreateThemeValuesProxyInput { value: ThemeValues | undefined; @@ -34,7 +34,9 @@ export default function createThemeValuesProxy({ ): string | number | ThemeValues | TextStyle | undefined => { const currentValue = target[key]; - const valueAsThemeValues = asThemeValuesObject(currentValue); + const valueAsThemeValues = isObject(currentValue) + ? (currentValue as ThemeValues) + : undefined; if (valueAsThemeValues) { const platformKeys = ["ios", "android", "web", "macos", "windows"]; @@ -139,7 +141,9 @@ function getPlatformValue(input: CreateThemeValuesProxyInput) { const { value, devicePlatform } = input; const currentPlatformValue = value?.[devicePlatform] ?? value?.default; - const valueAsThemeValues = asThemeValuesObject(currentPlatformValue); + const valueAsThemeValues = isObject(currentPlatformValue) + ? (currentPlatformValue as ThemeValues) + : undefined; if (valueAsThemeValues) { return createThemeValuesProxy({ ...input, value: valueAsThemeValues }); @@ -163,7 +167,9 @@ function getBreakpointValue(input: CreateThemeValuesProxyInput) { } const currentBreakpointValue = value?.[currentBreakpointKey] ?? value?.default; - const valueAsThemeValues = asThemeValuesObject(currentBreakpointValue); + const valueAsThemeValues = isObject(currentBreakpointKey) + ? (currentBreakpointKey as ThemeValues) + : undefined; if (valueAsThemeValues) { return createThemeValuesProxy({ ...input, value: valueAsThemeValues }); @@ -177,7 +183,9 @@ function getLightDarkValue(input: CreateThemeValuesProxyInput) { const currentLightDarkValue = value?.[currentLightDarkSelection] ?? value?.default; - const valueAsThemeValues = asThemeValuesObject(currentLightDarkValue); + const valueAsThemeValues = isObject(currentLightDarkSelection) + ? (currentLightDarkSelection as ThemeValues) + : undefined; if (valueAsThemeValues) { return createThemeValuesProxy({ ...input, value: valueAsThemeValues }); diff --git a/yarn.lock b/yarn.lock index 14a7d9fb3..9eb2cd7af 100644 --- a/yarn.lock +++ b/yarn.lock @@ -10441,6 +10441,11 @@ lodash.isnumber@^3.0.3: resolved "https://registry.yarnpkg.com/lodash.isnumber/-/lodash.isnumber-3.0.3.tgz#3ce76810c5928d03352301ac287317f11c0b1ffc" integrity sha512-QYqzpfwO3/CWf3XP+Z+tkQsfaLL/EnUlXWVkIk5FUPc4sBdTehEqZONuyRt2P67PXAk+NXmTBcc97zw9t1FQrw== +lodash.isobject@^3.0.2: + version "3.0.2" + resolved "https://registry.yarnpkg.com/lodash.isobject/-/lodash.isobject-3.0.2.tgz#3c8fb8d5b5bf4bf90ae06e14f2a530a4ed935e1d" + integrity sha512-3/Qptq2vr7WeJbB4KHUSKlq8Pl7ASXi3UG6CMbBm8WRtXi8+GHm7mKaU3urfpSEzWe2wCIChs6/sdocUsTKJiA== + lodash.memoize@^4.1.2: version "4.1.2" resolved "https://registry.yarnpkg.com/lodash.memoize/-/lodash.memoize-4.1.2.tgz#bcc6c49a42a2840ed997f323eada5ecd182e0bfe"