-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathindex.native.js
100 lines (91 loc) · 1.95 KB
/
index.native.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/**
* External dependencies
*/
import {
Animated,
Easing,
Text,
TouchableWithoutFeedback,
View,
Dimensions,
} from 'react-native';
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { useEffect, useRef, useState } from '@wordpress/element';
/**
* Internal dependencies
*/
import styles from './style.scss';
const Tooltip = ( { onTooltipHidden } ) => {
const [ visible, setVisible ] = useState( true );
const animationValue = useRef( new Animated.Value( 0 ) ).current;
useEffect( () => {
startAnimation();
}, [ visible ] );
const onHide = () => {
setVisible( false );
};
const startAnimation = () => {
Animated.timing( animationValue, {
toValue: visible ? 1 : 0,
duration: visible ? 300 : 150,
useNativeDriver: true,
delay: visible ? 500 : 0,
easing: Easing.out( Easing.quad ),
} ).start( () => {
if ( ! visible && onTooltipHidden ) {
onTooltipHidden();
}
} );
};
const stylesOverlay = [
styles.overlay,
{ height: Dimensions.get( 'window' ).height },
];
return (
<>
<TouchableWithoutFeedback onPress={ onHide }>
<View style={ stylesOverlay } />
</TouchableWithoutFeedback>
<Animated.View
style={ {
opacity: animationValue,
transform: [
{
translateY: animationValue.interpolate( {
inputRange: [ 0, 1 ],
outputRange: [ visible ? 4 : -8, -8 ],
} ),
},
],
} }
>
<TouchableWithoutFeedback onPress={ onHide }>
<View
style={ [
styles.tooltip,
{
shadowColor: styles.tooltipShadow.color,
shadowOffset: {
width: 0,
height: 2,
},
shadowOpacity: 0.25,
shadowRadius: 2,
elevation: 2,
},
] }
>
<Text style={ styles.text }>
{ __( 'Try a starter layout' ) }
</Text>
<View style={ styles.arrow } />
</View>
</TouchableWithoutFeedback>
</Animated.View>
</>
);
};
export default Tooltip;