Commit f071853
authored
[iOS] Fix
## Description
When the layout of the touchable changed during the animation, it
resulted in the end frame of the view being wrong.
This PR updates the button behavior in two ways:
1. Not applying the resting state if none of the resting state props
were changed
2. Saving the in-flight transform during a frame update and restoring it
after
## Test plan
|Before|After|
|-|-|
|<video
src="https://github.com/user-attachments/assets/a631179e-1cef-4689-8d61-5d0a2bf08b65"
/>|<video
src="https://github.com/user-attachments/assets/827574cd-f9eb-4f06-a45f-fd304fe9998c"
/>|
<details>
<summary>Expand</summary>
```jsx
import React, { useState } from 'react';
import { StyleSheet, Text, View } from 'react-native';
import { Touchable } from 'react-native-gesture-handler';
export default function EmptyExample() {
const [isActive, setIsActive] = useState(false);
return (
<View style={styles.container}>
<Touchable
style={[styles.button, isActive && styles.buttonActive]}
onPress={() => console.log('pressed')}
onPressIn={() => setIsActive(true)}
onPressOut={() => setIsActive(false)}
activeScale={1.2}>
<Text style={styles.label}>{isActive ? 'Highlighted' : 'Press me'}</Text>
</Touchable>
<Text style={styles.hint}>
Press the button, then slowly drag your pointer away from it.
</Text>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
padding: 24,
gap: 24,
},
button: {
backgroundColor: '#ddd',
paddingHorizontal: 32,
paddingVertical: 16,
borderRadius: 8,
},
buttonActive: {
backgroundColor: '#f97316',
},
label: {
fontSize: 20,
fontWeight: '600',
},
hint: {
textAlign: 'center',
opacity: 0.6,
fontSize: 14,
},
});
```
</details>Touchable animation ending in the wrong state (#4099)1 parent ce6db39 commit f071853
1 file changed
Lines changed: 40 additions & 3 deletions
Lines changed: 40 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
111 | 111 | | |
112 | 112 | | |
113 | 113 | | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
114 | 131 | | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
115 | 141 | | |
116 | 142 | | |
117 | 143 | | |
| |||
134 | 160 | | |
135 | 161 | | |
136 | 162 | | |
137 | | - | |
138 | | - | |
139 | 163 | | |
140 | 164 | | |
141 | 165 | | |
| |||
243 | 267 | | |
244 | 268 | | |
245 | 269 | | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
246 | 281 | | |
247 | 282 | | |
248 | 283 | | |
| |||
279 | 314 | | |
280 | 315 | | |
281 | 316 | | |
282 | | - | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
283 | 320 | | |
284 | 321 | | |
285 | 322 | | |
| |||
0 commit comments