我用的是
react-native-popup-menu
创造了我自己的
renderer
组件。它是一个函数组件,所以简而言之,它看起来是这样的:
const ContextMenuRenderer = ({ children, layouts, ...otherProps }) => {
return (
<Animated.View
{...otherProps}
onLayout={handleViewLayout}
style={[styles.viewStyle, viewAnimations]}
>
{children}
</Animated.View>
);
}
viewAnimations
包含打开动画,代码相对较大,但您可以在中看到它
this snack
.
这个
docs
表示“为了处理异步关闭动画,渲染器可以实现
close()
方法,该方法在菜单关闭之前调用。必须返回close方法
Promise
ContextMenu code
,它是一个类组件并实现
关闭()
作为:
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);
});
}
我试图在我的函数组件中实现类似的东西,但是代码没有被执行。我想这是行不通的,但我能做些什么来创建一个动画关闭?我想做一个淡出动画。
function close() {
console.log('close'); // It isn't logged
return new Promise((resolve) => {
console.log('resolve close');
});
}