Skip to content

Commit bd3bf06

Browse files
committed
fix: multiple box-shadows and animation (#25)
1 parent 9998fd1 commit bd3bf06

File tree

13 files changed

+92
-233
lines changed

13 files changed

+92
-233
lines changed

.config/jest.config.cjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ const jestExpo = require("jest-expo/jest-preset");
66
module.exports = {
77
...jestExpo,
88
testPathIgnorePatterns: ["dist/"],
9+
setupFilesAfterEnv: ["./.config/jest.setup.js"],
910
};

.config/jest.setup.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
// import { setUpTests } from "react-native-reanimated";
1+
import { setUpTests } from "react-native-reanimated";
22

3-
// setUpTests();
3+
setUpTests();

example/src/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default function App() {
66
return (
77
<>
88
<View className="justify-center items-center h-full">
9-
<Text className="text-blue-500 shadow-lg shadow-red">
9+
<Text className="text-green-500 ring-2 ring-blue-500 shadow-xl shadow-red-500">
1010
Test Component
1111
</Text>
1212
</View>

src/compiler/compiler.types.ts

Lines changed: 2 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
/* eslint-disable */
22
import type { Debugger } from "debug";
3-
import type {
4-
AnimationDirection,
5-
AnimationFillMode,
6-
AnimationPlayState,
7-
MediaFeatureNameFor_MediaFeatureId,
8-
} from "lightningcss";
3+
import type { MediaFeatureNameFor_MediaFeatureId } from "lightningcss";
94

105
import { VAR_SYMBOL } from "../runtime/native/reactivity";
116

@@ -147,134 +142,12 @@ export type InlineVariable = {
147142
[key: string]: unknown | undefined;
148143
};
149144

150-
/****************************** Animations V1 ******************************/
151-
152-
/**
153-
* An animation with a fallback style value
154-
*/
155-
export type AnimationWithDefault_V1 =
156-
| [AnimationRule_V1]
157-
| [AnimationRule_V1, StyleFunction];
158-
159-
/**
160-
* A CSS Animation rule
161-
*/
162-
export interface AnimationRule_V1 {
163-
/**
164-
* The animation delay.
165-
*/
166-
de?: number[];
167-
/**
168-
* The direction of the animation.
169-
*/
170-
di?: AnimationDirection[];
171-
/**
172-
* The animation duration.
173-
*/
174-
du?: number[];
175-
/**
176-
* The animation fill mode.
177-
*/
178-
f?: AnimationFillMode[];
179-
/**
180-
* The number of times the animation will run.
181-
*/
182-
i?: number[];
183-
/**
184-
* The animation name.
185-
*/
186-
n?: string[];
187-
/**
188-
* The current play state of the animation.
189-
*/
190-
p?: AnimationPlayState[];
191-
/**
192-
* The animation timeline.
193-
*/
194-
t?: never[];
195-
/**
196-
* The easing function for the animation.
197-
*/
198-
e?: EasingFunction[];
199-
}
200-
201-
export type AnimationKeyframes_V1 =
202-
| [AnimationInterpolation_V1[]]
203-
| [AnimationInterpolation_V1[], AnimationEasing[]];
204-
205-
export type AnimationEasing = number | [number, EasingFunction];
206-
207-
export type AnimationInterpolation_V1 =
208-
| [string, number[], StyleDescriptor[]]
209-
| [string, number[], StyleDescriptor[], number]
210-
| [string, number[], StyleDescriptor[], number, AnimationInterpolationType];
211-
212-
export type AnimationInterpolationType = "color" | "%" | undefined;
213-
214-
export type EasingFunction =
215-
| "linear"
216-
| "ease"
217-
| "ease-in"
218-
| "ease-out"
219-
| "ease-in-out"
220-
| {
221-
type: "cubic-bezier";
222-
/**
223-
* The x-position of the first point in the curve.
224-
*/
225-
x1: number;
226-
/**
227-
* The x-position of the second point in the curve.
228-
*/
229-
x2: number;
230-
/**
231-
* The y-position of the first point in the curve.
232-
*/
233-
y1: number;
234-
/**
235-
* The y-position of the second point in the curve.
236-
*/
237-
y2: number;
238-
}
239-
| {
240-
type: "steps";
241-
/**
242-
* The number of intervals in the function.
243-
*/
244-
c: number;
245-
/**
246-
* The step position.
247-
*/
248-
p?: "start" | "end" | "jump-none" | "jump-both";
249-
};
250-
251145
/****************************** Animations V2 ******************************/
252146

253147
export type Animation_V2 = [string, AnimationKeyframes_V2[]];
254148
export type AnimationRecord = Record<string, AnimationKeyframes_V2[]>;
255149
export type AnimationKeyframes_V2 = [string | number, StyleDeclaration[]];
256150

257-
/****************************** Transitions *****************************/
258-
259-
export type TransitionRule = {
260-
/**
261-
* Delay before the transition starts in milliseconds.
262-
*/
263-
de?: number[];
264-
/**
265-
* Duration of the transition in milliseconds.
266-
*/
267-
du?: number[];
268-
/**
269-
* Property to transition.
270-
*/
271-
p?: string[];
272-
/**
273-
* Easing function for the transition.
274-
*/
275-
e?: EasingFunction[];
276-
};
277-
278151
/****************************** Conditions ******************************/
279152

280153
export type MediaCondition =
@@ -368,7 +241,7 @@ export type LoggerOptions = {
368241
export interface CompilerCollection extends CompilerOptions {
369242
features: FeatureFlagRecord;
370243
rules: Map<string, StyleRule[]>;
371-
keyframes: Map<string, AnimationKeyframes_V1 | AnimationKeyframes_V2[]>;
244+
keyframes: Map<string, AnimationKeyframes_V2[]>;
372245
darkMode?: string | null;
373246
rootVariables: VariableRecord;
374247
universalVariables: VariableRecord;

src/compiler/keyframes.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type {
44
KeyframesRule,
55
} from "lightningcss";
66

7-
import type { EasingFunction, StyleDescriptor } from "./compiler.types";
7+
import type { StyleDescriptor } from "./compiler.types";
88
import { parseDeclaration } from "./declarations";
99
import type { StylesheetBuilder } from "./stylesheet";
1010

@@ -18,8 +18,8 @@ export function parseIterationCount(
1818

1919
export function parseEasingFunction(
2020
value: CSSEasingFunction[],
21-
): StyleDescriptor[] {
22-
return value.map((value): EasingFunction => {
21+
): StyleDescriptor {
22+
const easingFn = value.map((value) => {
2323
switch (value.type) {
2424
case "linear":
2525
case "ease":
@@ -28,15 +28,20 @@ export function parseEasingFunction(
2828
case "ease-in-out":
2929
return value.type;
3030
case "cubic-bezier":
31-
return value;
31+
return [
32+
{},
33+
"cubic-bezier",
34+
[value.x1, value.y1, value.x2, value.y2],
35+
] as const;
3236
case "steps":
33-
return {
34-
type: "steps",
35-
c: value.count,
36-
p: value.position?.type,
37-
};
37+
return [{}, "steps", [value.count, value.position?.type]] as const;
3838
}
3939
}) as StyleDescriptor[];
40+
41+
if (easingFn.length === 1) {
42+
return easingFn[0];
43+
}
44+
return easingFn;
4045
}
4146

4247
export function extractKeyFrames(

src/compiler/stylesheet.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,8 @@ export class StylesheetBuilder {
266266
}
267267
} else if (forceTuple || Array.isArray(propPath)) {
268268
declarations.push([value, propPath]);
269+
} else if (Array.isArray(value) && value.some(isStyleFunction)) {
270+
declarations.push([value, propPath]);
269271
} else {
270272
if (!this.staticDeclarations) {
271273
this.staticDeclarations = {};

src/runtime/native/styles/animation.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* eslint-disable */
22
import type { ComponentType } from "react";
33

4+
import { applyShorthand } from "../../utils";
45
import { StyleCollection } from "../injection";
56
import { weakFamily } from "../reactivity";
67
import type { StyleFunctionResolver } from "./resolve";
@@ -57,6 +58,7 @@ export const animationShorthand = shorthandHandler(
5758
playState,
5859
timingFunction,
5960
],
61+
"tuples",
6062
);
6163

6264
export const animatedComponentFamily = weakFamily(
@@ -92,6 +94,8 @@ export const animation: StyleFunctionResolver = (
9294
return;
9395
}
9496

97+
animationShortHandTuples.pop();
98+
9599
const nameTuple = animationShortHandTuples.find(
96100
(tuple) => tuple[1] === "animationName",
97101
);
@@ -133,7 +137,7 @@ export const animation: StyleFunctionResolver = (
133137

134138
nameTuple[0] = animation;
135139

136-
return animationShortHandTuples;
140+
return applyShorthand(animationShortHandTuples);
137141
};
138142

139143
const advancedTimingFunctions: Record<

src/runtime/native/styles/box-shadow.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { applyShorthand, isStyleDescriptorArray } from "../../utils";
1+
import { isStyleDescriptorArray } from "../../utils";
22
import type { StyleFunctionResolver } from "./resolve";
33
import { shorthandHandler } from "./shorthand";
44

@@ -19,6 +19,7 @@ const handler = shorthandHandler(
1919
[offsetX, offsetY, blurRadius, color],
2020
],
2121
[],
22+
"object",
2223
);
2324

2425
export const boxShadow: StyleFunctionResolver = (
@@ -38,17 +39,15 @@ export const boxShadow: StyleFunctionResolver = (
3839
} else if (isStyleDescriptorArray(shadows)) {
3940
if (shadows.length === 0) {
4041
return [];
41-
} else {
42+
} else if (Array.isArray(shadows[0])) {
4243
return shadows
43-
.map((shadow) => {
44-
return applyShorthand(
45-
handler(resolveValue, shadow, get, options),
46-
);
47-
})
44+
.map((shadow) => handler(resolveValue, shadow, get, options))
4845
.filter((v) => v !== undefined);
46+
} else {
47+
return handler(resolveValue, shadows, get, options);
4948
}
5049
} else {
51-
return applyShorthand(handler(resolveValue, shadows, get, options));
50+
return handler(resolveValue, shadows, get, options);
5251
}
5352
});
5453
}

src/runtime/native/styles/calc.ts

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export const calc: StyleFunctionResolver = (resolveValue, func) => {
3030
} else if (token === ")") {
3131
// Resolve all values within the brackets
3232
while (ops.length && ops[ops.length - 1] !== "(") {
33-
applyCalcOperator(ops.pop()!, values.pop()!, values.pop()!, values);
33+
applyCalcOperator(ops.pop()!, values.pop(), values.pop(), values);
3434
}
3535
ops.pop();
3636
} else if (token.endsWith("%")) {
@@ -45,7 +45,7 @@ export const calc: StyleFunctionResolver = (resolveValue, func) => {
4545
// @ts-ignore
4646
calcPrecedence[ops[ops.length - 1]] >= calcPrecedence[token]
4747
) {
48-
applyCalcOperator(ops.pop()!, values.pop()!, values.pop()!, values);
48+
applyCalcOperator(ops.pop()!, values.pop(), values.pop(), values);
4949
}
5050
ops.push(token);
5151
}
@@ -54,31 +54,9 @@ export const calc: StyleFunctionResolver = (resolveValue, func) => {
5454
return;
5555
}
5656
}
57-
// case "object": {
58-
// // All values should resolve to a numerical value
59-
// const value = resolveValue(token);
60-
// switch (typeof value) {
61-
// case "number": {
62-
// if (!mode) mode = "number";
63-
// if (mode !== "number") return;
64-
// values.push(value);
65-
// continue;
66-
// }
67-
// case "string": {
68-
// if (!value.endsWith("%")) {
69-
// return;
70-
// }
71-
// if (!mode) mode = "percentage";
72-
// if (mode !== "percentage") return;
73-
// values.push(Number.parseFloat(value.slice(0, -1)));
74-
// continue;
75-
// }
76-
// default:
77-
// return;
78-
// }
79-
// }
57+
8058
while (ops.length) {
81-
applyCalcOperator(ops.pop()!, values.pop()!, values.pop()!, values);
59+
applyCalcOperator(ops.pop()!, values.pop(), values.pop(), values);
8260
}
8361

8462
if (!mode) return;
@@ -100,8 +78,8 @@ export const calc: StyleFunctionResolver = (resolveValue, func) => {
10078

10179
function applyCalcOperator(
10280
operator: string,
103-
b: number, // These are reversed because we pop them off the stack
104-
a: number,
81+
b = 0, // These are reversed because we pop them off the stack
82+
a = 0,
10583
values: number[],
10684
) {
10785
switch (operator) {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export const emVariableName = "__rn-css-em";
2+
export const ShortHandSymbol = Symbol();

0 commit comments

Comments
 (0)