-
diff --git a/packages/vkui/src/lib/animation/useCSSKeyframesAnimationController.test.ts b/packages/vkui/src/lib/animation/useCSSKeyframesAnimationController.test.ts
index d7dc2fec48..74480c629a 100644
--- a/packages/vkui/src/lib/animation/useCSSKeyframesAnimationController.test.ts
+++ b/packages/vkui/src/lib/animation/useCSSKeyframesAnimationController.test.ts
@@ -3,7 +3,7 @@ import { renderHook } from '@testing-library/react';
import { useCSSKeyframesAnimationController } from './useCSSKeyframesAnimationController';
describe(useCSSKeyframesAnimationController, () => {
- describe.each([false, true])('`noAnimation` prop is `%s`', (noAnimation) => {
+ describe.each([false, true])('`disableInitAnimation` prop is `%s`', (disableInitAnimation) => {
const callbacks = {
onEnter: jest.fn(),
onEntering: jest.fn(),
@@ -23,13 +23,13 @@ describe(useCSSKeyframesAnimationController, () => {
it('should enter', () => {
const { result } = renderHook(() =>
- useCSSKeyframesAnimationController('enter', callbacks, noAnimation),
+ useCSSKeyframesAnimationController('enter', callbacks, disableInitAnimation),
);
- !noAnimation && expect(result.current[0]).toBe('enter');
+ !disableInitAnimation && expect(result.current[0]).toBe('enter');
act(result.current[1].onAnimationStart);
- if (!noAnimation) {
+ if (!disableInitAnimation) {
expect(result.current[0]).toBe('entering');
expect(callbacks.onEntering).toHaveBeenCalledTimes(1);
}
@@ -40,12 +40,14 @@ describe(useCSSKeyframesAnimationController, () => {
});
it('should exit', () => {
- const { result } = renderHook(() => useCSSKeyframesAnimationController('exit', callbacks));
+ const { result } = renderHook(() =>
+ useCSSKeyframesAnimationController('exit', callbacks, disableInitAnimation),
+ );
- !noAnimation && expect(result.current[0]).toBe('exit');
+ !disableInitAnimation && expect(result.current[0]).toBe('exit');
act(result.current[1].onAnimationStart);
- if (!noAnimation) {
+ if (!disableInitAnimation) {
expect(result.current[0]).toBe('exiting');
expect(callbacks.onExiting).toHaveBeenCalledTimes(1);
}
diff --git a/packages/vkui/src/lib/animation/useCSSKeyframesAnimationController.ts b/packages/vkui/src/lib/animation/useCSSKeyframesAnimationController.ts
index ff043dc3c4..b78578b7bd 100644
--- a/packages/vkui/src/lib/animation/useCSSKeyframesAnimationController.ts
+++ b/packages/vkui/src/lib/animation/useCSSKeyframesAnimationController.ts
@@ -26,8 +26,9 @@ export const useCSSKeyframesAnimationController = (
onExiting: onExitingProp = noop,
onExited: onExitedProp = noop,
}: UseCSSAnimationControllerCallback = {},
- noAnimation = false,
+ disableInitAnimation = false,
): [AnimationState, AnimationHandlers] => {
+ const isFirstInitRef = React.useRef(disableInitAnimation);
const [state, setState] = React.useState
(stateProp);
const [willBeEnter, setWillBeEnter] = React.useState(stateProp === 'enter');
const [willBeExit, setWillBeExit] = React.useState(stateProp === 'exit');
@@ -73,7 +74,7 @@ export const useCSSKeyframesAnimationController = (
function updateState() {
switch (stateProp) {
case 'enter':
- if (noAnimation && state === 'enter') {
+ if (isFirstInitRef.current && state === 'enter') {
entered();
break;
}
@@ -87,7 +88,7 @@ export const useCSSKeyframesAnimationController = (
onEnter();
break;
case 'exit':
- if (noAnimation && state === 'exit') {
+ if (isFirstInitRef.current && state === 'exit') {
exited();
break;
}
@@ -101,8 +102,10 @@ export const useCSSKeyframesAnimationController = (
onExit();
break;
}
+
+ isFirstInitRef.current = false;
},
- [state, stateProp, willBeEnter, willBeExit, noAnimation, entered, exited, onEnter, onExit],
+ [state, stateProp, willBeEnter, willBeExit, entered, exited, onEnter, onExit],
);
return [state, { onAnimationStart, onAnimationEnd }];