Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing exit variant propagation #346

Merged
merged 2 commits into from
Oct 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

Framer Motion adheres to [Semantic Versioning](http://semver.org/).

## [1.6.9] Unreleased

### Fix

- Exit variant propagation.

## [1.6.8] 2019-10-02

### Fix
Expand Down
26 changes: 18 additions & 8 deletions src/animation/use-value-animation-controls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import {
} from "./ValueAnimationControls"
import { useContext, useEffect } from "react"
import { MotionProps } from "../motion/types"
import { MotionContext } from "../motion/context/MotionContext"
import {
MotionContext,
MotionContextProps,
} from "../motion/context/MotionContext"
import { useConstant } from "../utils/use-constant"

/**
Expand All @@ -22,20 +25,27 @@ import { useConstant } from "../utils/use-constant"
export function useValueAnimationControls<P>(
config: ValueAnimationConfig,
props: P & MotionProps,
subscribeToParentControls: boolean
subscribeToParentControls: boolean,
parentContext?: MotionContextProps
) {
const { variants, transition } = props
const parentControls = useContext(MotionContext).controls
const controls = useConstant(() => new ValueAnimationControls<P>(config))

// Reset and resubscribe children every render to ensure stagger order is correct
controls.resetChildren()
controls.setProps(props)
controls.setVariants(variants)
controls.setDefaultTransition(transition)
if (
!parentContext ||
!parentContext.exitProps ||
!parentContext.exitProps.isExiting
) {
controls.resetChildren()
controls.setProps(props)
controls.setVariants(variants)
controls.setDefaultTransition(transition)

if (subscribeToParentControls && parentControls) {
parentControls.addChild(controls)
if (subscribeToParentControls && parentControls) {
parentControls.addChild(controls)
}
}

useEffect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@ describe("AnimatePresence", () => {

test("Exit propagates through variants", async () => {
const variants = {
enter: { opacity: 1 },
exit: { opacity: 0 },
enter: { opacity: 1, transition: { type: false } },
exit: { opacity: 0, transition: { type: false } },
}

const promise = new Promise<number>(resolve => {
Expand All @@ -218,7 +218,7 @@ describe("AnimatePresence", () => {
<AnimatePresence>
{isVisible && (
<motion.div
initial="exit"
initial="enter"
animate="enter"
exit="exit"
variants={variants}
Expand Down
3 changes: 2 additions & 1 deletion src/motion/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ export const createMotionComponent = <P extends {}>({
const controls = useValueAnimationControls(
controlsConfig,
props,
shouldInheritVariant
shouldInheritVariant,
parentContext
)

const context = useMotionContext(
Expand Down
1 change: 0 additions & 1 deletion src/motion/functionality/exit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export const Exit: FunctionalComponentDefinition = {
...props,
custom: custom !== undefined ? custom : props.custom,
})

controls.start(exit).then(onExitComplete)
})

Expand Down