Skip to content

Commit

Permalink
[Blur & Focus] Support relinquishing focus from multiple views via co…
Browse files Browse the repository at this point in the history
…ntainer - facebook#113
  • Loading branch information
josebalius committed Aug 2, 2015
1 parent bc56eb1 commit 1377736
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
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];
}
}
}

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

0 comments on commit 1377736

Please sign in to comment.