-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.tsx
51 lines (46 loc) · 1.12 KB
/
index.tsx
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
import React, {memo, useMemo, useRef} from 'react';
import {Animated, View} from 'react-native';
interface WithHighlightProps {
color?: string;
children?: React.ReactElement;
}
export const WithHighlight = memo(
({color = 'red', children}: WithHighlightProps) => {
const opacity = useRef(new Animated.Value(0)).current;
Animated.timing(opacity, {
toValue: 1,
duration: 150,
useNativeDriver: true,
}).start(() => {
Animated.timing(opacity, {
toValue: 0,
duration: 150,
useNativeDriver: true,
}).start();
});
const animatedStyle = useMemo(
() => ({
opacity: opacity.interpolate({
inputRange: [0, 1],
outputRange: [0, 1],
}),
borderColor: color,
borderWidth: 2,
position: 'absolute' as const,
top: 0,
left: 0,
right: 0,
bottom: 0,
}),
[opacity, color],
);
return useMemo(() => {
return (
<View>
<Animated.View style={animatedStyle} />
{children}
</View>
);
}, [animatedStyle, children]);
},
);