Browse Source

ios - change store to have NSMapTable instead of NSMutableDictionary

Ran Greenberg 7 years ago
parent
commit
a156e4764a

+ 1
- 1
ios/RNNBridgeModule.m View File

@@ -39,7 +39,7 @@ RCT_EXPORT_METHOD(pop:(NSString*)containerId)
39 39
 	[self assertReady];
40 40
 	UIViewController *vc = [[RNN instance].store findContainerForId:containerId];
41 41
 	
42
-	[[vc navigationController] popViewControllerAnimated:true];
42
+	[[vc navigationController] popViewControllerAnimated:YES];
43 43
 	[[RNN instance].store removeContainer:containerId];
44 44
 }
45 45
 

+ 4
- 6
ios/RNNStore.m View File

@@ -10,7 +10,7 @@
10 10
 
11 11
 @interface RNNStore ()
12 12
 
13
-@property NSMutableDictionary *containerStore;
13
+@property NSMapTable *containerStore;
14 14
 
15 15
 @end
16 16
 
@@ -19,14 +19,14 @@
19 19
 
20 20
 -(instancetype)init {
21 21
 	self = [super init];
22
-	self.containerStore = [NSMutableDictionary new];
23
-	
22
+	self.containerStore = [NSMapTable strongToWeakObjectsMapTable];
24 23
 	return self;
25 24
 }
26 25
 
27 26
 
28 27
 -(UIViewController *)findContainerForId:(NSString *)containerId {
29
-	return [self.containerStore valueForKey:containerId];
28
+	return [self.containerStore objectForKey:containerId];
29
+	
30 30
 }
31 31
 
32 32
 
@@ -46,6 +46,4 @@
46 46
 }
47 47
 
48 48
 
49
-
50
-
51 49
 @end

+ 1
- 1
playground/ios/playground.xcodeproj/project.pbxproj View File

@@ -295,8 +295,8 @@
295 295
 			isa = PBXGroup;
296 296
 			children = (
297 297
 				26070FCF1E4B8B9D003EC8B9 /* RNNControllerFactoryTest.m */,
298
-				00E356F01AD99517003FC87E /* Supporting Files */,
299 298
 				268692841E50572700E2C612 /* RNNStoreTest.m */,
299
+				00E356F01AD99517003FC87E /* Supporting Files */,
300 300
 			);
301 301
 			path = playgroundTests;
302 302
 			sourceTree = "<group>";

+ 18
- 3
playground/ios/playgroundTests/RNNStoreTest.m View File

@@ -18,7 +18,7 @@
18 18
 @implementation RNNStoreTest
19 19
 
20 20
 - (void)setUp {
21
-    [super setUp];
21
+	[super setUp];
22 22
 	
23 23
 	self.store = [RNNStore new];
24 24
 }
@@ -43,7 +43,7 @@
43 43
 - (void)testSetContainer_setNilContainerId {
44 44
 	NSString *containerId1 = nil;
45 45
 	UIViewController *vc1 = [UIViewController new];
46
-	XCTAssertThrows([self.store setContainer:vc1 containerId:containerId1]);
46
+	[self.store setContainer:vc1 containerId:containerId1];
47 47
 	XCTAssertNil([self.store findContainerForId:containerId1]);
48 48
 	
49 49
 }
@@ -71,10 +71,25 @@
71 71
 	XCTAssertEqualObjects(vc1, ans);
72 72
 	
73 73
 	[self.store removeContainer:containerId1];
74
-	
75 74
 	XCTAssertNil([self.store findContainerForId:containerId1]);
76 75
 }
77 76
 
77
+-(void)testPopWillRemoveVcFromStore {
78
+	NSString *vcId = @"cnt_vc_2";
79
+	
80
+	[self setContainerAndRelease:vcId];
81
+	
82
+	
83
+	XCTAssertNil([self.store findContainerForId:vcId]); // PASS
84
+}
78 85
 
86
+-(void) setContainerAndRelease:(NSString*)vcId {
87
+	@autoreleasepool {
88
+		UIViewController *vc2 = [UIViewController new];
89
+		[self.store setContainer:vc2 containerId:vcId];
90
+		
91
+		XCTAssertNotNil([self.store findContainerForId:vcId]); // PASS
92
+	}
93
+}
79 94
 
80 95
 @end

+ 18
- 0
playground/src/containers/SimpleScreen.js View File

@@ -7,13 +7,16 @@ class SimpleScreen extends Component {
7 7
   constructor(props) {
8 8
     super(props);
9 9
     this.onClickPop = this.onClickPop.bind(this);
10
+    this.onClickPush = this.onClickPush.bind(this);
10 11
   }
11 12
 
12 13
   render() {
13 14
     return (
14 15
       <View style={styles.root}>
15 16
         <Text style={styles.h1}>{this.props.text || 'Simple Screen'}</Text>
17
+        <Text style={styles.h2}>{this.props.stackPosition}</Text>
16 18
         {this.renderTextFromFunctionInProps()}
19
+        <Button title="Push" onPress={this.onClickPush} />
17 20
         <Button title="Pop" onPress={this.onClickPop} />
18 21
       </View>
19 22
     );
@@ -31,6 +34,16 @@ class SimpleScreen extends Component {
31 34
   onClickPop() {
32 35
     Navigation.on(this.props.id).pop();
33 36
   }
37
+  
38
+  onClickPush() {
39
+    Navigation.on(this.props.id).push({
40
+      name: 'navigation.playground.SimpleScreen',
41
+      passProps: {
42
+        stackPosition: this.props.stackPosition + 1,
43
+      }
44
+    });
45
+  }
46
+
34 47
 }
35 48
 export default SimpleScreen;
36 49
 
@@ -45,5 +58,10 @@ const styles = {
45 58
     fontSize: 24,
46 59
     textAlign: 'center',
47 60
     margin: 10
61
+  },
62
+  h2: {
63
+    fontSize: 12,
64
+    textAlign: 'center',
65
+    margin: 10
48 66
   }
49 67
 };

+ 8
- 1
playground/src/containers/WelcomeScreen.js View File

@@ -7,6 +7,7 @@ class WelcomeScreen extends Component {
7 7
   constructor(props) {
8 8
     super(props);
9 9
     this.onClickPush = this.onClickPush.bind(this);
10
+    this.onShowModal = this.onShowModal.bind(this);
10 11
   }
11 12
 
12 13
   render() {
@@ -17,6 +18,7 @@ class WelcomeScreen extends Component {
17 18
         <Button title="Switch to app with side menus" onPress={this.onClickSwitchToSideMenus} />
18 19
         <Button title="Switch to lifecycle screen" onPress={this.onClickLifecycleScreen} />
19 20
         <Button title="Push" onPress={this.onClickPush} />
21
+        <Button title="Show Modal" onPress={this.onClickPush} />
20 22
         <Text style={styles.footer}>{`this.props.id = ${this.props.id}`}</Text>
21 23
       </View>
22 24
     );
@@ -90,7 +92,8 @@ class WelcomeScreen extends Component {
90 92
     Navigation.on(this.props.id).push({
91 93
       name: 'navigation.playground.SimpleScreen',
92 94
       passProps: {
93
-        text: 'Pushed screen'
95
+        text: 'Pushed screen',
96
+        stackPosition: 1
94 97
       }
95 98
     });
96 99
   }
@@ -102,6 +105,10 @@ class WelcomeScreen extends Component {
102 105
       }
103 106
     });
104 107
   }
108
+  
109
+  onShowModal() {
110
+    Navigation.on(this.props.id).show
111
+  }
105 112
 }
106 113
 
107 114
 export default WelcomeScreen;