[v2] Fixes issues#1397#1816
Conversation
|
Note that it does not fix appLoaded event being raised multiple times due to many js bundles. It fixes app hanging due to not receiving the event. |
|
Thanks for the PR. |
|
@DanielZlotin FYI I am using RN 0.47.2. |
|
This reproduces on RN 0.50.3 as well. |
|
For RN 0.50.3, I checked both with and without debugger, and this fix works! |
|
Fix works for: |
There was a problem hiding this comment.
Tested, this is what I see:
Fixes
- It's now possible to run the app with JS Debugging enabled (#491, #862, #963)
Doesn't fix
- Warning still appears:
Sending RNN.appLaunched with no listeners registered.(#1397) - App still crashes after reloading (#2030, #1514) (this fixes it: #1836)
"react-native": "^0.51.0",
"react-native-gesture-handler": "^1.0.0-alpha.35",
|
Such a major bug in v2, didn't get fixed. Any body working on this atm? |
|
@anonrig while this is not merged, you can apply the fix using patch-package. Follow the instructions in the patch-package README. After the step patch-package
--- a/node_modules/react-native-navigation/lib/ios/RNNEventEmitter.m
+++ b/node_modules/react-native-navigation/lib/ios/RNNEventEmitter.m
@@ -1,6 +1,9 @@
#import "RNNEventEmitter.h"
-@implementation RNNEventEmitter
+@implementation RNNEventEmitter {
+ NSInteger _appLaunchedListenerCount;
+ BOOL _appLaunchedEventDeferred;
+}
RCT_EXPORT_MODULE();
@@ -15,9 +18,14 @@ static NSString* const onNavigationButtonPressed = @"RNN.navigationButtonPressed
# pragma mark public
--(void)sendOnAppLaunched {
+-(void)sendOnAppLaunched {
[self send:onAppLaunched body:nil];
-}
+ if (_appLaunchedListenerCount > 0) {
+ [self send:onAppLaunched body:nil];
+ } else {
+ _appLaunchedEventDeferred = TRUE;
+ }
+ }
-(void)sendContainerDidAppear:(NSString *)containerId {
[self send:containerDidAppear body:containerId];
@@ -31,10 +39,24 @@ static NSString* const onNavigationButtonPressed = @"RNN.navigationButtonPressed
[self send:onNavigationButtonPressed body:@{@"containerId":containerId , @"buttonId": buttonId }];
}
+- (void)addListener:(NSString *)eventName {
+ [super addListener:eventName];
+ if ([eventName isEqualToString:onAppLaunched]) {
+ _appLaunchedListenerCount++;
+ if (_appLaunchedEventDeferred) {
+ _appLaunchedEventDeferred = FALSE;
+ [self sendOnAppLaunched];
+ }
+ }
+}
+
# pragma mark private
-(void)send:(NSString *)eventName body:(id)body {
- [self sendEventWithName:eventName body:body];
+ // TODO This is a quick and dirty fix to issues/#1514.
+ if ([self bridge] != nil) {
+ [self sendEventWithName:eventName body:body];
+ }
}
@endAfter every This patch includes this pull request and #1836 as well. |
|
this patch does not work for me. Sending `RNN.appLaunched` with no listeners registered. react-native-navigation: 2.0.2070
react-native: 0.51.0
node: 9.3.0
npm: 5.6.0 |
#1397
Tested it and it works well with or without remote debugging enabled.