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

[Blur & Focus] Support relinquishing focus from multiple views via co… #2203

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Libraries/Components/TextInput/TextInputState.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ var TextInputState = {
if (this._currentlyFocusedID === textFieldID && textFieldID !== null) {
this._currentlyFocusedID = null;
RCTUIManager.blur(textFieldID);
} else {
RCTUIManager.blurView(textFieldID);
}
}
};
Expand Down
22 changes: 22 additions & 0 deletions React/Modules/RCTUIManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,20 @@ - (void)_manageChildren:(NSNumber *)containerReactTag
}
}

- (void)endEditingForShadowView:(NSNumber *)reactTag manager:(RCTUIManager *)uiManager viewRegistry:(RCTSparseArray *)viewRegistry
{
RCTShadowView *shadowView = uiManager.shadowViewRegistry[reactTag];

for(RCTShadowView *subview in [shadowView reactSubviews]) {
if([[subview reactSubviews] count] > 0) {
[uiManager endEditingForShadowView:subview.reactTag manager:uiManager viewRegistry:viewRegistry];
} else {
UIView *view = viewRegistry[subview.reactTag];
[view resignFirstResponder];
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

You should be able to do something like [subview endEditing:YES] instead of doing the complete traversal. Also can remove the uiManager parameter since self == uiManager.

UIView *view = uiManager.viewRegistry[reactTag];
if (view) {
  [view endEditing:YES];
} else {
  // Recurse through the shadow hierarchy when the shadow view has no backing UIView
  for (RCTShadowView *subview in [shadowView reactSubviews]) {
    [self endEditingForShadowView:subview.reactTag viewRegistry:viewRegistry];
  }
}

Copy link
Author

Choose a reason for hiding this comment

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

@ide Makes perfect sense, i'll make the changes, test and commit.


static BOOL RCTCallPropertySetter(NSString *key, SEL setter, id value, id view, id defaultView, RCTViewManager *manager)
{
// TODO: cache respondsToSelector tests
Expand Down Expand Up @@ -914,6 +928,14 @@ static void RCTSetShadowViewProps(NSDictionary *props, RCTShadowView *shadowView
}];
}

RCT_EXPORT_METHOD(blurView:(NSNumber *)reactTag)
{
if (!reactTag) return;
[self addUIBlock:^(__unused RCTUIManager *uiManager, RCTSparseArray *viewRegistry){
[uiManager endEditingForShadowView:reactTag manager:uiManager viewRegistry:viewRegistry];
}];
}

RCT_EXPORT_METHOD(findSubviewIn:(NSNumber *)reactTag atPoint:(CGPoint)point callback:(RCTResponseSenderBlock)callback) {
if (!reactTag) {
callback(@[(id)kCFNull]);
Expand Down