Permalink
Browse files

Fix a crash when keyboard is visible and bridge reload happens

Reviewed By: sahrens

Differential Revision: D6573855

fbshipit-source-id: 8768dca7d36782e82fb457f6ff4b09791e669d00
  • Loading branch information...
fromcelticpark authored and facebook-github-bot committed Dec 15, 2017
1 parent 5f8d8e9 commit d9c658566a14ce8767d87435264997aa18dd08e4
Showing with 9 additions and 2 deletions.
  1. +3 −2 React/Modules/RCTEventEmitter.m
  2. +6 −0 React/Modules/RCTKeyboardObserver.m
@@ -37,9 +37,10 @@ + (void)initialize
- (void)sendEventWithName:(NSString *)eventName body:(id)body
{
RCTAssert(_bridge != nil, @"bridge is not set. This is probably because you've "
RCTAssert(_bridge != nil, @"Error when sending event: %@ with body: %@. "
"Bridge is not set. This is probably because you've "
"explicitly synthesized the bridge in %@, even though it's inherited "
"from RCTEventEmitter.", [self class]);
"from RCTEventEmitter.", eventName, body, [self class]);
if (RCT_DEBUG && ![[self supportedEvents] containsObject:eventName]) {
RCTLogError(@"`%@` is not a supported event type for %@. Supported events are: `%@`",
@@ -54,9 +54,15 @@ - (void)stopObserving
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
// Bridge might be already invalidated by the time the keyboard is about to be dismissed.
// This might happen, for example, when reload from the packager is performed.
// Thus we need to check against nil here.
#define IMPLEMENT_KEYBOARD_HANDLER(EVENT) \
- (void)EVENT:(NSNotification *)notification \
{ \
if (!self.bridge) { \
return; \
} \
[self sendEventWithName:@#EVENT \
body:RCTParseKeyboardNotification(notification)]; \
}

0 comments on commit d9c6585

Please sign in to comment.