浏览代码

fixing modal leak

Daniel Zlotin 7 年前
父节点
当前提交
143804134a
共有 4 个文件被更改,包括 28 次插入7 次删除
  1. 13
    1
      ios/RNNReactRootViewCreator.m
  2. 7
    2
      ios/ReactNativeNavigation.m
  3. 4
    0
      playground/e2e/app.test.js
  4. 4
    4
      playground/src/containers/PushedScreen.js

+ 13
- 1
ios/RNNReactRootViewCreator.m 查看文件

@@ -2,6 +2,18 @@
2 2
 #import "RNNReactRootViewCreator.h"
3 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 17
 @implementation RNNReactRootViewCreator {
6 18
 	RCTBridge *_bridge;
7 19
 }
@@ -20,7 +32,7 @@
20 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 36
 										 moduleName:name
25 37
 								  initialProperties:@{@"id": rootViewId}];
26 38
 	return view;

+ 7
- 2
ios/ReactNativeNavigation.m 查看文件

@@ -1,7 +1,8 @@
1 1
 
2 2
 #import "ReactNativeNavigation.h"
3
- 
3
+
4 4
 #import <React/RCTBridge.h>
5
+#import <React/RCTUIManager.h>
5 6
 
6 7
 #import "RNNEventEmitter.h"
7 8
 #import "RNNSplashScreen.h"
@@ -75,8 +76,8 @@
75 76
 # pragma mark - js events
76 77
 
77 78
 -(void)onJavaScriptWillLoad {
78
-	[_store clean];
79 79
 	[self resetRootViewControllerOnlyOnJSDevReload];
80
+	[_store clean];
80 81
 }
81 82
 
82 83
 -(void)onJavaScriptLoaded {
@@ -102,9 +103,13 @@
102 103
 }
103 104
 
104 105
 -(void)resetRootViewControllerOnlyOnJSDevReload {
106
+#ifdef DEBUG
107
+	
105 108
 	if(![UIApplication.sharedApplication.delegate.window.rootViewController isKindOfClass:[RNNSplashScreen class]]) {
106 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 查看文件

@@ -169,6 +169,10 @@ describe('reload app', () => {
169 169
   it('show welcome screen after reload', () => {
170 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 178
 function elementByLabel(label) {

+ 4
- 4
playground/src/containers/PushedScreen.js 查看文件

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