fix(animated-fab): keep icon attached when toggling iconMode on iOS#4940
Open
azizbecha wants to merge 1 commit into
Open
fix(animated-fab): keep icon attached when toggling iconMode on iOS#4940azizbecha wants to merge 1 commit into
azizbecha wants to merge 1 commit into
Conversation
The icon's transform.translateX was conditionally either an Animated.Value (dynamic) or a plain number (static). With useNativeDriver, switching the prop from an animated node to a plain value doesn't reliably release it from the native animated module, leaving the icon stuck at animFAB's last value and visually detached from the FAB pill after static -> dynamic -> static. Drive iconWrapper translateX through animFAB.interpolate(...) in all animateFrom/RTL branches, using a constant output range for the non-animating case, so the prop is always owned by the native driver.
|
Hey @azizbecha, thank you for your pull request 🤗. The documentation from this branch can be viewed here. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
On iOS only, AnimatedFAB's icon visually detaches from the FAB pill after the iconMode prop is switched from static → dynamic → static. The icon ends up floating off to the side, offset by roughly textWidth + borderRadius, instead of staying centered in the collapsed pill.
Root cause
In
getCombinedStyles()(src/components/FAB/utils.ts), the icon wrapper's transform.translateX was set conditionally to either an Animated.Value (dynamic mode) or a plain JS number (static mode):translateX: isIconStatic ? 0 : animFABAnimations run with
useNativeDriver: true. When a style prop that was being driven by the native animated module is replaced with a plain value, the native side doesn't reliably release ownership of that prop, so the icon's view stays stuck atanimFAB's last value (e.g. the extendeddistance). Combined with the always-appliedleft: -distance, the icon lands in the wrong place — detached from the pill. On Android this swap behaves fine, which is why the bug is iOS‑specific.Fix
Never swap a style prop between an
Animatednode and a plain value.iconWrapper.translateXis now driven byanimFAB.interpolate(...)in all animateFrom / RTL branches, using a constant output range for the non‑animating case, so the prop is always owned by the native driver and updates correctly on every iconMode / extended change. TheanimateFrom="left"+ RTL dynamic branch was also normalized to a constant interpolation to match its previous static value of -distance.No changes needed in
AnimatedFAB.tsx,left/rightstay plain numbers (never animated, so no swap problem there).Testing
yarn typescript— cleanyarn jest— full suite passes (901 passed, 164 snapshots; no snapshot churn — the existing snapshots cover iconMode="dynamic", whichis unchanged)
yarn lint— cleaniconMode static → dynamic → staticwith extend/collapse scrolling in between — icon stays centered in the collapsed pill. Also verified withanimateFrom="left".Screen.Recording.2026-05-11.at.4.31.56.PM.mov