mirror of
https://github.com/zhigang1992/react-navigation.git
synced 2026-01-12 22:51:18 +08:00
fix: stop animations on unmount/cleanup
This commit is contained in:
@@ -48,6 +48,8 @@ export default function Badge({
|
||||
setRendered(false);
|
||||
}
|
||||
});
|
||||
|
||||
return () => opacity.stopAnimation();
|
||||
}, [opacity, rendered, visible]);
|
||||
|
||||
if (visible && !rendered) {
|
||||
|
||||
@@ -206,6 +206,8 @@ export default function BottomTabBar({
|
||||
...visibilityAnimationConfig?.hide?.config,
|
||||
}).start();
|
||||
}
|
||||
|
||||
return () => visible.stopAnimation();
|
||||
}, [visible, shouldShowTabBar]);
|
||||
|
||||
const [layout, setLayout] = React.useState({
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
import * as React from 'react';
|
||||
import { Animated, Platform } from 'react-native';
|
||||
import { BaseButton, BaseButtonProperties } from 'react-native-gesture-handler';
|
||||
|
||||
const AnimatedBaseButton = Animated.createAnimatedComponent(BaseButton);
|
||||
|
||||
type Props = BaseButtonProperties & {
|
||||
pressOpacity: number;
|
||||
};
|
||||
|
||||
const useNativeDriver = Platform.OS !== 'web';
|
||||
|
||||
export default class BorderlessButton extends React.Component<Props> {
|
||||
static defaultProps = {
|
||||
activeOpacity: 0.3,
|
||||
borderless: true,
|
||||
};
|
||||
|
||||
private opacity = new Animated.Value(1);
|
||||
|
||||
private handleActiveStateChange = (active: boolean) => {
|
||||
if (Platform.OS !== 'android') {
|
||||
Animated.spring(this.opacity, {
|
||||
stiffness: 1000,
|
||||
damping: 500,
|
||||
mass: 3,
|
||||
overshootClamping: true,
|
||||
restDisplacementThreshold: 0.01,
|
||||
restSpeedThreshold: 0.01,
|
||||
toValue: active ? this.props.pressOpacity : 1,
|
||||
useNativeDriver,
|
||||
}).start();
|
||||
}
|
||||
|
||||
this.props.onActiveStateChange?.(active);
|
||||
};
|
||||
|
||||
render() {
|
||||
const { children, style, enabled, ...rest } = this.props;
|
||||
|
||||
return (
|
||||
<AnimatedBaseButton
|
||||
{...rest}
|
||||
onActiveStateChange={this.handleActiveStateChange}
|
||||
style={[
|
||||
style,
|
||||
Platform.OS === 'ios' && enabled && { opacity: this.opacity },
|
||||
]}
|
||||
>
|
||||
{children}
|
||||
</AnimatedBaseButton>
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -141,6 +141,7 @@ export default class Card extends React.Component<Props> {
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
this.props.gesture.stopAnimation();
|
||||
this.isCurrentlyMounted = false;
|
||||
this.handleEndInteraction();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user