fix: stop animations on unmount/cleanup

This commit is contained in:
Satyajit Sahoo
2021-08-25 03:11:55 +02:00
parent acdde18d89
commit 5fb5f41eb6
4 changed files with 5 additions and 54 deletions

View File

@@ -48,6 +48,8 @@ export default function Badge({
setRendered(false);
}
});
return () => opacity.stopAnimation();
}, [opacity, rendered, visible]);
if (visible && !rendered) {

View File

@@ -206,6 +206,8 @@ export default function BottomTabBar({
...visibilityAnimationConfig?.hide?.config,
}).start();
}
return () => visible.stopAnimation();
}, [visible, shouldShowTabBar]);
const [layout, setLayout] = React.useState({

View File

@@ -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>
);
}
}

View File

@@ -141,6 +141,7 @@ export default class Card extends React.Component<Props> {
}
componentWillUnmount() {
this.props.gesture.stopAnimation();
this.isCurrentlyMounted = false;
this.handleEndInteraction();
}