Skip to content

Commit ff4e98c

Browse files
committed
fix(lynx): inline scale animation worklet
1 parent bc91f55 commit ff4e98c

2 files changed

Lines changed: 23 additions & 38 deletions

File tree

packages/lynx-react/src/hooks/useScaleFeedback.ts

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,16 @@ import {
88
} from "@lynx-js/react";
99
import type { RefObject } from "@lynx-js/react";
1010
import type { MainThread } from "@lynx-js/types";
11-
import { feedbackScaleDuration } from "@seed-design/lynx-css/scale-feedback" with {
12-
runtime: "shared",
13-
};
11+
import {
12+
feedbackScaleDuration,
13+
feedbackScaleTimingFunction,
14+
} from "@seed-design/lynx-css/scale-feedback" with { runtime: "shared" };
1415

1516
import type { LynxViewProps } from "../types";
1617
import { calculateScaleFeedback, isReducedMotion } from "../utils/calculate-scale-feedback" with {
1718
runtime: "shared",
1819
};
19-
import { animateScaleFeedback, type ScaleFeedbackElement } from "../utils/animate-scale-feedback" with {
20-
runtime: "shared",
21-
};
20+
import type { ScaleFeedbackElement } from "../utils/animate-scale-feedback";
2221

2322
type MainThreadLayoutChangeHandler = NonNullable<LynxViewProps["main-thread:bindlayoutchange"]>;
2423
type MainThreadTouchHandler = NonNullable<LynxViewProps["main-thread:bindtouchstart"]>;
@@ -64,11 +63,24 @@ function runScaleFeedback(
6463
) {
6564
"main thread";
6665

67-
animationRef.current = animateScaleFeedback(
68-
targetRef.current,
69-
animationRef.current,
70-
scale,
71-
duration,
66+
const target = targetRef.current;
67+
if (!target) return;
68+
69+
let currentTransform = "scale(1)";
70+
try {
71+
currentTransform = target.getComputedStyleProperty("transform") || currentTransform;
72+
} catch {
73+
// Some non-native runtimes expose the method but cannot evaluate it.
74+
}
75+
76+
animationRef.current?.cancel();
77+
animationRef.current = target.animate(
78+
[{ transform: currentTransform }, { transform: `scale(${scale})` }],
79+
{
80+
duration,
81+
easing: feedbackScaleTimingFunction,
82+
fill: "forwards",
83+
},
7284
);
7385
}
7486

packages/lynx-react/src/utils/animate-scale-feedback.ts

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -21,30 +21,3 @@ export function createScaleFeedbackAnimation(
2121
},
2222
};
2323
}
24-
25-
export function animateScaleFeedback(
26-
target: ScaleFeedbackElement | null,
27-
currentAnimation: MainThread.Animation | null,
28-
scale: number,
29-
duration: number,
30-
): MainThread.Animation | null {
31-
"main thread";
32-
33-
if (!target) return null;
34-
35-
let currentTransform = "scale(1)";
36-
try {
37-
currentTransform = target.getComputedStyleProperty("transform") || currentTransform;
38-
} catch {
39-
// Some non-native runtimes expose the method but cannot evaluate it.
40-
}
41-
42-
const { keyframes, options } = createScaleFeedbackAnimation(
43-
currentTransform,
44-
scale,
45-
duration,
46-
);
47-
currentAnimation?.cancel();
48-
49-
return target.animate(keyframes, options);
50-
}

0 commit comments

Comments
 (0)