Fix iOS scrollEnabled hardcoded to true #1043
Open
+2
−1
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
Motivation
Fixes a bug where the
scrollEnabled={false}prop would work correctly on the first render, but on subsequent renders, the scroll would always be enabled even when the prop remainedfalse.Root Cause
The
prepareForRecyclemethod was hardcoding_scrollEnabled = YES;when the component was recycled. After recycling, if the prop value didn't change between renders, theupdatePropsmethod wouldn't update_scrollEnabled(because it only updates when the value changes), leaving it with the incorrect hardcoded value.Solution
Removed hardcoded reset: Removed the hardcoded
_scrollEnabled = YES;reset from theprepareForRecyclemethod (line 133).Added initialization on first update: Added
_scrollEnabledinitialization in theupdatePropsmethod when_currentIndex == -1(first update after recycling), ensuring the prop value is always applied correctly on initial mount and after component recycling, even if the prop value hasn't changed from the previous instance.The changes ensure that:
initialPageis handled)updatePropsproperly updates it when the prop value changesAreas Impacted
RNCPagerViewComponentView.mm)scrollEnabledprop handlingTest Plan
Prerequisites
react-native-pager-viewinstalledSteps to Reproduce (Before Fix)
scrollEnabled={false}propfalseVerification (After Fix)
scrollEnabled={false}on a PagerView componentCompatibility
Note: This fix is iOS-specific. Android implementation was not affected by this issue.
Checklist
README.md(if needed)