Ran Greenberg il y a 7 ans
Parent
révision
ebaafd409e

+ 8
- 41
ios/RNNBridgeModule.m Voir le fichier

@@ -4,6 +4,7 @@
4 4
 #import "RNNControllerFactory.h"
5 5
 #import "RNNReactRootViewCreator.h"
6 6
 #import "RNNStore.h"
7
+#import "RNNModalManager.h"
7 8
 
8 9
 @implementation RNNBridgeModule
9 10
 
@@ -48,46 +49,16 @@ RCT_EXPORT_METHOD(showModal:(NSDictionary*)layout)
48 49
 	[self assertReady];
49 50
 	RNNControllerFactory *factory = [[RNNControllerFactory alloc] initWithRootViewCreator:[RNNReactRootViewCreator new] store:[RNN instance].store];
50 51
 	UIViewController *newVc = [factory createLayoutAndSaveToStore:layout];
51
-	
52
-	UIViewController *root = [self topPresentedVC];
53
-	[root presentViewController:newVc animated:YES completion:^{
54
-		
55
-	}];
52
+	[[[RNNModalManager alloc] initWithStore:[RNN instance].store] showModal:newVc];
56 53
 }
57 54
 
58 55
 RCT_EXPORT_METHOD(dismissModal:(NSString*)containerId)
59 56
 {
60
-	UIViewController *modalToDismiss = [[RNN instance].store findContainerForId:containerId];
61
-	
62
-	if (modalToDismiss) {
63
-		UIViewController *topVC = [self topPresentedVC];
64
-		
65
-		if (modalToDismiss == topVC) {
66
-			[modalToDismiss dismissViewControllerAnimated:YES completion:^{
67
-				[self removeNextModal];
68
-
69
-			}];
70
-		}
71
-		else {
72
-			[[RNN instance].store.modalsToDismissArray addObject:containerId];
73
-		}
74
-	}
57
+	[self assertReady];
58
+	[[[RNNModalManager alloc] initWithStore:[RNN instance].store] dismissModal:containerId];
75 59
 }
76 60
 
77
--(void)removeNextModal {
78
-	NSString *nextContainerId = [[RNN instance].store.modalsToDismissArray lastObject];
79
-	UIViewController *vc = [[RNN instance].store findContainerForId:nextContainerId];
80
-	
81
-	if (vc) {
82
-		UIViewController *topVC = [self topPresentedVC];
83
-		if (vc == topVC) {
84
-			[vc dismissViewControllerAnimated:YES completion:^{
85
-				[[RNN instance].store.modalsToDismissArray removeObject:nextContainerId];
86
-				[self removeNextModal];
87
-			}];
88
-		}
89
-	}
90
-}
61
+
91 62
 
92 63
 - (void)assertReady
93 64
 {
@@ -96,13 +67,9 @@ RCT_EXPORT_METHOD(dismissModal:(NSString*)containerId)
96 67
 	}
97 68
 }
98 69
 
99
--(UIViewController*)topPresentedVC {
100
-	UIViewController *root = UIApplication.sharedApplication.delegate.window.rootViewController;
101
-	while(root.presentedViewController) {
102
-		root = root.presentedViewController;
103
-	}
104
-	return root;
105
-}
70
+
71
+
72
+
106 73
 
107 74
 @end
108 75
 

+ 13
- 0
ios/RNNModalManager.h Voir le fichier

@@ -0,0 +1,13 @@
1
+#import <Foundation/Foundation.h>
2
+#import <UIKit/UIKit.h>
3
+#import "RNNStore.h"
4
+
5
+@interface RNNModalManager : NSObject
6
+
7
+-(instancetype)initWithStore:(RNNStore*)store;
8
+
9
+
10
+-(void)showModal:(UIViewController*)viewController;
11
+-(void)dismissModal:(NSString*)containerId;
12
+
13
+@end

+ 56
- 0
ios/RNNModalManager.m Voir le fichier

@@ -0,0 +1,56 @@
1
+#import "RNNModalManager.h"
2
+
3
+@interface RNNModalManager ()
4
+
5
+@property RNNStore *store;
6
+
7
+@end
8
+
9
+@implementation RNNModalManager
10
+
11
+
12
+-(instancetype)initWithStore:(RNNStore*)store {
13
+	self = [super init];
14
+	self.store = store;
15
+	return self;
16
+}
17
+
18
+-(void)showModal:(UIViewController *)viewController {
19
+	UIViewController *topVC = [self topPresentedVC];
20
+	[topVC presentViewController:viewController animated:YES completion:nil];
21
+}
22
+
23
+-(void)dismissModal:(NSString *)containerId {
24
+	[self.store.modalsToDismissArray addObject:containerId];
25
+	[self removePendingNextModalIfOnTop];
26
+}
27
+
28
+#pragma mark - private
29
+
30
+-(void)removePendingNextModalIfOnTop {
31
+	NSString *containerId = [self.store.modalsToDismissArray lastObject];
32
+	
33
+	UIViewController *modalToDismiss = [self.store findContainerForId:containerId];
34
+	
35
+	if(!modalToDismiss) {
36
+		return;
37
+	}
38
+	
39
+	if (modalToDismiss == [self topPresentedVC]) {
40
+		[modalToDismiss dismissViewControllerAnimated:YES completion:^{
41
+			[self.store.modalsToDismissArray removeObject:containerId];
42
+			[self removePendingNextModalIfOnTop];
43
+		}];
44
+	}
45
+}
46
+
47
+-(UIViewController*)topPresentedVC {
48
+	UIViewController *root = UIApplication.sharedApplication.delegate.window.rootViewController;
49
+	while(root.presentedViewController) {
50
+		root = root.presentedViewController;
51
+	}
52
+	return root;
53
+}
54
+
55
+
56
+@end

+ 8
- 0
ios/ReactNativeNavigation.xcodeproj/project.pbxproj Voir le fichier

@@ -7,6 +7,8 @@
7 7
 	objects = {
8 8
 
9 9
 /* Begin PBXBuildFile section */
10
+		261F0E641E6EC94900989DE2 /* RNNModalManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 261F0E621E6EC94900989DE2 /* RNNModalManager.h */; };
11
+		261F0E651E6EC94900989DE2 /* RNNModalManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 261F0E631E6EC94900989DE2 /* RNNModalManager.m */; };
10 12
 		263905AE1E4C6F440023D7D3 /* MMDrawerBarButtonItem.h in Headers */ = {isa = PBXBuildFile; fileRef = 2639058A1E4C6F440023D7D3 /* MMDrawerBarButtonItem.h */; };
11 13
 		263905AF1E4C6F440023D7D3 /* MMDrawerBarButtonItem.m in Sources */ = {isa = PBXBuildFile; fileRef = 2639058B1E4C6F440023D7D3 /* MMDrawerBarButtonItem.m */; };
12 14
 		263905B01E4C6F440023D7D3 /* MMDrawerController+Subclass.h in Headers */ = {isa = PBXBuildFile; fileRef = 2639058C1E4C6F440023D7D3 /* MMDrawerController+Subclass.h */; };
@@ -80,6 +82,8 @@
80 82
 /* End PBXCopyFilesBuildPhase section */
81 83
 
82 84
 /* Begin PBXFileReference section */
85
+		261F0E621E6EC94900989DE2 /* RNNModalManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNNModalManager.h; sourceTree = "<group>"; };
86
+		261F0E631E6EC94900989DE2 /* RNNModalManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNNModalManager.m; sourceTree = "<group>"; };
83 87
 		2639058A1E4C6F440023D7D3 /* MMDrawerBarButtonItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MMDrawerBarButtonItem.h; sourceTree = "<group>"; };
84 88
 		2639058B1E4C6F440023D7D3 /* MMDrawerBarButtonItem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MMDrawerBarButtonItem.m; sourceTree = "<group>"; };
85 89
 		2639058C1E4C6F440023D7D3 /* MMDrawerController+Subclass.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "MMDrawerController+Subclass.h"; sourceTree = "<group>"; };
@@ -221,6 +225,8 @@
221 225
 		7B1E4C4B1E2D173700C3A525 /* Controllers */ = {
222 226
 			isa = PBXGroup;
223 227
 			children = (
228
+				261F0E621E6EC94900989DE2 /* RNNModalManager.h */,
229
+				261F0E631E6EC94900989DE2 /* RNNModalManager.m */,
224 230
 				26916C941E4B9CCC00D13680 /* RNNRootViewCreator.h */,
225 231
 				26916C961E4B9E7700D13680 /* RNNReactRootViewCreator.h */,
226 232
 				26916C971E4B9E7700D13680 /* RNNReactRootViewCreator.m */,
@@ -297,6 +303,7 @@
297 303
 				263905B51E4C6F440023D7D3 /* MMExampleDrawerVisualStateManager.h in Headers */,
298 304
 				263905C61E4C6F440023D7D3 /* SidebarFeedlyAnimation.h in Headers */,
299 305
 				7B1126A31E2D2B6C00F9B03B /* RNNSplashScreen.h in Headers */,
306
+				261F0E641E6EC94900989DE2 /* RNNModalManager.h in Headers */,
300 307
 				7B1126A51E2D2B6C00F9B03B /* RNN.h in Headers */,
301 308
 				263905C01E4C6F440023D7D3 /* SidebarAirbnbAnimation.h in Headers */,
302 309
 				263905E61E4CAC950023D7D3 /* RNNSideMenuChildVC.h in Headers */,
@@ -387,6 +394,7 @@
387 394
 				7BA500751E2544B9001B9E1B /* ReactNativeNavigation.m in Sources */,
388 395
 				263905B21E4C6F440023D7D3 /* MMDrawerController.m in Sources */,
389 396
 				7BBFE5441E25330E002A6182 /* RNNBridgeModule.m in Sources */,
397
+				261F0E651E6EC94900989DE2 /* RNNModalManager.m in Sources */,
390 398
 				7BEF0D1D1E43771B003E96B0 /* RNNLayoutNode.m in Sources */,
391 399
 				7BA500781E254908001B9E1B /* RNNSplashScreen.m in Sources */,
392 400
 				263905BA1E4C6F440023D7D3 /* RCCDrawerController.m in Sources */,