1
1
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' ;
4
3
import { Constants } from '../../helpers' ;
5
4
import { asBaseComponent } from '../../commons/new' ;
6
5
import { Colors , Spacings } from '../../style' ;
@@ -43,9 +42,6 @@ export interface FloatingButtonProps {
43
42
testID ?: string ;
44
43
}
45
44
46
- const SHOW_ANIMATION_DELAY = 350 ;
47
- const SHOW_ANIMATION_DURATION = 180 ;
48
- const HIDE_ANIMATION_DURATION = 150 ;
49
45
const gradientImage = ( ) => require ( './gradient.png' ) ;
50
46
51
47
/**
@@ -60,17 +56,35 @@ class FloatingButton extends PureComponent<FloatingButtonProps> {
60
56
61
57
initialVisibility ?: boolean ;
62
58
firstLoad : boolean ;
59
+ visibleAnimated : Animated . Value ;
63
60
64
61
constructor ( props : FloatingButtonProps ) {
65
62
super ( props ) ;
66
63
67
64
this . initialVisibility = props . visible ;
68
65
this . firstLoad = true ;
66
+ this . visibleAnimated = new Animated . Value ( Number ( ! ! props . visible ) ) ;
69
67
}
70
68
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
+ }
74
88
75
89
renderButton ( ) {
76
90
const { bottomMargin, button, secondaryButton} = this . props ;
@@ -115,8 +129,6 @@ class FloatingButton extends PureComponent<FloatingButtonProps> {
115
129
116
130
render ( ) {
117
131
const { withoutAnimation, secondaryButton, visible} = this . props ;
118
- const Container = ! withoutAnimation ? AnimatableView : View ;
119
-
120
132
// NOTE: keep this.firstLoad as true as long as the visibility changed to true
121
133
this . firstLoad && ! visible ? this . firstLoad = true : this . firstLoad = false ;
122
134
@@ -129,30 +141,25 @@ class FloatingButton extends PureComponent<FloatingButtonProps> {
129
141
}
130
142
131
143
return (
132
- < Container
144
+ < View
133
145
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 ( ) ] }
140
148
>
141
149
{ this . renderOverlay ( ) }
142
150
{ this . renderButton ( ) }
143
151
{ secondaryButton && this . renderSecondaryButton ( ) }
144
- </ Container >
152
+ </ View >
145
153
) ;
146
154
}
147
155
}
148
156
149
157
const styles = StyleSheet . create ( {
150
- animatedContainer : {
151
- position : 'absolute' ,
152
- left : 0 ,
153
- right : 0 ,
158
+ container : {
159
+ ...StyleSheet . absoluteFillObject ,
160
+ top : undefined ,
154
161
alignItems : 'center' ,
155
- bottom : 0
162
+ zIndex : Constants . isAndroid ? 99 : undefined
156
163
} ,
157
164
image : {
158
165
...StyleSheet . absoluteFillObject ,
0 commit comments