@@ -455,19 +455,36 @@ - (void)viewDidMoveToWindow {
455
455
object: window];
456
456
}
457
457
458
+ + (NSNumber *)reactTagClosestToView : (RCTPlatformView *)view {
459
+ // The first responder may not necessarily have a React tag. For example, if we're focused on
460
+ // a multiline <TextInput>, the RN component whose blur/focus events we need to touch is an
461
+ // RCTMultilineTextInputView, but the first responder will be the underlying RCTUITextView.
462
+ for (RCTPlatformView *testView = view; testView != nil ; testView = [testView superview ]) {
463
+ NSNumber *reactTag = [testView reactTag ];
464
+ if (reactTag != nil ) {
465
+ return reactTag;
466
+ }
467
+ }
468
+ return nil ;
469
+ }
470
+
458
471
- (void )containingWindowDidBecomeKey {
459
472
NSResponder *firstResponder = [[self window ] firstResponder ];
460
473
if ([firstResponder isKindOfClass: [RCTPlatformView class ]]) {
461
- NSNumber *reactTag = [(RCTPlatformView *)firstResponder reactTag ];
462
- [[[self bridge ] eventDispatcher ] sendEvent: [RCTFocusChangeEvent focusEventWithReactTag: reactTag]];
474
+ NSNumber *reactTag = [RCTRootView reactTagClosestToView: (RCTPlatformView *)firstResponder];
475
+ if (reactTag != nil ) {
476
+ [[[self bridge ] eventDispatcher ] sendEvent: [RCTFocusChangeEvent focusEventWithReactTag: reactTag]];
477
+ }
463
478
}
464
479
}
465
480
466
481
- (void )containingWindowDidResignKey {
467
482
NSResponder *firstResponder = [[self window ] firstResponder ];
468
483
if ([firstResponder isKindOfClass: [RCTPlatformView class ]]) {
469
- NSNumber *reactTag = [(RCTPlatformView *)firstResponder reactTag ];
470
- [[[self bridge ] eventDispatcher ] sendEvent: [RCTFocusChangeEvent blurEventWithReactTag: reactTag]];
484
+ NSNumber *reactTag = [RCTRootView reactTagClosestToView: (RCTPlatformView *)firstResponder];
485
+ if (reactTag != nil ) {
486
+ [[[self bridge ] eventDispatcher ] sendEvent: [RCTFocusChangeEvent blurEventWithReactTag: reactTag]];
487
+ }
471
488
}
472
489
}
473
490
#endif // macOS]
0 commit comments