|
16 | 16 | #import "RCTBridge.h"
|
17 | 17 | #import "RCTConstants.h"
|
18 | 18 | #import "RCTDevSettings.h" // [macOS]
|
| 19 | +#import "RCTFocusChangeEvent.h" // [macOS] |
19 | 20 | // [macOS] remove #import "RCTKeyCommands.h"
|
20 | 21 | #import "RCTLog.h"
|
21 | 22 | #import "RCTPerformanceLogger.h"
|
@@ -432,6 +433,46 @@ - (void)viewDidChangeEffectiveAppearance
|
432 | 433 | #endif // macOS]
|
433 | 434 |
|
434 | 435 |
|
| 436 | +#pragma mark - Key window blur/focus |
| 437 | + |
| 438 | +#if TARGET_OS_OSX // [macOS |
| 439 | +- (void)viewDidMoveToWindow { |
| 440 | + [super viewDidMoveToWindow]; |
| 441 | + |
| 442 | + NSWindow *window = [self window]; |
| 443 | + if (window == nil) { |
| 444 | + return; |
| 445 | + } |
| 446 | + |
| 447 | + [[NSNotificationCenter defaultCenter] addObserver:self |
| 448 | + selector:@selector(containingWindowDidBecomeKey) |
| 449 | + name:NSWindowDidBecomeKeyNotification |
| 450 | + object:window]; |
| 451 | + |
| 452 | + [[NSNotificationCenter defaultCenter] addObserver:self |
| 453 | + selector:@selector(containingWindowDidResignKey) |
| 454 | + name:NSWindowDidResignKeyNotification |
| 455 | + object:window]; |
| 456 | +} |
| 457 | + |
| 458 | +- (void)containingWindowDidBecomeKey { |
| 459 | + NSResponder *firstResponder = [[self window] firstResponder]; |
| 460 | + if ([firstResponder isKindOfClass:[RCTPlatformView class]]) { |
| 461 | + NSNumber *reactTag = [(RCTPlatformView *)firstResponder reactTag]; |
| 462 | + [[[self bridge] eventDispatcher] sendEvent:[RCTFocusChangeEvent focusEventWithReactTag:reactTag]]; |
| 463 | + } |
| 464 | +} |
| 465 | + |
| 466 | +- (void)containingWindowDidResignKey { |
| 467 | + NSResponder *firstResponder = [[self window] firstResponder]; |
| 468 | + if ([firstResponder isKindOfClass:[RCTPlatformView class]]) { |
| 469 | + NSNumber *reactTag = [(RCTPlatformView *)firstResponder reactTag]; |
| 470 | + [[[self bridge] eventDispatcher] sendEvent:[RCTFocusChangeEvent blurEventWithReactTag:reactTag]]; |
| 471 | + } |
| 472 | +} |
| 473 | +#endif // macOS] |
| 474 | + |
| 475 | + |
435 | 476 | #if TARGET_OS_OSX // [macOS
|
436 | 477 | - (NSMenu *)menuForEvent:(NSEvent *)event
|
437 | 478 | {
|
|
0 commit comments