@@ -39,12 +39,6 @@ export interface FloatingButtonProps {
39
39
hideBackgroundOverlay ?: boolean ;
40
40
}
41
41
42
- interface State {
43
- shouldAnimateHide ?: boolean ;
44
- isVisible ?: boolean ;
45
- animating ?: boolean ;
46
- }
47
-
48
42
const SHOW_ANIMATION_DELAY = 350 ;
49
43
const SHOW_ANIMATION_DURATION = 180 ;
50
44
const HIDE_ANIMATION_DURATION = 150 ;
@@ -57,44 +51,21 @@ const gradientImage = () => require('./gradient.png');
57
51
* @extends : Button
58
52
* @extendsLink : https://github.com/wix/react-native-ui-lib/blob/master/src/components/button/index.js
59
53
*/
60
- class FloatingButton extends PureComponent < FloatingButtonProps , State > {
54
+ class FloatingButton extends PureComponent < FloatingButtonProps > {
61
55
static displayName = 'FloatingButton' ;
62
56
57
+ initialVisibility ?: boolean ;
58
+ firstLoad : boolean ;
59
+
63
60
constructor ( props : FloatingButtonProps ) {
64
61
super ( props ) ;
65
62
66
- this . state = {
67
- shouldAnimateHide : false ,
68
- isVisible : props . visible ,
69
- animating : false
70
- } ;
63
+ this . initialVisibility = props . visible ;
64
+ this . firstLoad = true ;
71
65
}
72
66
73
- UNSAFE_componentWillReceiveProps ( nextProps : FloatingButtonProps ) {
74
- const { withoutAnimation} = this . props ;
75
- const propsVisible = this . props . visible ;
76
- const nextVisible = nextProps . visible ;
77
-
78
- if ( ! withoutAnimation ) {
79
- const shouldStartAnimation =
80
- ! this . state . isVisible && nextVisible && ! this . state . animating ;
81
- if ( shouldStartAnimation ) {
82
- this . setState ( { animating : true } ) ;
83
-
84
- if ( nextProps . duration ) {
85
- setTimeout ( ( ) => {
86
- this . setState ( { isVisible : false , shouldAnimateHide : true } ) ;
87
- } , nextProps . duration ) ;
88
- }
89
- }
90
- }
91
-
92
- this . setState ( {
93
- shouldAnimateHide : withoutAnimation
94
- ? false
95
- : ! nextVisible && propsVisible ,
96
- isVisible : nextVisible
97
- } ) ;
67
+ componentDidMount ( ) {
68
+ this . firstLoad = false ;
98
69
}
99
70
100
71
onAnimationEnd = ( ) => {
@@ -143,22 +114,24 @@ class FloatingButton extends PureComponent<FloatingButtonProps, State> {
143
114
}
144
115
145
116
render ( ) {
146
- const { withoutAnimation, secondaryButton} = this . props ;
147
- const { isVisible, shouldAnimateHide} = this . state ;
117
+ const { withoutAnimation, secondaryButton, visible} = this . props ;
148
118
const Container = ! withoutAnimation ? AnimatableView : View ;
149
119
150
- // NOTE: Don't show if it should not be visible and it was already animated
151
- if ( ! isVisible && ! shouldAnimateHide ) {
120
+ // NOTE: On first load, don't show if it should not be visible
121
+ if ( this . firstLoad === true && ! this . initialVisibility ) {
122
+ return false ;
123
+ }
124
+ if ( ! visible && withoutAnimation ) {
152
125
return false ;
153
126
}
154
127
155
128
return (
156
129
< Container
157
130
pointerEvents = "box-none"
158
131
style = { [ styles . animatedContainer , Constants . isAndroid && { zIndex : 99 } ] }
159
- animation = { ! isVisible ? 'fadeOutDown' : 'fadeInUp' }
132
+ animation = { ! visible ? 'fadeOutDown' : 'fadeInUp' }
160
133
duration = { SHOW_ANIMATION_DURATION }
161
- delay = { ! isVisible ? HIDE_ANIMATION_DURATION : SHOW_ANIMATION_DELAY }
134
+ delay = { ! visible ? HIDE_ANIMATION_DURATION : SHOW_ANIMATION_DELAY }
162
135
easing = { 'ease-out' }
163
136
onAnimationEnd = { this . onAnimationEnd }
164
137
>
0 commit comments