mirror of
https://github.com/zhigang1992/nativewind.git
synced 2026-06-15 10:17:54 +08:00
fix: ensure spreadProps use flat styles on preview
This commit is contained in:
@@ -4,6 +4,7 @@ import { usePlatform } from "./context/platform";
|
||||
import {
|
||||
RWNCssStyle,
|
||||
UseTailwindCallback,
|
||||
UseTailwindCallbackOptions,
|
||||
UseTailwindOptions,
|
||||
} from "./use-tailwind";
|
||||
|
||||
@@ -11,16 +12,19 @@ import { useTailwind as useNativeTailwind } from "./use-tailwind.native";
|
||||
|
||||
export function useTailwind<
|
||||
P extends ViewStyle | TextStyle | ImageStyle | RWNCssStyle
|
||||
>(options?: UseTailwindOptions): UseTailwindCallback<P> {
|
||||
>(useTailwindOptions?: UseTailwindOptions): UseTailwindCallback<P> {
|
||||
const { platform, preview } = usePlatform();
|
||||
|
||||
if (platform === "web" && preview) {
|
||||
return ((className = "") => {
|
||||
return options?.flatten
|
||||
return (<F extends boolean | undefined = true>(
|
||||
className = "",
|
||||
{ flatten = true }: UseTailwindCallbackOptions<F> = {}
|
||||
) => {
|
||||
return flatten
|
||||
? classNameToInlineStyle(className)
|
||||
: { $$css: true, tailwindClassName: className };
|
||||
}) as UseTailwindCallback<P>;
|
||||
}
|
||||
|
||||
return useNativeTailwind<P>(options);
|
||||
return useNativeTailwind<P>(useTailwindOptions);
|
||||
}
|
||||
|
||||
@@ -40,9 +40,12 @@ export function withStyledProps<S, T extends string>({
|
||||
if (typeof value === "string") {
|
||||
if (preview) {
|
||||
styledProps[prop] = undefined;
|
||||
(mainStyles as unknown as Record<string, unknown>)[prop] = tw(value, {
|
||||
flatten: false,
|
||||
});
|
||||
(mainStyles as unknown as Record<string, unknown>)[prop] = (
|
||||
tw(value, {
|
||||
flatten: false,
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
}) as any
|
||||
).tailwindClassName;
|
||||
} else {
|
||||
const entries = Object.entries(tw(value, { flatten: true }));
|
||||
if (entries.length > 0) {
|
||||
|
||||
Reference in New Issue
Block a user