Skip to content

Remove animatable from FloatingButton component #1134

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 14, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 30 additions & 23 deletions src/components/floatingButton/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, {PropsWithChildren, PureComponent} from 'react';
import {StyleSheet} from 'react-native';
import {View as AnimatableView} from 'react-native-animatable';
import {StyleSheet, Animated} from 'react-native';
import {Constants} from '../../helpers';
import {asBaseComponent} from '../../commons/new';
import {Colors, Spacings} from '../../style';
Expand Down Expand Up @@ -43,9 +42,6 @@ export interface FloatingButtonProps {
testID?: string;
}

const SHOW_ANIMATION_DELAY = 350;
const SHOW_ANIMATION_DURATION = 180;
const HIDE_ANIMATION_DURATION = 150;
const gradientImage = () => require('./gradient.png');

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

initialVisibility?: boolean;
firstLoad: boolean;
visibleAnimated: Animated.Value;

constructor(props: FloatingButtonProps) {
super(props);

this.initialVisibility = props.visible;
this.firstLoad = true;
this.visibleAnimated = new Animated.Value(Number(!!props.visible));
}

onAnimationEnd = () => {
this.setState({animating: false});
};
componentDidUpdate(prevProps: FloatingButtonProps) {
if (prevProps.visible !== this.props.visible) {
Animated.timing(this.visibleAnimated, {
toValue: Number(!!this.props.visible),
duration: 300,
useNativeDriver: true
}).start();
}
}

getAnimatedStyle = () => {
return {
opacity: this.visibleAnimated,
transform: [{translateY: this.visibleAnimated.interpolate({
inputRange: [0, 1],
outputRange: [Constants.screenHeight / 2, 0]
})}]
};
}

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

render() {
const {withoutAnimation, secondaryButton, visible} = this.props;
const Container = !withoutAnimation ? AnimatableView : View;

// NOTE: keep this.firstLoad as true as long as the visibility changed to true
this.firstLoad && !visible ? this.firstLoad = true : this.firstLoad = false;

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

return (
<Container
<View
pointerEvents="box-none"
style={[styles.animatedContainer, Constants.isAndroid && {zIndex: 99}]}
animation={!visible ? 'fadeOutDown' : 'fadeInUp'}
duration={SHOW_ANIMATION_DURATION}
delay={!visible ? HIDE_ANIMATION_DURATION : SHOW_ANIMATION_DELAY}
easing={'ease-out'}
onAnimationEnd={this.onAnimationEnd}
animated
style={[styles.container, this.getAnimatedStyle()]}
>
{this.renderOverlay()}
{this.renderButton()}
{secondaryButton && this.renderSecondaryButton()}
</Container>
</View>
);
}
}

const styles = StyleSheet.create({
animatedContainer: {
position: 'absolute',
left: 0,
right: 0,
container: {
...StyleSheet.absoluteFillObject,
top: undefined,
alignItems: 'center',
bottom: 0
zIndex: Constants.isAndroid ? 99 : undefined
},
image: {
...StyleSheet.absoluteFillObject,
Expand Down