Browse Source

waitForRender animation options

yogevbd 6 years ago
parent
commit
fba6fc572e

+ 2
- 2
lib/ios/RNNCommandsHandler.m View File

@@ -128,8 +128,8 @@ static NSString* const setDefaultOptions	= @"setDefaultOptions";
128 128
 			[rootVc registerForPreviewingWithDelegate:(id)rootVc sourceView:elementView];
129 129
 		}
130 130
 	} else {
131
-		[newVc onReactViewReady:^{
132
-			id animationDelegate = (newVc.options.animations.push.hasCustomAnimation || newVc.isCustomTransitioned) ? newVc : nil;
131
+		id animationDelegate = (newVc.options.animations.push.hasCustomAnimation || newVc.isCustomTransitioned) ? newVc : nil;
132
+		[newVc waitForReactViewRender:newVc.options.animations.push.waitForRender perform:^{
133 133
 			[_stackManager push:newVc onTop:fromVC animated:newVc.options.animations.push.enable animationDelegate:animationDelegate completion:^{
134 134
 				[_eventEmitter sendOnNavigationCommandCompletion:push params:@{@"componentId": componentId}];
135 135
 				completion();

+ 4
- 8
lib/ios/RNNModalManager.m View File

@@ -12,21 +12,15 @@
12 12
 	_store = store;
13 13
 	return self;
14 14
 }
15
--(void)waitForContentToAppearAndThen:(SEL)nameOfSelector {
16
-	[[NSNotificationCenter defaultCenter] addObserver:self
17
-											 selector:nameOfSelector
18
-												 name: @"RCTContentDidAppearNotification"
19
-											   object:nil];
20
-}
21 15
 
22 16
 -(void)showModalAfterLoad:(NSDictionary*)notif {
23
-	[[NSNotificationCenter defaultCenter] removeObserver:self name:@"RCTContentDidAppearNotification" object:nil];
24 17
 	RNNRootViewController *topVC = (RNNRootViewController*)[self topPresentedVC];
25 18
 	topVC.definesPresentationContext = YES;
26 19
 	
27 20
 	if (topVC.options.animations.showModal.hasCustomAnimation) {
28 21
 		self.toVC.transitioningDelegate = topVC;
29 22
 	}
23
+	
30 24
 	[topVC presentViewController:self.toVC animated:self.toVC.options.animations.showModal.enable completion:^{
31 25
 		if (_completionBlock) {
32 26
 			_completionBlock();
@@ -49,7 +43,9 @@
49 43
     ) {
50 44
 		[self showModalAfterLoad:nil];
51 45
 	} else {
52
-		[self waitForContentToAppearAndThen:@selector(showModalAfterLoad:)];
46
+		[self.toVC waitForReactViewRender:self.toVC.options.animations.showModal.waitForRender perform:^{
47
+			[self showModalAfterLoad:nil];
48
+		}];
53 49
 	}
54 50
 }
55 51
 

+ 8
- 0
lib/ios/RNNNavigationController.m View File

@@ -36,6 +36,10 @@
36 36
 	[self.getTopViewController applyModalOptions];
37 37
 }
38 38
 
39
+- (UIViewController *)popViewControllerAnimated:(BOOL)animated {
40
+	return [super popViewControllerAnimated:animated];
41
+}
42
+
39 43
 - (NSString *)componentId {
40 44
 	return _componentId ? _componentId : self.getTopViewController.componentId;
41 45
 }
@@ -52,6 +56,10 @@
52 56
 	return self.getTopViewController.options;
53 57
 }
54 58
 
59
+- (void)waitForReactViewRender:(BOOL)wait perform:(RNNReactViewReadyCompletionBlock)readyBlock {
60
+	[self.getTopViewController waitForReactViewRender:wait perform:readyBlock];
61
+}
62
+
55 63
 - (UIViewController *)childViewControllerForStatusBarStyle {
56 64
 	return self.topViewController;
57 65
 }

+ 0
- 4
lib/ios/RNNRootViewController.h View File

@@ -11,8 +11,6 @@
11 11
 
12 12
 @class RNNRootViewController;
13 13
 
14
-typedef void (^RNNReactViewReadyCompletionBlock)(void);
15
-
16 14
 @interface RNNRootViewController : UIViewController	<RNNRootViewProtocol, UIViewControllerPreviewingDelegate, UISearchResultsUpdating, UISearchBarDelegate>
17 15
 
18 16
 @property (nonatomic, strong) RNNNavigationOptions* options;
@@ -31,8 +29,6 @@ typedef void (^RNNReactViewReadyCompletionBlock)(void);
31 29
 			   eventEmitter:(RNNEventEmitter*)eventEmitter
32 30
 		  isExternalComponent:(BOOL)isExternalComponent;
33 31
 
34
-- (void)onReactViewReady:(RNNReactViewReadyCompletionBlock)readyBlock;
35
-
36 32
 -(void)applyTabBarItem;
37 33
 -(void)applyTopTabsOptions;
38 34
 

+ 8
- 0
lib/ios/RNNRootViewController.m View File

@@ -91,6 +91,14 @@
91 91
 	[[NSNotificationCenter defaultCenter] removeObserver:self name:@"RCTContentDidAppearNotification" object:nil];
92 92
 }
93 93
 
94
+- (void)waitForReactViewRender:(BOOL)wait perform:(RNNReactViewReadyCompletionBlock)readyBlock {
95
+	if (wait) {
96
+		[self onReactViewReady:readyBlock];
97
+	} else {
98
+		readyBlock();
99
+	}
100
+}
101
+
94 102
 - (void)onReactViewReady:(RNNReactViewReadyCompletionBlock)readyBlock {
95 103
 	if (self.isCustomViewController) {
96 104
 		readyBlock();

+ 2
- 0
lib/ios/RNNRootViewProtocol.h View File

@@ -1,4 +1,5 @@
1 1
 #import "RNNNavigationOptions.h"
2
+typedef void (^RNNReactViewReadyCompletionBlock)(void);
2 3
 
3 4
 @protocol RNNRootViewProtocol <NSObject, UINavigationControllerDelegate, UIViewControllerTransitioningDelegate, UISplitViewControllerDelegate>
4 5
 
@@ -13,6 +14,7 @@
13 14
 
14 15
 @required
15 16
 - (NSString *)componentId;
17
+- (void)waitForReactViewRender:(BOOL)wait perform:(RNNReactViewReadyCompletionBlock)readyBlock;
16 18
 
17 19
 @end
18 20
 

+ 1
- 0
lib/ios/RNNScreenTransition.h View File

@@ -8,6 +8,7 @@
8 8
 @property (nonatomic, strong) RNNTransitionStateHolder* bottomTabs;
9 9
 
10 10
 @property (nonatomic) BOOL enable;
11
+@property (nonatomic) BOOL waitForRender;
11 12
 
12 13
 - (BOOL)hasCustomAnimation;
13 14
 

+ 1
- 0
lib/ios/RNNScreenTransition.m View File

@@ -10,6 +10,7 @@
10 10
 	self.bottomTabs = dict[@"bottomTabs"] ? [[RNNTransitionStateHolder alloc] initWithDict:dict[@"bottomTabs"]] : nil;
11 11
 
12 12
 	self.enable = dict[@"enabled"] ? [dict[@"enabled"] boolValue] : YES;
13
+	self.waitForRender = dict[@"waitForRender"] ? [dict[@"waitForRender"] boolValue] : NO;
13 14
 
14 15
 	return self;
15 16
 }

+ 4
- 0
lib/ios/RNNSideMenuChildVC.m View File

@@ -35,6 +35,10 @@
35 35
 	[self.child mergeOptions:options];
36 36
 }
37 37
 
38
+- (void)waitForReactViewRender:(BOOL)wait perform:(RNNReactViewReadyCompletionBlock)readyBlock {
39
+	[self.child waitForReactViewRender:wait perform:readyBlock];
40
+}
41
+
38 42
 - (UIStatusBarStyle)preferredStatusBarStyle {
39 43
 	return self.child.preferredStatusBarStyle;
40 44
 }

+ 4
- 0
lib/ios/RNNSideMenuController.m View File

@@ -93,6 +93,10 @@
93 93
 	[self.center mergeOptions:options];
94 94
 }
95 95
 
96
+- (void)waitForReactViewRender:(BOOL)wait perform:(RNNReactViewReadyCompletionBlock)readyBlock {
97
+	[self.center waitForReactViewRender:wait perform:readyBlock];
98
+}
99
+
96 100
 - (NSString *)componentId {
97 101
 	return _center.componentId;
98 102
 }

+ 4
- 0
lib/ios/RNNSplitViewController.m View File

@@ -33,6 +33,10 @@
33 33
 - (void)optionsUpdated {
34 34
 }
35 35
 
36
+- (void)waitForReactViewRender:(BOOL)wait perform:(RNNReactViewReadyCompletionBlock)readyBlock {
37
+	readyBlock();
38
+}
39
+
36 40
 - (void)mergeOptions:(RNNOptions *)options {
37 41
 	[self.options mergeOptions:options];
38 42
 }

+ 4
- 0
lib/ios/RNNTabBarController.m View File

@@ -45,6 +45,10 @@
45 45
 	[((UIViewController<RNNRootViewProtocol>*)self.selectedViewController) mergeOptions:options];
46 46
 }
47 47
 
48
+- (void)waitForReactViewRender:(BOOL)wait perform:(RNNReactViewReadyCompletionBlock)readyBlock {
49
+	[((UIViewController<RNNRootViewProtocol>*)self.selectedViewController) waitForReactViewRender:wait perform:readyBlock];
50
+}
51
+
48 52
 - (RNNNavigationOptions *)options {
49 53
 	return [((UIViewController<RNNRootViewProtocol>*)self.selectedViewController) options];
50 54
 }

+ 4
- 0
lib/ios/RNNTopTabsViewController.m View File

@@ -76,4 +76,8 @@
76 76
 	return _currentViewController.componentId;
77 77
 }
78 78
 
79
+- (void)waitForReactViewRender:(BOOL)wait perform:(RNNReactViewReadyCompletionBlock)readyBlock {
80
+	[_currentViewController waitForReactViewRender:wait perform:readyBlock];
81
+}
82
+
79 83
 @end