-
Notifications
You must be signed in to change notification settings - Fork 24.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[iOS] automaticallyAdjustKeyboardInsets not shifting scrollview content #46732
base: main
Are you sure you want to change the base?
Conversation
#import "UIResponder+React.h" | ||
|
||
static __weak id reactCurrentFirstResponder; | ||
|
||
@implementation UIResponder (React) | ||
+ (id)reactCurrentFirstResponder | ||
{ | ||
reactCurrentFirstResponder = nil; | ||
[[UIApplication sharedApplication] sendAction:@selector(reactFindFirstResponder:) to:nil from:nil forEvent:nil]; | ||
return reactCurrentFirstResponder; | ||
} | ||
|
||
- (void)reactFindFirstResponder:(id)sender | ||
{ | ||
reactCurrentFirstResponder = self; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is something we used to have and we removed it. It is seen as an anti-pattern, so we'd rather not have it. Probably @javache has more context on why it got removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cipolleschi I changed another way to find first responder :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found why: the previous API is a private API #37766 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think is private API because we're using our own selector reactFindFirstResponder. Let's see if we can avoid adding another action though.
@@ -34,6 +34,7 @@ @implementation RCTBaseTextInputView { | |||
|
|||
- (void)reactUpdateResponderOffsetForScrollView:(RCTScrollView *)scrollView | |||
{ | |||
scrollView.firstResponderFocusView = self.backedTextInputView; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should respect the early return.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@javache I optimized the code to only store it when the first responder is outside the scroll view.
/** Focus area of newly-activated text input relative to the window to compare against UIKeyboardFrameBegin/End */ | ||
@property (nonatomic, assign) CGRect firstResponderFocus; | ||
/** newly-activated text input relative to the window to compare against UIKeyboardFrameBegin/End */ | ||
@property (nonatomic, weak) UIView *firstResponderFocusView; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a lot of overlap between these two fields. If we're going to be storing the focusView anyway, can we get rid of the focus rect and instead add a reactFocusFrame
to UIView+React
?
@@ -102,6 +102,7 @@ - (void)didMoveToWindow | |||
|
|||
- (void)reactUpdateResponderOffsetForScrollView:(RCTScrollViewComponentView *)scrollView | |||
{ | |||
scrollView.firstResponderFocusView = _backedTextInputView; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Respect early return.
Summary:
Fixes #46595 . It seems #37766 broke the
automaticallyAdjustKeyboardInsets
when input accessory view become first responder.Changelog:
[IOS] [FIXED] - automaticallyAdjustKeyboardInsets not shifting scrollview content
Test Plan:
Repro please see in ##46595 .