Commit 38025e7
authored
[Native] Snap
## Description
Updates how `Touchable` handles animations:
- On Android, when the animation would take less than a single frame,
apply the values immediately. `ObjectAnimator` would run the animation
on the next frame, and if a new animation was started immediately after
(like a quick tap in a scroll view), it would read the "resting" state
instead of the one just applied.
- On iOS, do the same thing and read values from the presentation layer
only when an animation is running (similarly to Android, the animation
would start on the next frame).
- On Android, it also changes `LinearOutSlowInInterpolator` to
`FastOutSlowInInterpolator` to better match the animation curve from web
and iOS
## Test plan
|-|Before|After|
|-|-|-|
|Android|<video
src="https://github.com/user-attachments/assets/be32d3e3-8e6a-4697-8c53-5f727c7cb6d4"
/>|<video
src="https://github.com/user-attachments/assets/4b025d79-3caf-42da-b317-f13f56c83927"
/>|
|iOS|<video
src="https://github.com/user-attachments/assets/dc6199db-a3e8-4c3d-ab41-8ec90d0ed829"
/>|<video
src="https://github.com/user-attachments/assets/9ad97e93-c66f-4146-9f3c-114c9e381130"
/>|
(Yes, iOS before is being pressed on constantly, it's just animating
default -> default)
```jsx
import * as React from 'react';
import { StyleSheet } from 'react-native';
import { ScrollView, Touchable } from 'react-native-gesture-handler';
export default function TapToLikeExample() {
return (
<ScrollView
style={styles.container}
contentContainerStyle={{ flexGrow: 1 }}>
<Touchable
style={{ width: 200, height: 40, backgroundColor: 'red' }}
activeOpacity={0.2}
animationDuration={{ in: 0, out: 250 }}></Touchable>
</ScrollView>
);
}
const styles = StyleSheet.create({
container: {
gap: 24,
padding: 24,
},
});
```Touchable state on sub-frame animations (#4181)1 parent f2159b8 commit 38025e7
3 files changed
Lines changed: 109 additions & 9 deletions
File tree
- packages/react-native-gesture-handler
- android/src/main/java/com/swmansion/gesturehandler/react
- apple
Lines changed: 21 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
| |||
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
Lines changed: 24 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
| 26 | + | |
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| |||
546 | 546 | | |
547 | 547 | | |
548 | 548 | | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
549 | 571 | | |
550 | 572 | | |
551 | 573 | | |
| |||
560 | 582 | | |
561 | 583 | | |
562 | 584 | | |
563 | | - | |
| 585 | + | |
564 | 586 | | |
565 | 587 | | |
566 | 588 | | |
| |||
Lines changed: 64 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
258 | 258 | | |
259 | 259 | | |
260 | 260 | | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
261 | 277 | | |
262 | 278 | | |
263 | 279 | | |
264 | 280 | | |
265 | 281 | | |
266 | | - | |
267 | | - | |
268 | | - | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
269 | 292 | | |
270 | 293 | | |
271 | | - | |
272 | | - | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
273 | 313 | | |
| 314 | + | |
274 | 315 | | |
275 | 316 | | |
276 | 317 | | |
| |||
285 | 326 | | |
286 | 327 | | |
287 | 328 | | |
288 | | - | |
289 | | - | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
290 | 346 | | |
| 347 | + | |
291 | 348 | | |
292 | 349 | | |
293 | 350 | | |
| |||
0 commit comments