Browse Source

overlay refactor

yogevbd 6 years ago
parent
commit
8ff8783ca4
3 changed files with 33 additions and 48 deletions
  1. 12
    10
      lib/ios/RNNCommandsHandler.m
  2. 2
    4
      lib/ios/RNNOverlayManager.h
  3. 19
    34
      lib/ios/RNNOverlayManager.m

+ 12
- 10
lib/ios/RNNCommandsHandler.m View File

7
 #import "RNNSplitViewController.h"
7
 #import "RNNSplitViewController.h"
8
 #import "RNNElementFinder.h"
8
 #import "RNNElementFinder.h"
9
 #import "React/RCTUIManager.h"
9
 #import "React/RCTUIManager.h"
10
-
10
+#import "RNNErrorHandler.h"
11
 
11
 
12
 static NSString* const setRoot	= @"setRoot";
12
 static NSString* const setRoot	= @"setRoot";
13
 static NSString* const setStackRoot	= @"setStackRoot";
13
 static NSString* const setStackRoot	= @"setStackRoot";
40
 	_eventEmitter = eventEmitter;
40
 	_eventEmitter = eventEmitter;
41
 	_modalManager = [[RNNModalManager alloc] initWithStore:_store];
41
 	_modalManager = [[RNNModalManager alloc] initWithStore:_store];
42
 	_stackManager = [[RNNNavigationStackManager alloc] init];
42
 	_stackManager = [[RNNNavigationStackManager alloc] init];
43
-	_overlayManager = [[RNNOverlayManager alloc] initWithStore:_store];
43
+	_overlayManager = [[RNNOverlayManager alloc] init];
44
 	return self;
44
 	return self;
45
 }
45
 }
46
 
46
 
249
 	[self assertReady];
249
 	[self assertReady];
250
 
250
 
251
 	UIViewController<RNNRootViewProtocol>* overlayVC = [_controllerFactory createOverlay:layout];
251
 	UIViewController<RNNRootViewProtocol>* overlayVC = [_controllerFactory createOverlay:layout];
252
-	[_overlayManager showOverlay:overlayVC completion:^{
253
-		[_eventEmitter sendOnNavigationCommandCompletion:showOverlay params:@{@"layout": layout}];
254
-		completion();
255
-	}];
252
+	[_overlayManager showOverlay:overlayVC];
253
+	[_eventEmitter sendOnNavigationCommandCompletion:showOverlay params:@{@"layout": layout}];
254
+	completion();
256
 }
255
 }
257
 
256
 
258
 - (void)dismissOverlay:(NSString*)componentId completion:(RNNTransitionCompletionBlock)completion rejection:(RNNTransitionRejectionBlock)reject {
257
 - (void)dismissOverlay:(NSString*)componentId completion:(RNNTransitionCompletionBlock)completion rejection:(RNNTransitionRejectionBlock)reject {
259
 	[self assertReady];
258
 	[self assertReady];
260
-
261
-	[_overlayManager dismissOverlay:componentId completion:^{
262
-		[_eventEmitter sendOnNavigationCommandCompletion:dismissModal params:@{@"componentId": componentId}];
259
+	UIViewController* viewController = [_store findComponentForId:componentId];
260
+	if (viewController) {
261
+		[_overlayManager dismissOverlay:viewController];
262
+		[_eventEmitter sendOnNavigationCommandCompletion:dismissOverlay params:@{@"componentId": componentId}];
263
 		completion();
263
 		completion();
264
-	} rejection:reject];
264
+	} else {
265
+		[RNNErrorHandler reject:reject withErrorCode:1010 errorDescription:@"ComponentId not found"];
266
+	}
265
 }
267
 }
266
 
268
 
267
 #pragma mark - private
269
 #pragma mark - private

+ 2
- 4
lib/ios/RNNOverlayManager.h View File

5
 
5
 
6
 @interface RNNOverlayManager : NSObject
6
 @interface RNNOverlayManager : NSObject
7
 
7
 
8
-- (instancetype)initWithStore:(RNNStore*)store;
9
-
10
-- (void)showOverlay:(UIViewController*)viewController completion:(RNNTransitionCompletionBlock)completion;
11
-- (void)dismissOverlay:(NSString*)componentId completion:(RNNTransitionCompletionBlock)completion rejection:(RNNTransitionRejectionBlock)reject;
8
+- (void)showOverlay:(UIViewController*)viewController;
9
+- (void)dismissOverlay:(UIViewController*)viewController;
12
 
10
 
13
 @end
11
 @end

+ 19
- 34
lib/ios/RNNOverlayManager.m View File

1
 #import "RNNOverlayManager.h"
1
 #import "RNNOverlayManager.h"
2
-#import "RNNErrorHandler.h"
3
 #import "RNNOverlayWindow.h"
2
 #import "RNNOverlayWindow.h"
4
 
3
 
5
 @implementation RNNOverlayManager {
4
 @implementation RNNOverlayManager {
6
-	NSMutableDictionary* _overlayDict;
7
-	NSMutableDictionary* _overlayWindows;
8
-	RNNStore* _store;
5
+	NSMutableArray* _overlayWindows;
9
 }
6
 }
10
 
7
 
11
-- (instancetype)initWithStore:(RNNStore *)store {
8
+- (instancetype)init {
12
 	self = [super init];
9
 	self = [super init];
13
-	_overlayDict = [[NSMutableDictionary alloc] init];
14
-	_overlayWindows = [[NSMutableDictionary alloc] init];
15
-	_store = store;
10
+	_overlayWindows = [[NSMutableArray alloc] init];
16
 	return self;
11
 	return self;
17
 }
12
 }
18
 
13
 
19
 #pragma mark - public
14
 #pragma mark - public
20
 
15
 
21
-- (void)showOverlay:(RNNRootViewController *)viewController completion:(RNNTransitionCompletionBlock)completion {
22
-	[self cacheOverlay:viewController];
16
+- (void)showOverlay:(UIViewController *)viewController {
23
 	UIWindow* overlayWindow = [[RNNOverlayWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
17
 	UIWindow* overlayWindow = [[RNNOverlayWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
24
-	[_overlayWindows setObject:overlayWindow forKey:viewController.componentId];
18
+	[_overlayWindows addObject:overlayWindow];
25
 	[overlayWindow setWindowLevel:UIWindowLevelNormal];
19
 	[overlayWindow setWindowLevel:UIWindowLevelNormal];
26
 	[overlayWindow setRootViewController:viewController];
20
 	[overlayWindow setRootViewController:viewController];
27
 	[overlayWindow setHidden:NO];
21
 	[overlayWindow setHidden:NO];
28
-	
29
-	completion();
30
 }
22
 }
31
 
23
 
32
-- (void)dismissOverlay:(NSString*)componentId completion:(RNNTransitionCompletionBlock)completion rejection:(RNNTransitionRejectionBlock)reject {
33
-	RNNRootViewController* viewController = [_overlayDict objectForKey:componentId];
34
-	if (viewController) {
35
-		[self detachOverlayWindow:componentId];
36
-		[self removeCachedOverlay:viewController];
37
-		completion();
38
-	} else {
39
-		[RNNErrorHandler reject:reject withErrorCode:1010 errorDescription:@"ComponentId not found"];
40
-	}
24
+- (void)dismissOverlay:(UIViewController*)viewController {
25
+	UIWindow* overlayWindow = [self findWindowByRootViewController:viewController];
26
+	[self detachOverlayWindow:overlayWindow];
41
 }
27
 }
42
 
28
 
43
 #pragma mark - private
29
 #pragma mark - private
44
 
30
 
45
-- (void)cacheOverlay:(RNNRootViewController*)viewController {
46
-	[_overlayDict setObject:viewController forKey:viewController.componentId];
47
-}
48
-
49
-- (void)removeCachedOverlay:(RNNRootViewController*)viewController {
50
-	[_overlayDict removeObjectForKey:viewController.componentId];
51
-	[_store removeComponent:viewController.componentId];
31
+- (void)detachOverlayWindow:(UIWindow *)overlayWindow {
32
+	[overlayWindow setHidden:YES];
33
+	[_overlayWindows removeObject:overlayWindow];
52
 }
34
 }
53
 
35
 
54
-- (void)detachOverlayWindow:(NSString *)componentId {
55
-	UIWindow* overlayWindow = [_overlayWindows objectForKey:componentId];
56
-	[overlayWindow setHidden:YES];
57
-	[overlayWindow setRootViewController:nil];
58
-	overlayWindow = nil;
36
+- (UIWindow *)findWindowByRootViewController:(UIViewController *)viewController {
37
+	for (UIWindow* window in _overlayWindows) {
38
+		if ([window.rootViewController isEqual:viewController]) {
39
+			return window;
40
+		}
41
+	}
42
+	
43
+	return nil;
59
 }
44
 }
60
 
45
 
61
 @end
46
 @end