Skip to content

Commit 30dcb60

Browse files
authored
Remove animatable from FloatingButton component (#1134)
1 parent 438b1d1 commit 30dcb60

File tree

1 file changed

+30
-23
lines changed

1 file changed

+30
-23
lines changed

src/components/floatingButton/index.tsx

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import React, {PropsWithChildren, PureComponent} from 'react';
2-
import {StyleSheet} from 'react-native';
3-
import {View as AnimatableView} from 'react-native-animatable';
2+
import {StyleSheet, Animated} from 'react-native';
43
import {Constants} from '../../helpers';
54
import {asBaseComponent} from '../../commons/new';
65
import {Colors, Spacings} from '../../style';
@@ -43,9 +42,6 @@ export interface FloatingButtonProps {
4342
testID?: string;
4443
}
4544

46-
const SHOW_ANIMATION_DELAY = 350;
47-
const SHOW_ANIMATION_DURATION = 180;
48-
const HIDE_ANIMATION_DURATION = 150;
4945
const gradientImage = () => require('./gradient.png');
5046

5147
/**
@@ -60,17 +56,35 @@ class FloatingButton extends PureComponent<FloatingButtonProps> {
6056

6157
initialVisibility?: boolean;
6258
firstLoad: boolean;
59+
visibleAnimated: Animated.Value;
6360

6461
constructor(props: FloatingButtonProps) {
6562
super(props);
6663

6764
this.initialVisibility = props.visible;
6865
this.firstLoad = true;
66+
this.visibleAnimated = new Animated.Value(Number(!!props.visible));
6967
}
7068

71-
onAnimationEnd = () => {
72-
this.setState({animating: false});
73-
};
69+
componentDidUpdate(prevProps: FloatingButtonProps) {
70+
if (prevProps.visible !== this.props.visible) {
71+
Animated.timing(this.visibleAnimated, {
72+
toValue: Number(!!this.props.visible),
73+
duration: 300,
74+
useNativeDriver: true
75+
}).start();
76+
}
77+
}
78+
79+
getAnimatedStyle = () => {
80+
return {
81+
opacity: this.visibleAnimated,
82+
transform: [{translateY: this.visibleAnimated.interpolate({
83+
inputRange: [0, 1],
84+
outputRange: [Constants.screenHeight / 2, 0]
85+
})}]
86+
};
87+
}
7488

7589
renderButton() {
7690
const {bottomMargin, button, secondaryButton} = this.props;
@@ -115,8 +129,6 @@ class FloatingButton extends PureComponent<FloatingButtonProps> {
115129

116130
render() {
117131
const {withoutAnimation, secondaryButton, visible} = this.props;
118-
const Container = !withoutAnimation ? AnimatableView : View;
119-
120132
// NOTE: keep this.firstLoad as true as long as the visibility changed to true
121133
this.firstLoad && !visible ? this.firstLoad = true : this.firstLoad = false;
122134

@@ -129,30 +141,25 @@ class FloatingButton extends PureComponent<FloatingButtonProps> {
129141
}
130142

131143
return (
132-
<Container
144+
<View
133145
pointerEvents="box-none"
134-
style={[styles.animatedContainer, Constants.isAndroid && {zIndex: 99}]}
135-
animation={!visible ? 'fadeOutDown' : 'fadeInUp'}
136-
duration={SHOW_ANIMATION_DURATION}
137-
delay={!visible ? HIDE_ANIMATION_DURATION : SHOW_ANIMATION_DELAY}
138-
easing={'ease-out'}
139-
onAnimationEnd={this.onAnimationEnd}
146+
animated
147+
style={[styles.container, this.getAnimatedStyle()]}
140148
>
141149
{this.renderOverlay()}
142150
{this.renderButton()}
143151
{secondaryButton && this.renderSecondaryButton()}
144-
</Container>
152+
</View>
145153
);
146154
}
147155
}
148156

149157
const styles = StyleSheet.create({
150-
animatedContainer: {
151-
position: 'absolute',
152-
left: 0,
153-
right: 0,
158+
container: {
159+
...StyleSheet.absoluteFillObject,
160+
top: undefined,
154161
alignItems: 'center',
155-
bottom: 0
162+
zIndex: Constants.isAndroid ? 99 : undefined
156163
},
157164
image: {
158165
...StyleSheet.absoluteFillObject,

0 commit comments

Comments
 (0)