From 183dc30ea0fd254b976db8a9cbc0ca198f3ca697 Mon Sep 17 00:00:00 2001 From: Hubert Bieszczad Date: Tue, 25 Nov 2025 09:08:05 +0100 Subject: [PATCH] feat: support text-shadow --- .../uniwind/src/core/native/parsers/index.ts | 1 + .../src/core/native/parsers/textShadow.ts | 37 +++++++++++++++++++ packages/uniwind/src/core/native/store.ts | 6 ++- 3 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 packages/uniwind/src/core/native/parsers/textShadow.ts diff --git a/packages/uniwind/src/core/native/parsers/index.ts b/packages/uniwind/src/core/native/parsers/index.ts index e11d68d8..1ee4b280 100644 --- a/packages/uniwind/src/core/native/parsers/index.ts +++ b/packages/uniwind/src/core/native/parsers/index.ts @@ -1,4 +1,5 @@ export * from './boxShadow' export * from './fontVariant' export * from './gradient' +export * from './textShadow' export * from './transforms' diff --git a/packages/uniwind/src/core/native/parsers/textShadow.ts b/packages/uniwind/src/core/native/parsers/textShadow.ts new file mode 100644 index 00000000..ca46d9af --- /dev/null +++ b/packages/uniwind/src/core/native/parsers/textShadow.ts @@ -0,0 +1,37 @@ +export const parseTextShadowMutation = (styles: Record) => { + const tokens: Array = styles.textShadow.replace(/,/g, '').split(' ') + + if (tokens.length === 0) { + return + } + + const color = tokens.find(token => token.startsWith('#')) ?? '#000000' + const offsets = tokens.filter(token => token !== color) + const [offsetX, offsetY, radius] = offsets + + if (offsetX !== undefined && offsetY !== undefined) { + Object.defineProperty(styles, 'textShadowOffset', { + configurable: true, + enumerable: true, + value: { + width: Number(offsetX), + height: Number(offsetY), + }, + }) + delete styles.textShadow + } + + if (radius !== undefined) { + Object.defineProperty(styles, 'textShadowRadius', { + configurable: true, + enumerable: true, + value: Number(radius), + }) + } + + Object.defineProperty(styles, 'textShadowColor', { + configurable: true, + enumerable: true, + value: color, + }) +} diff --git a/packages/uniwind/src/core/native/store.ts b/packages/uniwind/src/core/native/store.ts index 8ec5d2db..bc86bb38 100644 --- a/packages/uniwind/src/core/native/store.ts +++ b/packages/uniwind/src/core/native/store.ts @@ -5,7 +5,7 @@ import { Uniwind } from '../config/config' import { UniwindListener } from '../listener' import { ComponentState, GenerateStyleSheetsCallback, RNStyle, Style, StyleSheets } from '../types' import { cloneWithAccessors } from './native-utils' -import { parseBoxShadow, parseFontVariant, parseTransformsMutation, resolveGradient } from './parsers' +import { parseBoxShadow, parseFontVariant, parseTextShadowMutation, parseTransformsMutation, resolveGradient } from './parsers' import { UniwindRuntime } from './runtime' type StylesResult = { @@ -214,6 +214,10 @@ class UniwindStoreBuilder { }) } + if (result.textShadow !== undefined) { + parseTextShadowMutation(result) + } + return { styles: { ...result } as RNStyle, dependencies: Array.from(new Set(dependencies)),