Transition: Fix switching from/to "optimized" transitions
This commit is contained in:
parent
969b9d28d8
commit
b9ff9fe3a6
@ -1,12 +1,6 @@
|
|||||||
import type {
|
import type { ElementRef } from '@teact';
|
||||||
ElementRef } from '../../lib/teact/teact';
|
import { beginHeavyAnimation, useEffect, useLayoutEffect, useRef } from '@teact';
|
||||||
import type React from '../../lib/teact/teact';
|
import { addExtraClass, removeExtraClass, setExtraStyles, toggleExtraClass } from '@teact/teact-dom';
|
||||||
import {
|
|
||||||
beginHeavyAnimation, useEffect, useLayoutEffect, useRef,
|
|
||||||
} from '../../lib/teact/teact';
|
|
||||||
import {
|
|
||||||
addExtraClass, removeExtraClass, setExtraStyles, toggleExtraClass,
|
|
||||||
} from '../../lib/teact/teact-dom';
|
|
||||||
import { getGlobal } from '../../global';
|
import { getGlobal } from '../../global';
|
||||||
|
|
||||||
import { requestForcedReflow, requestMutation } from '../../lib/fasterdom/fasterdom';
|
import { requestForcedReflow, requestMutation } from '../../lib/fasterdom/fasterdom';
|
||||||
@ -19,6 +13,7 @@ import { allowSwipeControlForTransition } from '../../util/swipeController';
|
|||||||
|
|
||||||
import useForceUpdate from '../../hooks/useForceUpdate';
|
import useForceUpdate from '../../hooks/useForceUpdate';
|
||||||
import usePreviousDeprecated from '../../hooks/usePreviousDeprecated';
|
import usePreviousDeprecated from '../../hooks/usePreviousDeprecated';
|
||||||
|
import useSyncEffectWithPrevDeps from '../../hooks/useSyncEffectWithPrevDeps.ts';
|
||||||
|
|
||||||
import './Transition.scss';
|
import './Transition.scss';
|
||||||
|
|
||||||
@ -122,6 +117,27 @@ function Transition({
|
|||||||
rendersRef.current[nextKey] = children;
|
rendersRef.current[nextKey] = children;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Reset when switching from/to "optimized" transitions
|
||||||
|
useSyncEffectWithPrevDeps(([prevName]) => {
|
||||||
|
if (!prevName) return;
|
||||||
|
|
||||||
|
const prevIsSliceOptimized = prevName === 'slideOptimized' || prevName === 'slideOptimizedRtl';
|
||||||
|
const isSlideOptimized = name === 'slideOptimized' || name === 'slideOptimizedRtl';
|
||||||
|
const shouldReset = (prevIsSliceOptimized && !isSlideOptimized) || (!prevIsSliceOptimized && isSlideOptimized);
|
||||||
|
if (!shouldReset) return;
|
||||||
|
|
||||||
|
rendersRef.current = { [activeKey]: children };
|
||||||
|
|
||||||
|
if (prevIsSliceOptimized) {
|
||||||
|
requestMutation(() => {
|
||||||
|
const container = containerRef.current!;
|
||||||
|
|
||||||
|
['slideOptimized', 'slideOptimizedBackwards', 'slideOptimizedRtl', 'slideOptimizedRtlBackwards']
|
||||||
|
.forEach((cn) => removeExtraClass(container, `Transition-${cn}`));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, [name]);
|
||||||
|
|
||||||
const isBackwards = (
|
const isBackwards = (
|
||||||
direction === -1
|
direction === -1
|
||||||
|| (direction === 'auto' && prevActiveKey > activeKey)
|
|| (direction === 'auto' && prevActiveKey > activeKey)
|
||||||
@ -130,9 +146,8 @@ function Transition({
|
|||||||
|
|
||||||
useLayoutEffect(() => {
|
useLayoutEffect(() => {
|
||||||
function cleanup() {
|
function cleanup() {
|
||||||
if (!shouldCleanup) {
|
if (!shouldCleanup) return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (cleanupExceptionKey !== undefined) {
|
if (cleanupExceptionKey !== undefined) {
|
||||||
rendersRef.current = { [cleanupExceptionKey]: rendersRef.current[cleanupExceptionKey] };
|
rendersRef.current = { [cleanupExceptionKey]: rendersRef.current[cleanupExceptionKey] };
|
||||||
} else if (cleanupOnlyKey !== undefined) {
|
} else if (cleanupOnlyKey !== undefined) {
|
||||||
@ -140,6 +155,7 @@ function Transition({
|
|||||||
} else {
|
} else {
|
||||||
rendersRef.current = {};
|
rendersRef.current = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
forceUpdate();
|
forceUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user