Skip to content

Commit 7857c3a

Browse files
committed
Fixed wrong logic in fallback of commit method
1 parent ce88805 commit 7857c3a

File tree

3 files changed

+10
-17
lines changed

3 files changed

+10
-17
lines changed

src/hooks/core.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { noop } from "../utils";
1+
import { getKeys, noop, uniqBy } from "../utils";
22

33
export type AnimatableCSSProperties = Omit<
44
React.CSSProperties,
@@ -25,6 +25,9 @@ export interface AnimationOptions
2525
easing?: TypedEasing;
2626
}
2727

28+
export const getKeyframeKeys = (keyframes: TypedKeyframe[]): string[] =>
29+
uniqBy(keyframes.flatMap((k) => getKeys(k)));
30+
2831
export const createAnimation = (
2932
el: HTMLElement | null,
3033
keyframes: Keyframe[] | null,

src/hooks/useAnimation.ts

+3-8
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
11
import { createRef, useEffect, useLayoutEffect, useRef, useState } from "react";
2-
import {
3-
getKeys,
4-
isSameObject,
5-
isSameObjectArray,
6-
toArray,
7-
uniqBy,
8-
} from "../utils";
2+
import { isSameObject, isSameObjectArray, toArray } from "../utils";
93
import {
104
AnimationOptions,
115
createAnimation,
126
createHandle,
7+
getKeyframeKeys,
138
TypedKeyframe,
149
} from "./core";
1510

@@ -104,7 +99,7 @@ export const useAnimation = (
10499
handle._commit(
105100
getAnimation(),
106101
getTarget()!,
107-
uniqBy(getKeys(getKeyframes()))
102+
getKeyframeKeys(getKeyframes())
108103
);
109104
return externalHandle;
110105
},

src/hooks/useAnimations.ts

+3-8
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
11
import { createRef, useEffect, useLayoutEffect, useRef, useState } from "react";
2-
import {
3-
getKeys,
4-
isSameObject,
5-
isSameObjectArray,
6-
toArray,
7-
uniqBy,
8-
} from "../utils";
2+
import { isSameObject, isSameObjectArray, toArray } from "../utils";
93
import {
104
AnimationOptions,
115
createAnimation,
126
createHandle,
7+
getKeyframeKeys,
138
TypedKeyframe,
149
} from "./core";
1510
import type { WithRef } from "./useAnimation";
@@ -106,7 +101,7 @@ export const useAnimations = <ID extends string>(
106101
handle._commit(
107102
getAnimation(name),
108103
getTarget()!,
109-
uniqBy(getKeys(toArray(getKeyframesAndOptions(name)[0])))
104+
getKeyframeKeys(toArray(getKeyframesAndOptions(name)[0]))
110105
);
111106
return externalHandle;
112107
},

0 commit comments

Comments
 (0)