Skip to content

Commit

Permalink
fix(iOS): fix animating Switch component value change (#46173)
Browse files Browse the repository at this point in the history
Summary:
This PR fixes animating controlled `Switch` component when it's initial value is set to `false`

When initial value was set to `false`, `_isInitialValueSet` flag wasn't changed to `YES`, because `oldSwitchProps.value` &`newSwitchProps.value` were equal, which resulted in controlled `Switch` component being updated without animation on first value change

This PR fixes it by moving setting `_isInitialValueSet` flag to the end of `updateProps` method

## Changelog:

[IOS] [FIXED] - Fix animating Switch component value change in Fabric

Pull Request resolved: #46173

Test Plan:
1. Open `Switch` example in `RNTester`
2. In `Change events can be detected` section press switch that is `off` by default
3. Switch under it should change with animation

Reviewed By: javache

Differential Revision: D62377771

Pulled By: cipolleschi

fbshipit-source-id: 0213287c935db79a199b086ebb36a6979df03913
  • Loading branch information
krozniata authored and facebook-github-bot committed Sep 9, 2024
1 parent 95af340 commit 84f2d25
Showing 1 changed file with 2 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ - (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &
if (oldSwitchProps.value != newSwitchProps.value) {
BOOL shouldAnimate = _isInitialValueSet == YES;
[_switchView setOn:newSwitchProps.value animated:shouldAnimate];
_isInitialValueSet = YES;
}

// `disabled`
Expand All @@ -86,6 +85,8 @@ - (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &
_switchView.thumbTintColor = RCTUIColorFromSharedColor(newSwitchProps.thumbTintColor);
}

_isInitialValueSet = YES;

[super updateProps:props oldProps:oldProps];
}

Expand Down

0 comments on commit 84f2d25

Please sign in to comment.