Commit e36d8d3
authored
[apple] Handle hover in
## Description
Follow up for [Android
PR](#4282)
which brings hover animations to iOS, macOS and tvOS platforms.
Of course docs/jsdoc will have to be unified between them, it will be
done after merging either of these.
<!--
Description and motivation for this PR.
Include 'Fixes #<number>' if this is fixing some issue.
-->
## Test plan
<details>
<summary>Tested on existing Touchable example and the code below:
</summary>
```tsx
import * as React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import {
GestureHandlerRootView,
Touchable as GHTouchable,
} from 'react-native-gesture-handler';
const SLOW = 700;
export default function App() {
const [pressCount, setPressCount] = React.useState(0);
const [disabled, setDisabled] = React.useState(false);
// Auto-toggle `disabled` every 2s so hover mask/resume can be tested with a
// mouse held still over the button — tapping a separate control would move
// the pointer off first. Hover and watch: the visual masks to default while
// disabled and resumes the hover look when re-enabled, pointer unmoved.
React.useEffect(() => {
const id = setInterval(() => setDisabled((d) => !d), 2000);
return () => clearInterval(id);
}, []);
return (
<GestureHandlerRootView style={styles.root}>
<Text style={styles.title}>Slow hover + press</Text>
<Text style={styles.hint}>
Use a mouse / stylus. Hover to grow & fade, press to shrink & fade more.
Transitions should never flicker through the default state.
</Text>
<View style={styles.stage}>
<GHTouchable
// Press (active) visuals
defaultOpacity={1}
defaultScale={1}
activeOpacity={0.3}
activeScale={0.8}
// Hover visuals
hoverOpacity={0.6}
hoverScale={1.2}
// Underlay so the change is extra visible
underlayColor="black"
defaultUnderlayOpacity={0}
hoverUnderlayOpacity={0.15}
activeUnderlayOpacity={0.35}
// Slow everything down: in/out for both tap and hover
animationDuration={{
tap: { in: SLOW, out: SLOW },
hover: { in: SLOW, out: SLOW },
}}
disabled={disabled}
style={styles.button}
onPress={() => setPressCount((c) => c + 1)}>
<Text style={styles.buttonText}>Hover / Press me</Text>
</GHTouchable>
</View>
<Text style={styles.counter}>
{disabled ? 'DISABLED' : 'enabled'} · Presses: {pressCount}
</Text>
</GestureHandlerRootView>
);
}
const styles = StyleSheet.create({
root: {
flex: 1,
backgroundColor: '#ecf0f1',
alignItems: 'center',
justifyContent: 'center',
padding: 24,
},
title: {
fontSize: 22,
fontWeight: 'bold',
color: '#2c3e50',
marginBottom: 8,
},
hint: {
fontSize: 14,
color: '#7f8c8d',
textAlign: 'center',
marginBottom: 40,
},
stage: {
width: 260,
height: 260,
alignItems: 'center',
justifyContent: 'center',
},
button: {
width: 180,
height: 180,
borderRadius: 24,
backgroundColor: '#8e44ad',
alignItems: 'center',
justifyContent: 'center',
},
buttonText: {
color: 'white',
fontSize: 18,
fontWeight: 'bold',
},
counter: {
marginTop: 40,
fontSize: 16,
color: '#2c3e50',
fontWeight: 'bold',
},
});
```
</details>Touchable (#4283)1 parent 52e082f commit e36d8d3
10 files changed
Lines changed: 358 additions & 131 deletions
File tree
- packages
- docs-gesture-handler/docs/components
- react-native-gesture-handler
- apple
- Handlers
- src/components
Lines changed: 1 addition & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
237 | 237 | | |
238 | 238 | | |
239 | 239 | | |
240 | | - | |
241 | 240 | | |
242 | | - | |
243 | 241 | | |
244 | 242 | | |
245 | 243 | | |
246 | 244 | | |
247 | 245 | | |
248 | 246 | | |
249 | 247 | | |
250 | | - | |
251 | 248 | | |
252 | | - | |
253 | 249 | | |
254 | 250 | | |
255 | 251 | | |
256 | 252 | | |
257 | 253 | | |
258 | 254 | | |
259 | 255 | | |
260 | | - | |
261 | 256 | | |
262 | | - | |
263 | 257 | | |
264 | 258 | | |
265 | 259 | | |
| |||
296 | 290 | | |
297 | 291 | | |
298 | 292 | | |
299 | | - | |
| 293 | + | |
300 | 294 | | |
301 | 295 | | |
302 | 296 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
| 23 | + | |
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| |||
Lines changed: 1 addition & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
89 | 89 | | |
90 | 90 | | |
91 | 91 | | |
92 | | - | |
93 | | - | |
94 | | - | |
| 92 | + | |
95 | 93 | | |
96 | 94 | | |
97 | 95 | | |
| |||
Lines changed: 0 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
11 | 10 | | |
12 | 11 | | |
Lines changed: 18 additions & 35 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | 16 | | |
21 | 17 | | |
22 | 18 | | |
23 | 19 | | |
24 | 20 | | |
25 | 21 | | |
26 | | - | |
| 22 | + | |
27 | 23 | | |
28 | | - | |
29 | 24 | | |
30 | 25 | | |
31 | 26 | | |
| |||
85 | 80 | | |
86 | 81 | | |
87 | 82 | | |
88 | | - | |
| 83 | + | |
89 | 84 | | |
90 | 85 | | |
91 | 86 | | |
| |||
97 | 92 | | |
98 | 93 | | |
99 | 94 | | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
106 | 98 | | |
107 | 99 | | |
108 | 100 | | |
109 | 101 | | |
110 | 102 | | |
111 | 103 | | |
112 | 104 | | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
118 | 108 | | |
119 | 109 | | |
120 | 110 | | |
121 | 111 | | |
122 | 112 | | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
129 | 116 | | |
130 | 117 | | |
131 | 118 | | |
132 | 119 | | |
133 | 120 | | |
134 | 121 | | |
135 | 122 | | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
141 | 126 | | |
142 | 127 | | |
143 | 128 | | |
144 | 129 | | |
145 | 130 | | |
146 | 131 | | |
147 | 132 | | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
153 | 136 | | |
154 | 137 | | |
155 | 138 | | |
156 | 139 | | |
157 | 140 | | |
158 | 141 | | |
159 | 142 | | |
160 | | - | |
| 143 | + | |
161 | 144 | | |
162 | 145 | | |
163 | 146 | | |
| |||
Lines changed: 5 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
380 | 380 | | |
381 | 381 | | |
382 | 382 | | |
383 | | - | |
384 | 383 | | |
385 | | - | |
386 | | - | |
387 | | - | |
388 | | - | |
389 | | - | |
390 | 384 | | |
| 385 | + | |
391 | 386 | | |
392 | 387 | | |
393 | 388 | | |
| |||
412 | 407 | | |
413 | 408 | | |
414 | 409 | | |
415 | | - | |
416 | | - | |
417 | | - | |
418 | | - | |
419 | | - | |
420 | | - | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
421 | 414 | | |
422 | 415 | | |
423 | 416 | | |
| |||
Lines changed: 7 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
40 | 45 | | |
41 | 46 | | |
42 | 47 | | |
| |||
54 | 59 | | |
55 | 60 | | |
56 | 61 | | |
| 62 | + | |
| 63 | + | |
57 | 64 | | |
58 | 65 | | |
59 | 66 | | |
| |||
0 commit comments