Skip to content

Commit

Permalink
Fix a crash when keyboard is visible and bridge reload happens
Browse files Browse the repository at this point in the history
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 d9c6585
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 3 additions & 2 deletions React/Modules/RCTEventEmitter.m
Original file line number Diff line number Diff line change
Expand Up @@ -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: `%@`",
Expand Down
6 changes: 6 additions & 0 deletions React/Modules/RCTKeyboardObserver.m
Original file line number Diff line number Diff line change
Expand Up @@ -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)]; \
}
Expand Down

0 comments on commit d9c6585

Please sign in to comment.