Skip to content

Commit bfa4f35

Browse files
authored
[iOS] Handle 0 duration animation correctly on Touchable (#4113)
## Description On iOS, setting `tapAnimationDuration` on Touchable didn't turn off the animation entirely, instead making it take 0.25s. CoreAnimation treats `0` in this case as `not set` and uses the default duration. This PR adds an explicit check for the `0` duration and applies the end state immediately for the underlay. ## Test plan ```jsx <Touchable style={{ width: 220, paddingVertical: 20, borderRadius: 12, backgroundColor: '#A0D5EF', alignItems: 'center', justifyContent: 'center', overflow: 'hidden', }} underlayColor={COLORS.RED} activeUnderlayOpacity={0.6} tapAnimationDuration={0} onPress={() => pushLog('onPress')}> <Text>Hold me</Text> </Touchable> ```
1 parent 3dca7f3 commit bfa4f35

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

packages/react-native-gesture-handler/apple/RNGestureHandlerButton.mm

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,17 @@ - (void)animateUnderlayToOpacity:(float)toOpacity duration:(NSTimeInterval)durat
173173
_underlayLayer.presentationLayer ? [_underlayLayer.presentationLayer opacity] : _underlayLayer.opacity;
174174
[_underlayLayer removeAllAnimations];
175175

176+
// CABasicAnimation with duration 0 resolves to the current CATransaction's
177+
// default duration (0.25s), not "no animation". Snap the value directly
178+
// with implicit actions disabled to get a true instant update.
179+
if (durationMs <= 0) {
180+
[CATransaction begin];
181+
[CATransaction setDisableActions:YES];
182+
_underlayLayer.opacity = toOpacity;
183+
[CATransaction commit];
184+
return;
185+
}
186+
176187
CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"opacity"];
177188
anim.fromValue = @(_underlayLayer.opacity);
178189
anim.toValue = @(toOpacity);

0 commit comments

Comments
 (0)