-
Notifications
You must be signed in to change notification settings - Fork 119
/
Moti.PressableTooltip.tsx
95 lines (85 loc) 路 1.72 KB
/
Moti.PressableTooltip.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
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
import React from 'react'
import { StyleSheet, View } from 'react-native'
import { MotiImage } from 'moti'
import {
mergeAnimateProp,
MotiPressable,
useMotiPressable,
useMotiPressableTransition,
} from 'moti/interactions'
function Logo() {
const state = useMotiPressable(
'logo',
({ pressed, hovered }) => {
'worklet'
return {
opacity: pressed || hovered ? 0.5 : 1,
}
},
[]
)
const transition = useMotiPressableTransition(({ pressed }) => {
'worklet'
return {
delay: pressed ? 0 : 100,
}
})
return (
<MotiImage
source={{
uri: beatGigLogo,
}}
state={state}
style={styles.logo}
resizeMode="contain"
// transition={useDerivedValue(() => ({ type: 'timing' }), [])}
transition={transition}
/>
)
}
function App() {
return (
<MotiPressable
animate={(state) => {
'worklet'
return mergeAnimateProp(state, {
scale: state.pressed ? 0.9 : 1,
})
}}
id="logo"
style={styles.shape}
>
<Logo />
</MotiPressable>
)
}
export default function HelloWorld() {
return (
<View style={styles.container}>
<App />
</View>
)
}
const styles = StyleSheet.create({
shape: {
justifyContent: 'center',
height: 180,
width: 250,
borderRadius: 25,
marginRight: 10,
backgroundColor: 'black',
},
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
flexDirection: 'row',
backgroundColor: 'black',
},
logo: {
alignSelf: 'center',
height: 50,
width: 200,
},
})
const beatGigLogo = `https://beatgig.com/_next/static/images/beatgig-256-a2ce12989084a7604b2cb2994e29fccb.png`