Browse Source

fixing modal leak

Daniel Zlotin 7 years ago
parent
commit
143804134a

+ 13
- 1
ios/RNNReactRootViewCreator.m View File

2
 #import "RNNReactRootViewCreator.h"
2
 #import "RNNReactRootViewCreator.h"
3
 #import <React/RCTRootView.h>
3
 #import <React/RCTRootView.h>
4
 
4
 
5
+@interface RNNReactRootView : RCTRootView
6
+
7
+@end
8
+
9
+@implementation RNNReactRootView
10
+
11
+-(void) dealloc {
12
+	
13
+}
14
+
15
+@end
16
+
5
 @implementation RNNReactRootViewCreator {
17
 @implementation RNNReactRootViewCreator {
6
 	RCTBridge *_bridge;
18
 	RCTBridge *_bridge;
7
 }
19
 }
20
 		@throw [NSException exceptionWithName:@"MissingViewId" reason:@"Missing view id" userInfo:nil];
32
 		@throw [NSException exceptionWithName:@"MissingViewId" reason:@"Missing view id" userInfo:nil];
21
 	}
33
 	}
22
 	
34
 	
23
-	UIView *view = [[RCTRootView alloc] initWithBridge:_bridge
35
+	UIView *view = [[RNNReactRootView alloc] initWithBridge:_bridge
24
 										 moduleName:name
36
 										 moduleName:name
25
 								  initialProperties:@{@"id": rootViewId}];
37
 								  initialProperties:@{@"id": rootViewId}];
26
 	return view;
38
 	return view;

+ 7
- 2
ios/ReactNativeNavigation.m View File

1
 
1
 
2
 #import "ReactNativeNavigation.h"
2
 #import "ReactNativeNavigation.h"
3
- 
3
+
4
 #import <React/RCTBridge.h>
4
 #import <React/RCTBridge.h>
5
+#import <React/RCTUIManager.h>
5
 
6
 
6
 #import "RNNEventEmitter.h"
7
 #import "RNNEventEmitter.h"
7
 #import "RNNSplashScreen.h"
8
 #import "RNNSplashScreen.h"
75
 # pragma mark - js events
76
 # pragma mark - js events
76
 
77
 
77
 -(void)onJavaScriptWillLoad {
78
 -(void)onJavaScriptWillLoad {
78
-	[_store clean];
79
 	[self resetRootViewControllerOnlyOnJSDevReload];
79
 	[self resetRootViewControllerOnlyOnJSDevReload];
80
+	[_store clean];
80
 }
81
 }
81
 
82
 
82
 -(void)onJavaScriptLoaded {
83
 -(void)onJavaScriptLoaded {
102
 }
103
 }
103
 
104
 
104
 -(void)resetRootViewControllerOnlyOnJSDevReload {
105
 -(void)resetRootViewControllerOnlyOnJSDevReload {
106
+#ifdef DEBUG
107
+	
105
 	if(![UIApplication.sharedApplication.delegate.window.rootViewController isKindOfClass:[RNNSplashScreen class]]) {
108
 	if(![UIApplication.sharedApplication.delegate.window.rootViewController isKindOfClass:[RNNSplashScreen class]]) {
106
 		UIApplication.sharedApplication.delegate.window.rootViewController = nil;
109
 		UIApplication.sharedApplication.delegate.window.rootViewController = nil;
107
 	}
110
 	}
111
+	
112
+#endif
108
 }
113
 }
109
 
114
 
110
 
115
 

+ 4
- 0
playground/e2e/app.test.js View File

169
   it('show welcome screen after reload', () => {
169
   it('show welcome screen after reload', () => {
170
     expect(elementByLabel('React Native Navigation!')).toBeVisible();
170
     expect(elementByLabel('React Native Navigation!')).toBeVisible();
171
   });
171
   });
172
+
173
+  it('show modal then reload will not cause a leak', () => {
174
+    elementByLabel('Show Modal').tap();
175
+  });
172
 });
176
 });
173
 
177
 
174
 function elementByLabel(label) {
178
 function elementByLabel(label) {

+ 4
- 4
playground/src/containers/PushedScreen.js View File

28
       </View>
28
       </View>
29
     );
29
     );
30
   }
30
   }
31
-  
31
+
32
   onClickPush() {
32
   onClickPush() {
33
     Navigation.on(this.props.id).push({
33
     Navigation.on(this.props.id).push({
34
       name: 'navigation.playground.PushedScreen',
34
       name: 'navigation.playground.PushedScreen',
38
       }
38
       }
39
     });
39
     });
40
   }
40
   }
41
-  
41
+
42
   onClickPop() {
42
   onClickPop() {
43
     Navigation.on(this.props.id).pop();
43
     Navigation.on(this.props.id).pop();
44
   }
44
   }
45
-  
45
+
46
   onClickPopPrevious() {
46
   onClickPopPrevious() {
47
     Navigation.on(_.last(this.props.previousScreenIds)).pop();
47
     Navigation.on(_.last(this.props.previousScreenIds)).pop();
48
   }
48
   }
49
-  
49
+
50
   getStackPosition() {
50
   getStackPosition() {
51
     return this.props.stackPosition || 1;
51
     return this.props.stackPosition || 1;
52
   }
52
   }