feat: minimumContentPadding prop on KeyboardChatScrollView#1344
Merged
kirillzyusko merged 33 commits intokirillzyusko:mainfrom Mar 10, 2026
Merged
feat: minimumContentPadding prop on KeyboardChatScrollView#1344kirillzyusko merged 33 commits intokirillzyusko:mainfrom
minimumContentPadding prop on KeyboardChatScrollView#1344kirillzyusko merged 33 commits intokirillzyusko:mainfrom
Conversation
Contributor
📊 Package size report
|
06cc264 to
629b694
Compare
kirillzyusko
reviewed
Mar 6, 2026
kirillzyusko
reviewed
Mar 6, 2026
fb9d88f to
50a444c
Compare
|
The latest updates on your projects. Learn more about Argos notifications ↗︎
|
kirillzyusko
reviewed
Mar 7, 2026
minimumContentPadding prop on KeyboardChatScrollView
Add a blankSize prop that will ensure that it's possible to put the latest user message right at the top of the screen when building an AI chat app. KeyboardChatLegendList: Fix imports after reverting to beta.32
Fix Android keyboard close/open asymmetry and apply binary blank absorption Two changes to the Android useChatKeyboard hook: 1. Apply the same binary blank absorption from the iOS fix: only absorb blank space when fully visible (visibleFraction >= 1), otherwise shift content by the full keyboard amount. Previously Android used linear scaling which caused partial occlusion when blank was partially visible. 2. Fix close animation overshooting on non-inverted lists. The close path was computing the theoretical scroll displacement (keyboard height minus blank absorption) to undo the open shift. But when the open shift was clamped by maxScroll, the theoretical value exceeded the actual shift, causing close to move content down more than open moved it up. Record the actual scroll displacement at the end of the open animation (scroll.value - offsetBeforeScroll) and use that for the close calculation. This makes open/close symmetric regardless of clamping.
…lView Previously, scrollIndicatorInsets matched contentInset, which included blankSize. This caused the scroll indicator to end halfway down the screen when blankSize was large. Add a scrollIndicatorPadding prop to ScrollViewWithBottomPadding that computes indicator insets from keyboard + extraContentPadding only, excluding blankSize. User-supplied scrollIndicatorInsets.bottom/top are now additive adjustments (previously silently ignored). Update AILegendListChat example to pass a negative safe area bottom adjustment for apps that render into the unsafe area.
… 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
When closing the keyboard on iOS, after an earlier commit that fixed android behavior, it made iOS worse than it was in the first commit of this PR. This improves iOS.
a7f010f to
1b2d38e
Compare
kirillzyusko
approved these changes
Mar 10, 2026
Owner
|
This is amazing! I can't express how grateful I am to you for making this a reality! ❤️ |
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
Added new
minimumContentPaddingprop toKeyboardChatScrollView. This is to provide a mechanism for positioning the latest user message at the top of the screen when building AI chat apps with streaming responses.💡 Motivation and Context
Schematically all the process can be shown as this:
The main idea is that
minimumContentPaddingadds a scrollable range inScrollView, so that "just sent" message can be scrolled up and be visible from the top (typical functionality in AI apps).However we need to define a strategy how new property reacts when keyboard appears/disappears. For that we define two stategies:
minimumContentPadding>extraContentPadding+keyboardHeight- content position is not changing in this caseminimumContentPadding><extraContentPadding+keyboardHeight- content position is changes by delta between left/right operand.This is a typical AI flow. Both ChatGPT/Claude works in this way, so I don't think we need to customize it somehow (maybe in future, but not now).
Closes #1333
📢 Changelog
Docs
JS
applyWorkaroundForContentInsetHitTestBugprop;minimumContentPaddingprop;indicatorInsetsprops to have a better control of scroll indicator position.iOS
applyWorkaroundForContentInsetHitTestBugprop;Android
🤔 How Has This Been Tested?
Manually testing on iOS and Android with the AI LegendList Chat example that I included in this PR.
You can type 'a', 'b', 'c', or 'd' in the chat to get shorter vs longer replies from the AI to test how things work with the blankSize.
Tested on:
📸 Screenshots (if appropriate):
Simulator.Screen.Recording.-.iPhone.16.Pro.-.2026-03-03.at.16.31.29.mp4
Simulator.Screen.Recording.-.iPhone.16.Pro.-.2026-03-03.at.16.32.00.mp4
Simulator.Screen.Recording.-.iPhone.16.Pro.-.2026-03-03.at.16.32.50.mp4
Simulator.Screen.Recording.-.iPhone.16.Pro.-.2026-03-03.at.16.33.04.mp4
Simulator.Screen.Recording.-.iPhone.16.Pro.-.2026-03-03.at.16.34.52.mp4
📝 Checklist