Browse Source

refactored animated prop

yogevbd 6 years ago
parent
commit
d40503670a

+ 1
- 1
lib/ios/RNNAnimator.m View File

@@ -33,7 +33,7 @@
33 33
 -(NSArray*)prepareSharedElementTransitionWithComponentView:(UIView*)componentView {
34 34
 	NSMutableArray* transitions = [NSMutableArray new];
35 35
 	for (NSDictionary* transition in self.transitionOptions.animations) {
36
-		RNNTransitionStateHolder* transitionStateHolder = [[RNNTransitionStateHolder alloc] initWithTransition:transition];
36
+		RNNTransitionStateHolder* transitionStateHolder = [[RNNTransitionStateHolder alloc] initWithDict:transition];
37 37
 		RNNTransition* transition = [[RNNTransition alloc] initFromVC:self.fromVC toVC:self.toVC transitionOptions:transitionStateHolder isBackButton:self.backButton];
38 38
 
39 39
 		[componentView addSubview:transition.animatedView];

+ 3
- 3
lib/ios/RNNModalManager.m View File

@@ -22,10 +22,10 @@
22 22
 -(void)showModalAfterLoad:(NSDictionary*)notif {
23 23
 	[[NSNotificationCenter defaultCenter] removeObserver:self name:@"RCTContentDidAppearNotification" object:nil];
24 24
 	RNNRootViewController *topVC = (RNNRootViewController*)[self topPresentedVC];
25
-	if (topVC.options.animations.showModal) {
25
+	if (topVC.options.animations.showModal.hasCustomAnimation) {
26 26
 		self.toVC.transitioningDelegate = topVC;
27 27
 	}
28
-	[topVC presentViewController:self.toVC animated:self.toVC.isAnimated completion:^{
28
+	[topVC presentViewController:self.toVC animated:self.toVC.options.animations.showModal.enabled completion:^{
29 29
 		if (_completionBlock) {
30 30
 			_completionBlock();
31 31
 			_completionBlock = nil;
@@ -74,7 +74,7 @@
74 74
 	}
75 75
 	
76 76
 	if (modalToDismiss == topPresentedVC || [[topPresentedVC childViewControllers] containsObject:modalToDismiss]) {
77
-		[modalToDismiss dismissViewControllerAnimated:modalToDismiss.isAnimated completion:^{
77
+		[modalToDismiss dismissViewControllerAnimated:modalToDismiss.options.animations.dismissModal.enabled completion:^{
78 78
 			[[_store pendingModalIdsToDismiss] removeObject:componentId];
79 79
 			[_store removeComponent:componentId];
80 80
 			[self removePendingNextModalIfOnTop];

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

@@ -16,11 +16,6 @@
16 16
 	return [((UIViewController<RNNRootViewProtocol>*)self.topViewController) isCustomViewController];
17 17
 }
18 18
 
19
-- (BOOL)isAnimated {
20
-	UIViewController<RNNRootViewProtocol>* rootVC = (UIViewController<RNNRootViewProtocol>*) self.topViewController;
21
-	return rootVC.isAnimated;
22
-}
23
-
24 19
 - (void)mergeOptions:(NSDictionary *)options {
25 20
 	[((UIViewController<RNNRootViewProtocol>*)self.topViewController) mergeOptions:options];
26 21
 }

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

@@ -26,7 +26,6 @@ extern const NSInteger TOP_BAR_TRANSPARENT_TAG;
26 26
 @property (nonatomic, strong) RNNTransitionsOptions* animations;
27 27
 
28 28
 
29
-@property (nonatomic, strong) NSNumber* animated;
30 29
 @property (nonatomic, strong) NSNumber* statusBarHidden;
31 30
 @property (nonatomic, strong) NSNumber* screenBackgroundColor;
32 31
 @property (nonatomic, strong) NSMutableDictionary* originalTopBarImages;

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

@@ -33,7 +33,6 @@ const NSInteger TOP_BAR_TRANSPARENT_TAG = 78264803;
33 33
 	self.rootBackgroundImage = [RCTConvert UIImage:[options objectForKey:@"rootBackgroundImage"]];
34 34
 	self.bottomTab = [[RNNBottomTabOptions alloc] initWithDict:[options objectForKey:@"bottomTab"]];
35 35
 	self.overlay = [[RNNOverlayOptions alloc] initWithDict:[options objectForKey:@"overlay"]];
36
-	self.animated = [options objectForKey:@"animated"];
37 36
 	self.customTransition = [[RNNAnimationOptions alloc] initWithDict:[options objectForKey:@"customTransition"]];
38 37
 	self.animations = [[RNNTransitionsOptions alloc] initWithDict:[options objectForKey:@"animations"]];
39 38
 

+ 10
- 10
lib/ios/RNNNavigationStackManager.m View File

@@ -30,7 +30,7 @@ dispatch_queue_t RCTGetUIManagerQueue(void);
30 30
 	self.fromVC = vc;
31 31
 	
32 32
 	
33
-	if (self.toVC.options.animations.push || self.toVC.isCustomTransitioned) {
33
+	if (self.toVC.options.animations.push.hasCustomAnimation || self.toVC.isCustomTransitioned) {
34 34
 		vc.navigationController.delegate = newTop;
35 35
 	} else {
36 36
 		vc.navigationController.delegate = nil;
@@ -57,7 +57,7 @@ dispatch_queue_t RCTGetUIManagerQueue(void);
57 57
 		}
58 58
 	}];
59 59
 	
60
-	[[self.fromVC navigationController] pushViewController:self.toVC animated:self.toVC.isAnimated];
60
+	[[self.fromVC navigationController] pushViewController:self.toVC animated:self.toVC.options.animations.push.enabled];
61 61
 	[CATransaction commit];
62 62
 	
63 63
 	self.toVC = nil;
@@ -71,35 +71,35 @@ dispatch_queue_t RCTGetUIManagerQueue(void);
71 71
 	if ([nvc topViewController] == vc) {
72 72
 		if (vc.options.animations.pop) {
73 73
 			nvc.delegate = vc;
74
-			[nvc popViewControllerAnimated:vc.isAnimated];
74
+			[nvc popViewControllerAnimated:vc.options.animations.pop.enabled];
75 75
 		} else {
76 76
 			nvc.delegate = nil;
77
-			[nvc popViewControllerAnimated:vc.isAnimated];
77
+			[nvc popViewControllerAnimated:vc.options.animations.pop.enabled];
78 78
 		}
79 79
 	} else {
80 80
 		NSMutableArray * vcs = nvc.viewControllers.mutableCopy;
81 81
 		[vcs removeObject:vc];
82
-		[nvc setViewControllers:vcs animated:YES];
82
+		[nvc setViewControllers:vcs animated:vc.options.animations.pop.enabled];
83 83
 	}
84 84
 	[_store removeComponent:componentId];
85 85
 }
86 86
 
87 87
 -(void)popTo:(NSString*)componentId {
88
-	UIViewController *vc = [_store findComponentForId:componentId];
88
+	RNNRootViewController *vc = (RNNRootViewController*)[_store findComponentForId:componentId];
89 89
 	
90 90
 	if (vc) {
91 91
 		UINavigationController *nvc = [vc navigationController];
92 92
 		if(nvc) {
93
-			NSArray *poppedVCs = [nvc popToViewController:vc animated:YES];
93
+			NSArray *poppedVCs = [nvc popToViewController:vc animated:vc.options.animations.pop.enabled];
94 94
 			[self removePopedViewControllers:poppedVCs];
95 95
 		}
96 96
 	}
97 97
 }
98 98
 
99 99
 -(void)popToRoot:(NSString*)componentId {
100
-	UIViewController* vc = [_store findComponentForId:componentId];
100
+	RNNRootViewController *vc = (RNNRootViewController*)[_store findComponentForId:componentId];
101 101
 	UINavigationController* nvc = [vc navigationController];
102
-	NSArray* poppedVCs = [nvc popToRootViewControllerAnimated:YES];
102
+	NSArray* poppedVCs = [nvc popToRootViewControllerAnimated:vc.options.animations.pop.enabled];
103 103
 	[self removePopedViewControllers:poppedVCs];
104 104
 }
105 105
 
@@ -113,7 +113,7 @@ dispatch_queue_t RCTGetUIManagerQueue(void);
113 113
 		}
114 114
 	}];
115 115
 	
116
-	[nvc setViewControllers:@[newRoot] animated:[newRoot.options.animated boolValue]];
116
+	[nvc setViewControllers:@[newRoot] animated:newRoot.options.animations.push.enabled];
117 117
 	
118 118
 	[CATransaction commit];
119 119
 }

+ 42
- 38
lib/ios/RNNRootViewController.m View File

@@ -5,7 +5,11 @@
5 5
 #import "RNNCustomTitleView.h"
6 6
 #import "RNNPushAnimation.h"
7 7
 
8
-@interface RNNRootViewController()
8
+@interface RNNRootViewController() {
9
+	UIView* _customTitleView;
10
+	UIView* _customTopBar;
11
+	UIView* _customTopBarBackground;
12
+}
9 13
 @property (nonatomic, strong) NSString* componentName;
10 14
 @property (nonatomic) BOOL _statusBarHidden;
11 15
 @property (nonatomic) BOOL isExternalComponent;
@@ -48,10 +52,8 @@
48 52
 
49 53
 -(void)viewWillAppear:(BOOL)animated{
50 54
 	[super viewWillAppear:animated];
51
-    if (!self._optionsApplied) {
52
-        [self.options applyOn:self];
53
-    }
54
-    self._optionsApplied = true;
55
+	[self.options applyOn:self];
56
+	[self optionsUpdated];
55 57
 }
56 58
 
57 59
 -(void)viewDidAppear:(BOOL)animated {
@@ -83,41 +85,47 @@
83 85
 }
84 86
 
85 87
 - (void)setCustomNavigationTitleView {
86
-	if (self.options.topBar.title.component.name) {
87
-		RCTRootView *reactView = (RCTRootView*)[_creator createRootViewFromComponentOptions:self.options.topBar.title.component];
88
-
89
-		RNNCustomTitleView *titleView = [[RNNCustomTitleView alloc] initWithFrame:self.navigationController.navigationBar.bounds subView:reactView alignment:self.options.topBar.title.component.alignment];
90
-        reactView.backgroundColor = UIColor.clearColor;
91
-		titleView.backgroundColor = UIColor.clearColor;
92
-		self.navigationItem.titleView = titleView;
93
-	} if ([self.navigationItem.title isKindOfClass:[RNNCustomTitleView class]]) {
94
-		self.navigationItem.title = nil;
88
+	if (!_customTitleView) {
89
+		if (self.options.topBar.title.component.name) {
90
+			RCTRootView *reactView = (RCTRootView*)[_creator createRootViewFromComponentOptions:self.options.topBar.title.component];
91
+			
92
+			_customTitleView = [[RNNCustomTitleView alloc] initWithFrame:self.navigationController.navigationBar.bounds subView:reactView alignment:self.options.topBar.title.component.alignment];
93
+			reactView.backgroundColor = UIColor.clearColor;
94
+			_customTitleView.backgroundColor = UIColor.clearColor;
95
+			self.navigationItem.titleView = _customTitleView;
96
+		} if ([self.navigationItem.title isKindOfClass:[RNNCustomTitleView class]] && !_customTitleView) {
97
+			self.navigationItem.title = nil;
98
+		}
95 99
 	}
96 100
 }
97 101
 
98 102
 - (void)setCustomNavigationBarView {
99
-	if (self.options.topBar.component.name) {
100
-		RCTRootView *reactView = (RCTRootView*)[_creator createRootViewFromComponentOptions:self.options.topBar.component];
101
-
102
-		RNNCustomTitleView *titleView = [[RNNCustomTitleView alloc] initWithFrame:self.navigationController.navigationBar.bounds subView:reactView alignment:@"fill"];
103
-		reactView.backgroundColor = UIColor.clearColor;
104
-		titleView.backgroundColor = UIColor.clearColor;
105
-		[self.navigationController.navigationBar addSubview:titleView];
106
-	} else if ([[self.navigationController.navigationBar.subviews lastObject] isKindOfClass:[RNNCustomTitleView class]]) {
107
-		[[self.navigationController.navigationBar.subviews lastObject] removeFromSuperview];
103
+	if (!_customTopBar) {
104
+		if (self.options.topBar.component.name) {
105
+			RCTRootView *reactView = (RCTRootView*)[_creator createRootViewFromComponentOptions:self.options.topBar.component];
106
+			
107
+			_customTopBar = [[RNNCustomTitleView alloc] initWithFrame:self.navigationController.navigationBar.bounds subView:reactView alignment:@"fill"];
108
+			reactView.backgroundColor = UIColor.clearColor;
109
+			_customTopBar.backgroundColor = UIColor.clearColor;
110
+			[self.navigationController.navigationBar addSubview:_customTopBar];
111
+		} else if ([[self.navigationController.navigationBar.subviews lastObject] isKindOfClass:[RNNCustomTitleView class]] && !_customTopBar) {
112
+			[[self.navigationController.navigationBar.subviews lastObject] removeFromSuperview];
113
+		}
108 114
 	}
109 115
 }
110 116
 
111 117
 - (void)setCustomNavigationComponentBackground {
112
-	if (self.options.topBar.background.component.name) {
113
-		RCTRootView *reactView = (RCTRootView*)[_creator createRootViewFromComponentOptions:self.options.topBar.background.component];
114
-
115
-		RNNCustomTitleView *titleView = [[RNNCustomTitleView alloc] initWithFrame:self.navigationController.navigationBar.bounds subView:reactView alignment:@"fill"];
116
-		[self.navigationController.navigationBar insertSubview:titleView atIndex:1];
117
-		self.navigationController.navigationBar.clipsToBounds = YES;
118
-	} else if ([[self.navigationController.navigationBar.subviews objectAtIndex:1] isKindOfClass:[RNNCustomTitleView class]]) {
119
-		[[self.navigationController.navigationBar.subviews objectAtIndex:1] removeFromSuperview];
120
-		self.navigationController.navigationBar.clipsToBounds = NO;
118
+	if (!_customTopBarBackground) {
119
+		if (self.options.topBar.background.component.name) {
120
+			RCTRootView *reactView = (RCTRootView*)[_creator createRootViewFromComponentOptions:self.options.topBar.background.component];
121
+			
122
+			_customTopBarBackground = [[RNNCustomTitleView alloc] initWithFrame:self.navigationController.navigationBar.bounds subView:reactView alignment:@"fill"];
123
+			[self.navigationController.navigationBar insertSubview:_customTopBarBackground atIndex:1];
124
+			self.navigationController.navigationBar.clipsToBounds = YES;
125
+		} else if ([[self.navigationController.navigationBar.subviews objectAtIndex:1] isKindOfClass:[RNNCustomTitleView class]]) {
126
+			[[self.navigationController.navigationBar.subviews objectAtIndex:1] removeFromSuperview];
127
+			self.navigationController.navigationBar.clipsToBounds = NO;
128
+		}
121 129
 	}
122 130
 }
123 131
 
@@ -125,10 +133,6 @@
125 133
 	return self.options.customTransition.animations != nil;
126 134
 }
127 135
 
128
-- (BOOL)isAnimated {
129
-	return self.options.animated ? [self.options.animated boolValue] : YES;
130
-}
131
-
132 136
 - (BOOL)isCustomViewController {
133 137
 	return self.isExternalComponent;
134 138
 }
@@ -176,9 +180,9 @@
176 180
 {
177 181
 	if (self.animator) {
178 182
 		return self.animator;
179
-	} else if (operation == UINavigationControllerOperationPush && self.options.animations.push) {
183
+	} else if (operation == UINavigationControllerOperationPush && self.options.animations.push.hasCustomAnimation) {
180 184
 		return [[RNNPushAnimation alloc] initWithScreenTransition:self.options.animations.push];
181
-	} else if (operation == UINavigationControllerOperationPop && self.options.animations.pop) {
185
+	} else if (operation == UINavigationControllerOperationPop && self.options.animations.pop.hasCustomAnimation) {
182 186
 		return [[RNNPushAnimation alloc] initWithScreenTransition:self.options.animations.pop];
183 187
 	} else {
184 188
 		return nil;

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

@@ -5,12 +5,11 @@
5 5
 @optional
6 6
 - (void)mergeOptions:(NSDictionary*)options;
7 7
 - (BOOL)isCustomViewController;
8
-- (void)optionsUpdated;
9 8
 - (void)performOnRotation:(void (^)(void))block;
9
+- (void)optionsUpdated;
10 10
 
11 11
 @required
12 12
 - (BOOL)isCustomTransitioned;
13
-- (BOOL)isAnimated;
14 13
 - (RNNNavigationOptions*)options;
15 14
 - (NSString *)componentId;
16 15
 

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

@@ -7,4 +7,8 @@
7 7
 @property (nonatomic, strong) RNNTransitionStateHolder* content;
8 8
 @property (nonatomic, strong) RNNTransitionStateHolder* bottomTabs;
9 9
 
10
+@property (nonatomic) BOOL enabled;
11
+
12
+- (BOOL)hasCustomAnimation;
13
+
10 14
 @end

+ 11
- 4
lib/ios/RNNScreenTransition.m View File

@@ -4,11 +4,18 @@
4 4
 
5 5
 - (instancetype)initWithDict:(NSDictionary *)dict {
6 6
 	self = [super init];
7
-	self.topBar = [[RNNTransitionStateHolder alloc] initWithTransition:dict[@"topBar"]];
8
-	self.content = [[RNNTransitionStateHolder alloc] initWithTransition:dict[@"content"]];
9
-	self.bottomTabs = [[RNNTransitionStateHolder alloc] initWithTransition:dict[@"bottomTabs"]];
10
-	
7
+
8
+	self.topBar = dict[@"topBar"] ? [[RNNTransitionStateHolder alloc] initWithDict:dict[@"topBar"]] : nil;
9
+	self.content = dict[@"content"] ? [[RNNTransitionStateHolder alloc] initWithDict:dict[@"content"]] : nil;
10
+	self.bottomTabs = dict[@"bottomTabs"] ? [[RNNTransitionStateHolder alloc] initWithDict:dict[@"bottomTabs"]] : nil;
11
+
12
+	self.enabled = dict[@"enabled"] ? [dict[@"enabled"] boolValue] : YES;
13
+
11 14
 	return self;
12 15
 }
13 16
 
17
+- (BOOL)hasCustomAnimation {
18
+	return (self.topBar || self.content || self.bottomTabs);
19
+}
20
+
14 21
 @end

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

@@ -37,10 +37,6 @@
37 37
 	return NO;
38 38
 }
39 39
 
40
-- (BOOL)isAnimated {
41
-	return YES;
42
-}
43
-
44 40
 - (RNNOptions *)options {
45 41
 	return nil;
46 42
 }

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

@@ -76,10 +76,6 @@
76 76
 	return NO;
77 77
 }
78 78
 
79
-- (BOOL)isAnimated {
80
-	return YES;
81
-}
82
-
83 79
 - (RNNOptions *)options {
84 80
 	return nil;
85 81
 }

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

@@ -37,10 +37,6 @@
37 37
 	return NO;
38 38
 }
39 39
 
40
-- (BOOL)isAnimated {
41
-	return YES;
42
-}
43
-
44 40
 - (RNNOptions *)options {
45 41
 	return nil;
46 42
 }

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

@@ -76,10 +76,6 @@
76 76
 	return NO;
77 77
 }
78 78
 
79
-- (BOOL)isAnimated {
80
-	return YES;
81
-}
82
-
83 79
 - (RNNOptions *)options {
84 80
 	return nil;
85 81
 }

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

@@ -20,8 +20,6 @@
20 20
 @property (nonatomic) double endX;
21 21
 @property (nonatomic) UIViewAnimationOptions interpolation;
22 22
 
23
-- (instancetype)initWithTransition:(NSDictionary*)transition;
24
-
25 23
 - (void)setupInitialTransitionForView:(UIView *)view;
26 24
 
27 25
 - (void)completeTransitionForView:(UIView*)view;

+ 19
- 1
lib/ios/RNNTransitionStateHolder.m View File

@@ -8,7 +8,7 @@
8 8
 @end
9 9
 @implementation RNNTransitionStateHolder
10 10
 
11
--(instancetype)initWithTransition:(NSDictionary *)transition {
11
+-(instancetype)initWithDict:(NSDictionary *)transition {
12 12
 	self = [super init];
13 13
 	
14 14
 	self.springDamping = [RNNUtils getDoubleOrKey:transition withKey:@"springDamping" withDefault:0.85];
@@ -31,6 +31,24 @@
31 31
 	return self;
32 32
 }
33 33
 
34
+- (void)mergeWith:(NSDictionary *)transition {
35
+	self.springDamping = [RNNUtils getDoubleOrKey:transition withKey:@"springDamping" withDefault:0.85];
36
+	self.springVelocity = [RNNUtils getDoubleOrKey:transition withKey:@"springVelocity" withDefault:0.8];
37
+	self.startDelay = [RNNUtils getDoubleOrKey:transition withKey:@"startDelay" withDefault:0];
38
+	self.duration = [RNNUtils getDoubleOrKey:transition withKey:@"duration" withDefault:1];
39
+	self.startAlpha = [RNNUtils getDoubleOrKey:transition withKey:@"startAlpha" withDefault:1];
40
+	self.endAlpha = [RNNUtils getDoubleOrKey:transition withKey:@"endAlpha" withDefault:1];
41
+	self.interactivePop = [RNNUtils getBoolOrKey:transition withKey:@"interactivePop" withDefault:NO];
42
+	self.startX = [RNNUtils getDoubleOrKey:transition[@"x"] withKey:@"from" withDefault:0];
43
+	self.startY = [RNNUtils getDoubleOrKey:transition[@"y"] withKey:@"from" withDefault:0];
44
+	self.endX = [RNNUtils getDoubleOrKey:transition[@"x"] withKey:@"to" withDefault:0];
45
+	self.endY = [RNNUtils getDoubleOrKey:transition[@"y"] withKey:@"to" withDefault:0];
46
+	self.fromId = [transition objectForKey:@"fromId"];
47
+	self.toId = [transition objectForKey:@"toId"];
48
+	self.isSharedElementTransition = [[transition objectForKey:@"type"] isEqualToString:@"sharedElement"];
49
+	self.interpolation = [self animationOptionsFromString:transition[@"interpolation"]];
50
+}
51
+
34 52
 - (UIViewAnimationOptions)animationOptionsFromString:(NSString*)interpolationString {
35 53
 	if ([interpolationString isEqualToString:@"accelerate"]) {
36 54
 		return UIViewAnimationOptionCurveEaseIn;

+ 1
- 8
lib/ios/RNNTransitionsOptions.m View File

@@ -3,18 +3,11 @@
3 3
 @implementation RNNTransitionsOptions
4 4
 
5 5
 - (instancetype)initWithDict:(NSDictionary *)dict {
6
-	self = [super init];
6
+	self = [super initWithDict:dict];
7 7
 	
8 8
 	[self mergeWith:dict];
9 9
 	
10 10
 	return self;
11 11
 }
12 12
 
13
-- (void)mergeWith:(NSDictionary *)otherOptions {
14
-	self.push = otherOptions[@"push"] ? [[RNNScreenTransition alloc] initWithDict:otherOptions[@"push"]] : _push;
15
-	self.pop = otherOptions[@"pop"] ? [[RNNScreenTransition alloc] initWithDict:otherOptions[@"pop"]] : _pop;
16
-	self.showModal = otherOptions[@"showModal"] ? [[RNNScreenTransition alloc] initWithDict:otherOptions[@"showModal"]] : _showModal;
17
-	self.dismissModal = otherOptions[@"dismissModal"] ? [[RNNScreenTransition alloc] initWithDict:otherOptions[@"dismissModal"]] : _dismissModal;
18
-}
19
-
20 13
 @end

+ 5
- 1
playground/src/screens/WelcomeScreen.js View File

@@ -302,7 +302,11 @@ class WelcomeScreen extends Component {
302 302
       component: {
303 303
         name: 'navigation.playground.OptionsScreen',
304 304
         options: {
305
-          animated: false
305
+          animations: {
306
+            push: {
307
+              enabled: false
308
+            }
309
+          }
306 310
         }
307 311
       }
308 312
     });