I am using the react-native-popup-menu
and created my own renderer
component. It's a function component, so in short it looks like this:
const ContextMenuRenderer = ({ children, layouts, ...otherProps }) => {
return (
<Animated.View
{...otherProps}
onLayout={handleViewLayout}
style={[styles.viewStyle, viewAnimations]}
>
{children}
</Animated.View>
);
}
viewAnimations
contains the opening animations, the code is relatively large but you can see it in this snack.
The docs says "In order to handle asynchronous closing animations, renderer can implement close()
method which is called before menu closes. close method has to return Promise
."
I read the ContextMenu code, it is a class component and implements close()
as:
close() {
return new Promise(resolve => {
Animated.timing(this.state.scaleAnim, {
duration: CLOSE_ANIM_DURATION,
toValue: 0,
easing: Easing.in(Easing.cubic),
useNativeDriver: USE_NATIVE_DRIVER,
}).start(resolve);
});
}
I tried to implement something similar inside my Function Component but the code isn't executed. I figured it wouldn't work, but what can I do to create an animation on close? I wanted to do a fade out animation.
function close() {
console.log('close'); // It isn't logged
return new Promise((resolve) => {
console.log('resolve close');
});
}