Accordion-Collapse-react-native icon indicating copy to clipboard operation
Accordion-Collapse-react-native copied to clipboard

How to add animation

Open thebiltheory opened this issue 3 years ago • 3 comments

Is it possible to animate the opening of the box?

thebiltheory avatar Oct 26 '20 12:10 thebiltheory

You can animate the body the way you want in your application. e.g. This component has a fade animation on mount,

const Body = () => {
  const fadeAnim = useRef(new Animated.Value(0)).current; // Initial value for opacity: 0

  useEffect(() => {
    Animated.timing(fadeAnim, {
      toValue: 1,
      duration: 10000,
    }).start();
  }, [fadeAnim]);

  return (
    <Animated.View style={{opacity: fadeAnim}}>
      <Text>test2</Text>
    </Animated.View>
  );
};

If I render this component inside the CollapseBody,

<Collapse>
        <CollapseHeader>
          <View>
            <Text>header</Text>
          </View>
        </CollapseHeader>
        <CollapseBody>
          <Body />
        </CollapseBody>
</Collapse>

This will result in a fade animation when you toggle the Collapse component (since the CollapseBody mounts until we toggle it) You can play around with animation using API provided or Libraries and put whatever content inside Collapse and animate it the way you want.

marouanekadiri avatar Oct 27 '20 19:10 marouanekadiri

Would it be possible to show an example for animating the collapse height?

lukeinage avatar Aug 11 '22 09:08 lukeinage

i appreciate your work, i think It will look better if there is a props for an animation like (True or False) if we want to activate the animation on opening or on closing the accordion .

AhmedTriki-IT avatar Jan 19 '23 13:01 AhmedTriki-IT