fix(ios): skip programmatic selectRow while user is scrolling (Fabric crash)#674
Open
raid5 wants to merge 1 commit into
Open
fix(ios): skip programmatic selectRow while user is scrolling (Fabric crash)#674raid5 wants to merge 1 commit into
raid5 wants to merge 1 commit into
Conversation
On the New Architecture (Fabric), a controlled Picker can crash with EXC_BAD_ACCESS during a fast fling. Every committed value flows through -setSelectedIndex:, which calls -selectRow:animated:. Mid-gesture, lagging React state echoes back a stale index that re-drives the live wheel, re-entering UIPickerView's suspended update cycle during UIKit hit-testing. Add an -isUserScrolling helper that inspects the picker's backing UIScrollView(s) (isTracking/isDragging/isDecelerating) and bail out of -setSelectedIndex: while the user is actively manipulating the wheel. -didSelectRow: already keeps the internal index accurate, so idle programmatic resets continue to work.
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
Fixes an intermittent native crash on iOS when a controlled
Pickeris scrolled quickly under the New Architecture (Fabric). The fix skips the programmatic re-selection of a row while the user is physically dragging/flinging the wheel.Problem
With a controlled picker (
selectedValuedriven by React state), fast scrolling can crash the app withEXC_BAD_ACCESSinside UIKit's_endSuspendingUpdates. It reproduces reliably on Fabric builds and does not occur on the old architecture, because the two architectures batch prop updates differently.Repro:
PickerwhoseselectedValueis a controlled React state value updated fromonValueChange.Root cause
Every committed
selectedValueflows into-[RNCPicker setSelectedIndex:], which calls-selectRow:animated:. During a fling, React state lags the live native wheel and echoes back a now-stale index. That stale value re-drivesselectRow:in the middle of the active gesture, re-enteringUIPickerView's suspended update cycle while UIKit is hit-testing — hence the crash. On the old architecture the update batching happened differently, so only New Architecture builds are affected.Fix
-isUserScrollinghelper that walks the picker's internal subview hierarchy and returns whether any backingUIScrollViewis currentlyisTracking,isDragging, orisDecelerating.-setSelectedIndex:that skips the programmatic re-drive while the user is actively manipulating the wheel.-didSelectRow:already keeps_selectedIndexin sync with the user's gesture, so no selection state is lost; programmatic resets performed while the wheel is idle continue to behave exactly as before. The change is confined toios/RNCPicker.mmand does not alter the JS API.Testing
This change has been running in a shipping iOS app built with the New Architecture, where it eliminated a recurring
EXC_BAD_ACCESSinside UIKit's_endSuspendingUpdatesduring fast scrolling of a controlled picker.selectedValuecontinue to move the wheel as expected on both the old and New Architecture.ios/RNCPicker.mmand does not alter the JS API, so the existing JS test suite is unaffected; the repo has no Objective-C unit-test harness to extend, so no automated test was added.This fix was prepared with AI assistance and reviewed by a human before submission.