Skip to content

Commit 06032cc

Browse files
committed
Return handle from end method
1 parent 8901a10 commit 06032cc

File tree

3 files changed

+6
-8
lines changed

3 files changed

+6
-8
lines changed

src/hooks/useAnimation.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export type AnimationHandle = {
2626
setPlaybackRate: (
2727
rate: number | ((prevRate: number) => number)
2828
) => AnimationHandle;
29-
end: () => Promise<void>;
29+
end: () => Promise<AnimationHandle>;
3030
ref: RefObject<any>;
3131
};
3232

@@ -108,7 +108,7 @@ export const useAnimation = (
108108
handle._setRate(getAnimation(), rate);
109109
return externalHandle;
110110
},
111-
end: () => handle._end(getAnimation()),
111+
end: () => handle._end(getAnimation()).then(() => externalHandle),
112112
ref,
113113
};
114114
return [

src/hooks/useAnimationFunction.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export type AnimationFunctionHandle = {
1717
setPlaybackRate: (
1818
rate: number | ((prevRate: number) => number)
1919
) => AnimationFunctionHandle;
20-
end: () => Promise<void>;
20+
end: () => Promise<AnimationFunctionHandle>;
2121
};
2222

2323
export type ComputedTimingContext = Required<
@@ -108,7 +108,7 @@ export const useAnimationFunction = (
108108
handle._setRate(getAnimation(), rate);
109109
return externalHandle;
110110
},
111-
end: () => handle._end(getAnimation()),
111+
end: () => handle._end(getAnimation()).then(() => externalHandle),
112112
};
113113
return [
114114
externalHandle,

stories/hooks/useAnimationController.stories.tsx

+2-4
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,8 @@ const Block = ({ i, length: n }: { i: number; length: number }) => {
183183
useEffect(() => {
184184
const run = async () => {
185185
animate.cancelAll();
186-
await animate.get("one").play().end();
187-
animate.get("one").cancel();
188-
await animate.get("two").play().end();
189-
animate.get("two").cancel();
186+
(await animate.get("one").play().end()).cancel();
187+
(await animate.get("two").play().end()).cancel();
190188
await animate.get("three").play().end();
191189
run();
192190
};

0 commit comments

Comments
 (0)