Skip to content

Commit 51ce9d7

Browse files
committed
feat(TransitionView): remove previous slide before continuing to next slide, enhance animation
1 parent 9d68962 commit 51ce9d7

File tree

5 files changed

+11
-39
lines changed

5 files changed

+11
-39
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
.slide {
2-
position: absolute;
2+
height: 100%;
33
width: 100%;
44
}

packages/core/src/components/SlideTransition/SlideTransition.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ const SlideTransition = forwardRef(
1414
variants={slideAnimationVariants}
1515
initial="initial"
1616
animate="enter"
17-
exit="exit"
1817
transition={slideAnimationTransition}
1918
className={cx(styles.slide, className)}
2019
style={style}

packages/core/src/components/SlideTransition/utils/animationVariants.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,14 @@ import { SlideDirection } from "../SlideTransition.types";
22

33
export const slideAnimationVariants = {
44
initial: (direction: SlideDirection) => ({
5-
x: direction === "forward" ? "10%" : "-10%",
6-
opacity: 0
5+
x: direction === "forward" ? "3%" : "-3%"
76
}),
87
enter: {
9-
x: 0,
10-
opacity: 1
11-
},
12-
exit: (direction: SlideDirection) => ({
13-
x: direction === "forward" ? "-10%" : "10%",
14-
opacity: 0
15-
})
8+
x: 0
9+
}
1610
};
1711

1812
export const slideAnimationTransition = {
19-
duration: 0.1,
13+
duration: 0.25,
2014
ease: [0.0, 0.0, 0.4, 1.0]
2115
};
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
.slideshow {
2-
position: relative;
32
width: 100%;
43
height: 100%;
5-
overflow: hidden;
4+
min-height: 0;
65
}

packages/core/src/components/TransitionView/TransitionView.tsx

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,26 @@
1-
import React, { forwardRef, useEffect, useRef, useState } from "react";
1+
import React, { forwardRef } from "react";
22
import cx from "classnames";
33
import { AnimatePresence } from "framer-motion";
44
import { TransitionViewProps } from "./TransitionView.types";
55
import { getTestId } from "../../tests/test-ids-utils";
66
import { ComponentDefaultTestId } from "../../tests/constants";
77
import styles from "./TransitionView.module.scss";
88
import SlideTransition from "../SlideTransition/SlideTransition";
9-
import useMergeRef from "../../hooks/useMergeRef";
109

1110
const TransitionView = forwardRef(
1211
(
13-
{ activeStep, direction, height, id, className, "data-testid": dataTestId, children }: TransitionViewProps,
12+
{ activeStep, direction, id, className, "data-testid": dataTestId, children }: TransitionViewProps,
1413
ref: React.ForwardedRef<HTMLDivElement>
1514
) => {
16-
const componentRef = useRef<HTMLDivElement>(null);
17-
const mergedRef = useMergeRef(ref, componentRef);
18-
const slideTransitionRef = useRef<HTMLDivElement>(null);
19-
const [contentHeight, setContentHeight] = useState<number | "100%">(height);
20-
const slideTransitionHeight = height || contentHeight === "100%" || contentHeight > 0 ? "100%" : "auto";
21-
22-
useEffect(() => {
23-
if (!slideTransitionRef.current) return;
24-
// if parent has definite height, stretch component to fill it, otherwise use content height
25-
setContentHeight(componentRef.current.clientHeight > 0 ? "100%" : slideTransitionRef.current.scrollHeight);
26-
}, [height, slideTransitionRef]);
27-
2815
return (
2916
<div
3017
id={id}
3118
className={cx(styles.slideshow, className)}
3219
data-testid={dataTestId || getTestId(ComponentDefaultTestId.TRANSITION_VIEW, id)}
33-
ref={mergedRef}
34-
style={{ height: height ?? contentHeight }}
20+
ref={ref}
3521
>
36-
<AnimatePresence initial={false} custom={direction}>
37-
<SlideTransition
38-
key={activeStep}
39-
direction={direction}
40-
// it must be "auto" on initial load to consider scrollable content in contentHeight calculation
41-
style={{ height: slideTransitionHeight }}
42-
ref={slideTransitionRef}
43-
>
22+
<AnimatePresence initial={false} custom={direction} exitBeforeEnter>
23+
<SlideTransition key={activeStep} direction={direction}>
4424
{children[activeStep]}
4525
</SlideTransition>
4626
</AnimatePresence>

0 commit comments

Comments
 (0)