From 84f2d251245e8dd9770fead9576f4b9418d97b06 Mon Sep 17 00:00:00 2001 From: Kacper Rozniata <56474758+krozniata@users.noreply.github.com> Date: Mon, 9 Sep 2024 16:41:49 -0700 Subject: [PATCH] fix(iOS): fix animating `Switch` component value change (#46173) 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: https://github.com/facebook/react-native/pull/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 --- .../Mounting/ComponentViews/Switch/RCTSwitchComponentView.mm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/react-native/React/Fabric/Mounting/ComponentViews/Switch/RCTSwitchComponentView.mm b/packages/react-native/React/Fabric/Mounting/ComponentViews/Switch/RCTSwitchComponentView.mm index 941ad9b7f09..c3d44953ef3 100644 --- a/packages/react-native/React/Fabric/Mounting/ComponentViews/Switch/RCTSwitchComponentView.mm +++ b/packages/react-native/React/Fabric/Mounting/ComponentViews/Switch/RCTSwitchComponentView.mm @@ -63,7 +63,6 @@ using namespace facebook::react; if (oldSwitchProps.value != newSwitchProps.value) { BOOL shouldAnimate = _isInitialValueSet == YES; [_switchView setOn:newSwitchProps.value animated:shouldAnimate]; - _isInitialValueSet = YES; } // `disabled` @@ -86,6 +85,8 @@ using namespace facebook::react; _switchView.thumbTintColor = RCTUIColorFromSharedColor(newSwitchProps.thumbTintColor); } + _isInitialValueSet = YES; + [super updateProps:props oldProps:oldProps]; }