fix: noop scrollRectToVisible on iOS#1336
Merged
kirillzyusko merged 4 commits intomainfrom Mar 4, 2026
Merged
Conversation
Contributor
📊 Package size report
|
This was referenced Mar 3, 2026
trcoffman
added a commit
to trcoffman/react-native-keyboard-controller
that referenced
this pull request
Mar 5, 2026
… iOS Implements a runtime swizzling fix for React Native 0.81+ bug where ScrollView's contentInset area fails to respond to touch events. This prevents users from initiating scroll gestures by touching the inset padding area, which is critical for chat UX patterns where contentInset positions messages at the top of the screen. ## Problem React Native's RCTScrollViewComponentView.betterHitTest returns the container view (self) instead of the underlying UIScrollView instance when the touch is in the contentInset area. This causes touch events to be intercepted by the container, preventing the scroll view from receiving gestures. Upstream issue: facebook/react-native#54123 ## Solution Uses Objective-C runtime method swizzling to override hitTest:withEvent: on the ScrollView's container view. The fix mirrors the upstream patch: - Calls the original hitTest:withEvent: implementation - When the result is self (the container) - which is the bug - dynamically finds and returns the UIScrollView child instead - Otherwise preserves the original result (subviews, nil, etc.) Key implementation detail: the UIScrollView is looked up dynamically at hit-test time rather than captured during swizzling. This ensures the fix works across React Native hot reloads and full refreshes where the view hierarchy is recreated but the swizzled class persists. Implementation follows the same pattern as PR kirillzyusko#1336's scrollRectToVisible fix: dynamic subclass creation with idempotent prefix check, applied lazily in didMoveToWindow. ## Benefits ✅ Users can now scroll by touching contentInset area ✅ Interactive content (Pressables, buttons, inputs) continues to work normally ✅ Survives React Native hot reloads and full refreshes ✅ Fixes chat UX where messages need top positioning via contentInset ✅ Non-breaking: defensive implementation returns early if structure unexpected ✅ Compatible with existing scrollRectToVisible noop fix ✅ Zero-cost for apps not using ClippingScrollView ✅ Provides immediate relief while waiting for upstream React Native fix ## Performance Considerations The dynamic scrollView lookup only executes when: - The original hitTest returns the container (empty space/contentInset area) - NOT when touching actual content (messages, buttons, etc.) Cost: iterating through container's direct subviews (typically 1-3 views) - UIScrollView + maybe scroll indicators - Just pointer comparisons and class checks - Negligible performance impact ## Risks and Considerations⚠️ Runtime swizzling: Fragile if React Native's view hierarchy changes Mitigation: Defensive checks, silently returns if container not found⚠️ Dynamic lookup on every hit test in contentInset area: Small overhead Mitigation: Only 1-3 subviews to check, only runs for empty space touches⚠️ React Native version variations: Different RN versions may have different hierarchies Mitigation: Graceful degradation - no fix applied but doesn't break⚠️ Calling original implementation: Assumes it's safe to invoke Mitigation: Standard ObjC pattern, same lifetime guarantees as the view ## Testing Recommendations - Test contentInset with top/bottom/left/right values - Verify touch in contentInset area initiates scroll - Verify interactive elements (Pressables, buttons, inputs) remain functional - Test with inverted ScrollViews (chat pattern) - Verify behavior persists after hot reload - Verify behavior persists after full refresh - Test keyboard interactions remain functional - Verify no console warnings - Test on iOS 17+ with React Native 0.81+ ## Technical Details Implementation in ClippingScrollViewDecoratorViewManager.mm: - Added KCApplyFixedHitTest() function that swizzles hitTest:withEvent: - Modified didMoveToWindow() to apply both fixes - Captures original IMP and calls it via function pointer - Conditional: if (result == self) lookup and return UIScrollView child - Dynamic lookup avoids stale references across RN refreshes - Uses KC_FixedHitTest_ prefix for idempotent check
trcoffman
added a commit
to trcoffman/react-native-keyboard-controller
that referenced
this pull request
Mar 5, 2026
… iOS Implements a runtime swizzling fix for React Native 0.81+ bug where ScrollView's contentInset area fails to respond to touch events. This prevents users from initiating scroll gestures by touching the inset padding area, which is critical for chat UX patterns where contentInset positions messages at the top of the screen. ## Problem React Native's RCTScrollViewComponentView.betterHitTest returns the container view (self) instead of the underlying UIScrollView instance when the touch is in the contentInset area. This causes touch events to be intercepted by the container, preventing the scroll view from receiving gestures. Upstream issue: facebook/react-native#54123 ## Solution Uses Objective-C runtime method swizzling to override hitTest:withEvent: on the ScrollView's container view. The fix mirrors the upstream patch: - Calls the original hitTest:withEvent: implementation - When the result is self (the container) - which is the bug - dynamically finds and returns the UIScrollView child instead - Otherwise preserves the original result (subviews, nil, etc.) Key implementation detail: the UIScrollView is looked up dynamically at hit-test time rather than captured during swizzling. This ensures the fix works across React Native hot reloads and full refreshes where the view hierarchy is recreated but the swizzled class persists. Implementation follows the same pattern as PR kirillzyusko#1336's scrollRectToVisible fix: dynamic subclass creation with idempotent prefix check, applied lazily in didMoveToWindow. ## Benefits ✅ Users can now scroll by touching contentInset area ✅ Interactive content (Pressables, buttons, inputs) continues to work normally ✅ Survives React Native hot reloads and full refreshes ✅ Fixes chat UX where messages need top positioning via contentInset ✅ Non-breaking: defensive implementation returns early if structure unexpected ✅ Compatible with existing scrollRectToVisible noop fix ✅ Zero-cost for apps not using ClippingScrollView ✅ Provides immediate relief while waiting for upstream React Native fix ## Performance Considerations The dynamic scrollView lookup only executes when: - The original hitTest returns the container (empty space/contentInset area) - NOT when touching actual content (messages, buttons, etc.) Cost: iterating through container's direct subviews (typically 1-3 views) - UIScrollView + maybe scroll indicators - Just pointer comparisons and class checks - Negligible performance impact ## Risks and Considerations⚠️ Runtime swizzling: Fragile if React Native's view hierarchy changes Mitigation: Defensive checks, silently returns if container not found⚠️ Dynamic lookup on every hit test in contentInset area: Small overhead Mitigation: Only 1-3 subviews to check, only runs for empty space touches⚠️ React Native version variations: Different RN versions may have different hierarchies Mitigation: Graceful degradation - no fix applied but doesn't break⚠️ Calling original implementation: Assumes it's safe to invoke Mitigation: Standard ObjC pattern, same lifetime guarantees as the view ## Testing Recommendations - Test contentInset with top/bottom/left/right values - Verify touch in contentInset area initiates scroll - Verify interactive elements (Pressables, buttons, inputs) remain functional - Test with inverted ScrollViews (chat pattern) - Verify behavior persists after hot reload - Verify behavior persists after full refresh - Test keyboard interactions remain functional - Verify no console warnings - Test on iOS 17+ with React Native 0.81+ ## Technical Details Implementation in ClippingScrollViewDecoratorViewManager.mm: - Added KCApplyFixedHitTest() function that swizzles hitTest:withEvent: - Modified didMoveToWindow() to apply both fixes - Captures original IMP and calls it via function pointer - Conditional: if (result == self) lookup and return UIScrollView child - Dynamic lookup avoids stale references across RN refreshes - Uses KC_FixedHitTest_ prefix for idempotent check
trcoffman
added a commit
to trcoffman/react-native-keyboard-controller
that referenced
this pull request
Mar 6, 2026
… iOS Implements a runtime swizzling fix for React Native 0.81+ bug where ScrollView's contentInset area fails to respond to touch events. This prevents users from initiating scroll gestures by touching the inset padding area, which is critical for chat UX patterns where contentInset positions messages at the top of the screen. ## Problem React Native's RCTScrollViewComponentView.betterHitTest returns the container view (self) instead of the underlying UIScrollView instance when the touch is in the contentInset area. This causes touch events to be intercepted by the container, preventing the scroll view from receiving gestures. Upstream issue: facebook/react-native#54123 ## Solution Uses Objective-C runtime method swizzling to override hitTest:withEvent: on the ScrollView's container view. The fix mirrors the upstream patch: - Calls the original hitTest:withEvent: implementation - When the result is self (the container) - which is the bug - dynamically finds and returns the UIScrollView child instead - Otherwise preserves the original result (subviews, nil, etc.) Key implementation detail: the UIScrollView is looked up dynamically at hit-test time rather than captured during swizzling. This ensures the fix works across React Native hot reloads and full refreshes where the view hierarchy is recreated but the swizzled class persists. Implementation follows the same pattern as PR kirillzyusko#1336's scrollRectToVisible fix: dynamic subclass creation with idempotent prefix check, applied lazily in didMoveToWindow. ## Benefits ✅ Users can now scroll by touching contentInset area ✅ Interactive content (Pressables, buttons, inputs) continues to work normally ✅ Survives React Native hot reloads and full refreshes ✅ Fixes chat UX where messages need top positioning via contentInset ✅ Non-breaking: defensive implementation returns early if structure unexpected ✅ Compatible with existing scrollRectToVisible noop fix ✅ Zero-cost for apps not using ClippingScrollView ✅ Provides immediate relief while waiting for upstream React Native fix ## Performance Considerations The dynamic scrollView lookup only executes when: - The original hitTest returns the container (empty space/contentInset area) - NOT when touching actual content (messages, buttons, etc.) Cost: iterating through container's direct subviews (typically 1-3 views) - UIScrollView + maybe scroll indicators - Just pointer comparisons and class checks - Negligible performance impact ## Risks and Considerations⚠️ Runtime swizzling: Fragile if React Native's view hierarchy changes Mitigation: Defensive checks, silently returns if container not found⚠️ Dynamic lookup on every hit test in contentInset area: Small overhead Mitigation: Only 1-3 subviews to check, only runs for empty space touches⚠️ React Native version variations: Different RN versions may have different hierarchies Mitigation: Graceful degradation - no fix applied but doesn't break⚠️ Calling original implementation: Assumes it's safe to invoke Mitigation: Standard ObjC pattern, same lifetime guarantees as the view ## Testing Recommendations - Test contentInset with top/bottom/left/right values - Verify touch in contentInset area initiates scroll - Verify interactive elements (Pressables, buttons, inputs) remain functional - Test with inverted ScrollViews (chat pattern) - Verify behavior persists after hot reload - Verify behavior persists after full refresh - Test keyboard interactions remain functional - Verify no console warnings - Test on iOS 17+ with React Native 0.81+ ## Technical Details Implementation in ClippingScrollViewDecoratorViewManager.mm: - Added KCApplyFixedHitTest() function that swizzles hitTest:withEvent: - Modified didMoveToWindow() to apply both fixes - Captures original IMP and calls it via function pointer - Conditional: if (result == self) lookup and return UIScrollView child - Dynamic lookup avoids stale references across RN refreshes - Uses KC_FixedHitTest_ prefix for idempotent check
trcoffman
added a commit
to trcoffman/react-native-keyboard-controller
that referenced
this pull request
Mar 6, 2026
… iOS Implements a runtime swizzling fix for React Native 0.81+ bug where ScrollView's contentInset area fails to respond to touch events. This prevents users from initiating scroll gestures by touching the inset padding area, which is critical for chat UX patterns where contentInset positions messages at the top of the screen. ## Problem React Native's RCTScrollViewComponentView.betterHitTest returns the container view (self) instead of the underlying UIScrollView instance when the touch is in the contentInset area. This causes touch events to be intercepted by the container, preventing the scroll view from receiving gestures. Upstream issue: facebook/react-native#54123 ## Solution Uses Objective-C runtime method swizzling to override hitTest:withEvent: on the ScrollView's container view. The fix mirrors the upstream patch: - Calls the original hitTest:withEvent: implementation - When the result is self (the container) - which is the bug - dynamically finds and returns the UIScrollView child instead - Otherwise preserves the original result (subviews, nil, etc.) Key implementation detail: the UIScrollView is looked up dynamically at hit-test time rather than captured during swizzling. This ensures the fix works across React Native hot reloads and full refreshes where the view hierarchy is recreated but the swizzled class persists. Implementation follows the same pattern as PR kirillzyusko#1336's scrollRectToVisible fix: dynamic subclass creation with idempotent prefix check, applied lazily in didMoveToWindow. ## Benefits ✅ Users can now scroll by touching contentInset area ✅ Interactive content (Pressables, buttons, inputs) continues to work normally ✅ Survives React Native hot reloads and full refreshes ✅ Fixes chat UX where messages need top positioning via contentInset ✅ Non-breaking: defensive implementation returns early if structure unexpected ✅ Compatible with existing scrollRectToVisible noop fix ✅ Zero-cost for apps not using ClippingScrollView ✅ Provides immediate relief while waiting for upstream React Native fix ## Performance Considerations The dynamic scrollView lookup only executes when: - The original hitTest returns the container (empty space/contentInset area) - NOT when touching actual content (messages, buttons, etc.) Cost: iterating through container's direct subviews (typically 1-3 views) - UIScrollView + maybe scroll indicators - Just pointer comparisons and class checks - Negligible performance impact ## Risks and Considerations⚠️ Runtime swizzling: Fragile if React Native's view hierarchy changes Mitigation: Defensive checks, silently returns if container not found⚠️ Dynamic lookup on every hit test in contentInset area: Small overhead Mitigation: Only 1-3 subviews to check, only runs for empty space touches⚠️ React Native version variations: Different RN versions may have different hierarchies Mitigation: Graceful degradation - no fix applied but doesn't break⚠️ Calling original implementation: Assumes it's safe to invoke Mitigation: Standard ObjC pattern, same lifetime guarantees as the view ## Testing Recommendations - Test contentInset with top/bottom/left/right values - Verify touch in contentInset area initiates scroll - Verify interactive elements (Pressables, buttons, inputs) remain functional - Test with inverted ScrollViews (chat pattern) - Verify behavior persists after hot reload - Verify behavior persists after full refresh - Test keyboard interactions remain functional - Verify no console warnings - Test on iOS 17+ with React Native 0.81+ ## Technical Details Implementation in ClippingScrollViewDecoratorViewManager.mm: - Added KCApplyFixedHitTest() function that swizzles hitTest:withEvent: - Modified didMoveToWindow() to apply both fixes - Captures original IMP and calls it via function pointer - Conditional: if (result == self) lookup and return UIScrollView child - Dynamic lookup avoids stale references across RN refreshes - Uses KC_FixedHitTest_ prefix for idempotent check
trcoffman
added a commit
to trcoffman/react-native-keyboard-controller
that referenced
this pull request
Mar 9, 2026
… iOS Implements a runtime swizzling fix for React Native 0.81+ bug where ScrollView's contentInset area fails to respond to touch events. This prevents users from initiating scroll gestures by touching the inset padding area, which is critical for chat UX patterns where contentInset positions messages at the top of the screen. ## Problem React Native's RCTScrollViewComponentView.betterHitTest returns the container view (self) instead of the underlying UIScrollView instance when the touch is in the contentInset area. This causes touch events to be intercepted by the container, preventing the scroll view from receiving gestures. Upstream issue: facebook/react-native#54123 ## Solution Uses Objective-C runtime method swizzling to override hitTest:withEvent: on the ScrollView's container view. The fix mirrors the upstream patch: - Calls the original hitTest:withEvent: implementation - When the result is self (the container) - which is the bug - dynamically finds and returns the UIScrollView child instead - Otherwise preserves the original result (subviews, nil, etc.) Key implementation detail: the UIScrollView is looked up dynamically at hit-test time rather than captured during swizzling. This ensures the fix works across React Native hot reloads and full refreshes where the view hierarchy is recreated but the swizzled class persists. Implementation follows the same pattern as PR kirillzyusko#1336's scrollRectToVisible fix: dynamic subclass creation with idempotent prefix check, applied lazily in didMoveToWindow. ## Benefits ✅ Users can now scroll by touching contentInset area ✅ Interactive content (Pressables, buttons, inputs) continues to work normally ✅ Survives React Native hot reloads and full refreshes ✅ Fixes chat UX where messages need top positioning via contentInset ✅ Non-breaking: defensive implementation returns early if structure unexpected ✅ Compatible with existing scrollRectToVisible noop fix ✅ Zero-cost for apps not using ClippingScrollView ✅ Provides immediate relief while waiting for upstream React Native fix ## Performance Considerations The dynamic scrollView lookup only executes when: - The original hitTest returns the container (empty space/contentInset area) - NOT when touching actual content (messages, buttons, etc.) Cost: iterating through container's direct subviews (typically 1-3 views) - UIScrollView + maybe scroll indicators - Just pointer comparisons and class checks - Negligible performance impact ## Risks and Considerations⚠️ Runtime swizzling: Fragile if React Native's view hierarchy changes Mitigation: Defensive checks, silently returns if container not found⚠️ Dynamic lookup on every hit test in contentInset area: Small overhead Mitigation: Only 1-3 subviews to check, only runs for empty space touches⚠️ React Native version variations: Different RN versions may have different hierarchies Mitigation: Graceful degradation - no fix applied but doesn't break⚠️ Calling original implementation: Assumes it's safe to invoke Mitigation: Standard ObjC pattern, same lifetime guarantees as the view ## Testing Recommendations - Test contentInset with top/bottom/left/right values - Verify touch in contentInset area initiates scroll - Verify interactive elements (Pressables, buttons, inputs) remain functional - Test with inverted ScrollViews (chat pattern) - Verify behavior persists after hot reload - Verify behavior persists after full refresh - Test keyboard interactions remain functional - Verify no console warnings - Test on iOS 17+ with React Native 0.81+ ## Technical Details Implementation in ClippingScrollViewDecoratorViewManager.mm: - Added KCApplyFixedHitTest() function that swizzles hitTest:withEvent: - Modified didMoveToWindow() to apply both fixes - Captures original IMP and calls it via function pointer - Conditional: if (result == self) lookup and return UIScrollView child - Dynamic lookup avoids stale references across RN refreshes - Uses KC_FixedHitTest_ prefix for idempotent check
5 tasks
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.
📜 Description
Make
scrollRectToVisibleofReactScrollViewno-op.💡 Motivation and Context
This issue became visible after #797
Before we were modifying
heightof fake view. AndscrollRectToVisibleis not sensitive to this:But since we started to modify
contentInsetthis function now can also "scroll" and this causes strange effect such as #1331This is a
ReactScrollViewbuilt-in solution for "avoiding"TextInput. Logs:Which we can evaluate as:
So UIKit scrolls by 738.4 - 717.7 ≈ 20.7px 😡 I think this effect is totally undesirable for
KeyboardAwareScrollVIew/ClippingScrollViewsince we control scroll position on our own, so via swizzling (this is the only one option at the moment, correct option would be to add a new prop toScrollViewinreact-native) I make this method a no-op.I checked and functionality like "tap-status-bar-to-scroll" works well. So I think it's safe to have this fix 🤞
Closes #1331
📢 Changelog
JS
ClippingScrollViewreal view on iOS;iOS
ClippingScrollViewshadow node;scrollRectToVisibleto no-op;Android
ClippingScrollViewshadow node;🤔 How Has This Been Tested?
Tested manually on iPhone 17 Pro (iOS 26.2).
📸 Screenshots (if appropriate):
scroll-rect-to-visible-no-op.mov
📝 Checklist