Skip to content

Commit

Permalink
Reapply "Remove zod parsing in creating values"
Browse files Browse the repository at this point in the history
This reverts commit 959f1d1.
  • Loading branch information
YoussefHenna committed Nov 19, 2024
1 parent 7a35a1b commit dac82ed
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
3 changes: 2 additions & 1 deletion packages/theme/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/",
Expand Down
18 changes: 13 additions & 5 deletions packages/theme/src/createThemeValuesProxy.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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"];
Expand Down Expand Up @@ -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 });
Expand All @@ -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 });
Expand All @@ -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 });
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit dac82ed

Please sign in to comment.