Skip to content
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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

zhongwuzw
Copy link
Contributor

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 .

@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. labels Sep 30, 2024
Comment on lines 8 to 23
#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;
}
Copy link
Contributor

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.

Copy link
Contributor Author

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 :)

Copy link
Contributor

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)

Copy link
Member

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;
Copy link
Member

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.

Copy link
Contributor Author

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.

Comment on lines 51 to 54
/** 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;
Copy link
Member

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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Respect early return.

@zhongwuzw zhongwuzw requested a review from javache October 2, 2024 14:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

automaticallyAdjustKeyboardInsets not shifting scrollview content
4 participants