@@ -14,7 +14,7 @@ import { BlurView } from '@react-native-community/blur';
14
14
/**
15
15
* WordPress dependencies
16
16
*/
17
- import { useEffect , useRef , Platform } from '@wordpress/element' ;
17
+ import { useEffect , useRef , useCallback , Platform } from '@wordpress/element' ;
18
18
import { usePreferredColorSchemeStyle } from '@wordpress/compose' ;
19
19
20
20
/**
@@ -30,40 +30,37 @@ const Notice = ( { onNoticeHidden, content, id, status } ) => {
30
30
const timer = useRef ( null ) ;
31
31
32
32
useEffect ( ( ) => {
33
- startAnimation ( ) ;
34
-
35
- return ( ) => {
36
- clearTimeout ( timer ?. current ) ;
37
- } ;
38
- } , [ ] ) ;
39
-
40
- function onHide ( ) {
33
+ // start animation
41
34
Animated . timing ( animationValue , {
42
- toValue : 0 ,
43
- duration : 150 ,
35
+ toValue : 1 ,
36
+ duration : 300 ,
44
37
useNativeDriver : true ,
45
38
easing : Easing . out ( Easing . quad ) ,
46
39
} ) . start ( ( { finished } ) => {
47
40
if ( finished && onNoticeHidden ) {
48
- onNoticeHidden ( id ) ;
41
+ timer . current = setTimeout ( ( ) => {
42
+ onHide ( ) ;
43
+ } , HIDE_TIMER ) ;
49
44
}
50
45
} ) ;
51
- }
52
46
53
- function startAnimation ( ) {
47
+ return ( ) => {
48
+ clearTimeout ( timer ?. current ) ;
49
+ } ;
50
+ } , [ animationValue , onHide , onNoticeHidden ] ) ;
51
+
52
+ const onHide = useCallback ( ( ) => {
54
53
Animated . timing ( animationValue , {
55
- toValue : 1 ,
56
- duration : 300 ,
54
+ toValue : 0 ,
55
+ duration : 150 ,
57
56
useNativeDriver : true ,
58
57
easing : Easing . out ( Easing . quad ) ,
59
58
} ) . start ( ( { finished } ) => {
60
59
if ( finished && onNoticeHidden ) {
61
- timer . current = setTimeout ( ( ) => {
62
- onHide ( ) ;
63
- } , HIDE_TIMER ) ;
60
+ onNoticeHidden ( id ) ;
64
61
}
65
62
} ) ;
66
- }
63
+ } , [ animationValue , onNoticeHidden , id ] ) ;
67
64
68
65
const noticeSolidStyles = usePreferredColorSchemeStyle (
69
66
styles . noticeSolid ,
0 commit comments