Fix leftover style functions without props in the options.

This commit is contained in:
Zoe Roux
2023-01-15 03:02:54 +09:00
parent d1da3af5ba
commit 9dc2d92d64
3 changed files with 12 additions and 5 deletions
+2 -1
View File
@@ -100,6 +100,7 @@ const P = (props: TextProps) => {
function App() {
const { css } = useYoshiki();
const test: ImageProps = {};
const funcStyle = css({ focus: { self: { bg: "red" } } });
return (
<View
@@ -114,7 +115,7 @@ function App() {
<Text>Open up App.tsx to start working on your app!</Text>
<CustomBox color="black" {...css({ borderColor: "red", borderWidth: px(3) })} />
<BoxWithoutProps {...css({ borderColor: "red", borderWidth: px(3) })} />
<Pressable android_ripple={{ color: "black" }}>
<Pressable android_ripple={{ color: "black" }} {...css({ bg: "black" }, funcStyle)}>
<P
accessibilityLabel="toto"
{...css([undefined, false, { color: "red" }, [{ color: "green" }, false]])}
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "yoshiki",
"version": "1.2.0",
"version": "1.2.1",
"author": "Zoe Roux <zoe.roux@sdg.moe> (https://github.com/AnonymusRaccoon)",
"license": "MIT",
"keywords": [
+9 -3
View File
@@ -6,6 +6,7 @@
import {
ImageStyle,
PressableProps,
PressableStateCallbackType,
TextStyle,
useWindowDimensions,
ViewStyle,
@@ -87,8 +88,8 @@ export const useYoshiki = (_?: string) => {
if (hasState<State>(css)) {
const { hover, focus, fover, press, ...inline } = css;
const { onPressIn, onPressOut, onHoverIn, onHoverOut, onFocus, onBlur } =
leftOvers as PressableProps;
const { onPressIn, onPressOut, onHoverIn, onHoverOut, onFocus, onBlur } = (leftOvers ??
{}) as PressableProps;
const ret: StyleFunc<unknown> = ({ hovered, focused, pressed }) => {
childStyles.current = {};
assignChilds(childStyles.current, child);
@@ -142,9 +143,14 @@ export const useYoshiki = (_?: string) => {
},
} satisfies PressableProps;
} else {
const ret = [processStyle(css), processStyle(child?.self ?? {})];
const loStyle = leftOvers?.style;
return {
...leftOvers,
style: [processStyle(css), processStyle(child?.self ?? {}), leftOvers?.style],
style:
typeof loStyle === "function"
? (state: PressableStateCallbackType) => [...ret, loStyle(state)]
: [...ret, loStyle],
} as any;
}
};