diff --git a/packages/yoshiki/package.json b/packages/yoshiki/package.json index 2a22ed1..79786e4 100644 --- a/packages/yoshiki/package.json +++ b/packages/yoshiki/package.json @@ -1,6 +1,6 @@ { "name": "yoshiki", - "version": "1.0.8", + "version": "1.1.0", "author": "Zoe Roux (https://github.com/AnonymusRaccoon)", "license": "MIT", "keywords": [ diff --git a/packages/yoshiki/src/native/generator.tsx b/packages/yoshiki/src/native/generator.tsx index 3ba7227..35d32d8 100644 --- a/packages/yoshiki/src/native/generator.tsx +++ b/packages/yoshiki/src/native/generator.tsx @@ -21,7 +21,7 @@ import { } from "../type"; import { isBreakpoints } from "../utils"; import { shorthandsFn } from "../shorthands"; -import { StyleFunc, NativeCssFunc } from "./type"; +import { StyleFunc, NativeCssFunc, EnhancedStyle } from "./type"; import { useReducer, useRef } from "react"; const useBreakpoint = (): number => { @@ -64,15 +64,17 @@ const useForceRerender = () => { return useReducer((x) => x + 1, 0)[1]; }; +type State = EnhancedStyle | undefined; + export const useYoshiki = () => { const breakpoint = useBreakpoint(); const theme = useTheme(); const rerender = useForceRerender(); - const childStyles = useRef>({}); + const childStyles = useRef>({}); const css: NativeCssFunc = (cssList, leftOvers) => { // The as any is because we can't be sure the style type is right one. - const css = processStyleListWithChild(cssList, childStyles.current as any); + const { child, ...css } = processStyleListWithChild(cssList, childStyles.current as any); const processStyle = (styleList: Record>) => { const ret = Object.fromEntries( @@ -83,18 +85,20 @@ export const useYoshiki = () => { return ret; }; - if (hasState>(css)) { + if (hasState(css)) { const { hover, focus, press, ...inline } = css; const { onPressIn, onPressOut, onHoverIn, onHoverOut, onFocus, onBlur } = leftOvers as PressableProps; const ret: StyleFunc = ({ hovered, focused, pressed }) => { childStyles.current = {}; + assignChilds(childStyles.current, child); if (hovered) assignChilds(childStyles.current, hover); if (focused) assignChilds(childStyles.current, focus); if (pressed) assignChilds(childStyles.current, press); return [ processStyle(inline), + processStyle(child?.self ?? {}), hovered && processStyle(hover?.self ?? {}), focused && processStyle(focus?.self ?? {}), pressed && processStyle(press?.self ?? {}), @@ -138,7 +142,7 @@ export const useYoshiki = () => { } else { return { ...leftOvers, - style: [processStyle(css), leftOvers?.style], + style: [processStyle(css), processStyle(child?.self ?? {}), leftOvers?.style], } as any; } }; diff --git a/packages/yoshiki/src/native/type.ts b/packages/yoshiki/src/native/type.ts index 40fc782..c549a92 100644 --- a/packages/yoshiki/src/native/type.ts +++ b/packages/yoshiki/src/native/type.ts @@ -3,7 +3,7 @@ // Licensed under the MIT license. See LICENSE file in the project root for details. // -import { WithState, YoshikiStyle, StyleList } from "../type"; +import { WithState, YoshikiStyle, StyleList, WithChild } from "../type"; import { shorthandsFn } from "../shorthands"; import { ImageStyle, PressableProps, StyleProp, TextStyle, ViewStyle } from "react-native"; import { Theme } from "../theme"; @@ -43,37 +43,45 @@ export type StyleFunc