question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AnimatePresent not unmounts component when using 'worklet'

See original GitHub issue

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

Component remains in tree and not umounted after exit.

Expected Behavior

Component should be unmounted after exit

Steps To Reproduce

  1. Use exit prop with worklet

Versions

- Moti: 0.18.0
- Reanimated: 2.8.0
- React Native: 0.68.2
- Expo: 45.0.4

Screenshots

No response

Reproduction

function MyComponent() {
  const forward = true

  return (
    <AnimatePresence custom={forward} initial={false}>
      <MotiView
        key={index}
        style={[StyleSheet.absoluteFill, styles.content]}
        from={forward ? ANIMATE_RT : ANIMATE_LT_STACK}
        animate={{ translateX: 0 }}
        // exit={{ opacity: 0 }} // <- with this component unmounts
        exit={(custom) => {
          'worklet'
          // With 'worklet' exit components still exist in tree and proceed weird animations
          return custom ? ANIMATE_LT_STACK : ANIMATE_RT
        }}
        transition={TRANSITION}
      >
        {arr[index]}
      </MotiView>
    </AnimatePresence>
  )
}

const ANIMATE_RT = {
  translateX: WIDTH,
  zIndex: 10,
}
const ANIMATE_LT_STACK = { translateX: -WIDTH, zIndex: 5 }
const ANIMATE_LT = { translateX: -WIDTH }
const TRANSITION: TransitionConfig = {
  type: 'timing',
  duration: 2000,
  easing: Easing.out(Easing.cubic),
}

const styles = StyleSheet.create({
  content: {
    overflow: 'hidden',
  },
})

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:14 (9 by maintainers)

github_iconTop GitHub Comments

0reactions
nandorojocommented, Aug 2, 2022

chances are, there’s some other reason. is it an expensive component? AnimatePresence should only be used for simple animations usually, not for deeply-nested components

Read more comments on GitHub >

github_iconTop Results From Across the Web

[BUG] AnimatePresence won't unmount fastly changing content
Bug description: Hi, I'm using AnimatePresence to animate text that ... but will not unmount the component after the exit animation plays.
Read more >
AnimatePresence | Framer for Developers
Notifies components when they're going to be unmounted and; Allows them to defer that unmounting until after an operation is complete (for instance...
Read more >
why isnt my framer motion animation not triggering on unmount?
my loader component that I want to add the unmount animation to: import { motion } from 'framer-motion'; import React from ' ...
Read more >
Animations — Tamagui Core
AnimatePresence animates direct children before they unmount. It's inspired by and forked from Framer Motion , but works with any animation in Tamagui....
Read more >
framer-motion animate presence unmount - CodeSandbox
Activating extension 'vscode.typescript-language-features' failed: Could not find bundled tsserver.js.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found