|
@@ -7,9 +7,9 @@
|
7
|
7
|
#import "InteractivePopGestureDelegate.h"
|
8
|
8
|
|
9
|
9
|
@interface RNNStackPresenter() {
|
10
|
|
- RNNReactComponentRegistry* _componentRegistry;
|
11
|
|
- UIView* _customTopBarBackground;
|
12
|
|
- RNNReactView* _topBarBackgroundReactView;
|
|
10
|
+ RNNReactComponentRegistry* _componentRegistry;
|
|
11
|
+ UIView* _customTopBarBackground;
|
|
12
|
+ RNNReactView* _topBarBackgroundReactView;
|
13
|
13
|
TopBarPresenter* _topBarPresenter;
|
14
|
14
|
InteractivePopGestureDelegate *_interactivePopGestureDelegate;
|
15
|
15
|
}
|
|
@@ -20,10 +20,10 @@
|
20
|
20
|
@implementation RNNStackPresenter
|
21
|
21
|
|
22
|
22
|
- (instancetype)initWithComponentRegistry:(RNNReactComponentRegistry *)componentRegistry defaultOptions:(RNNNavigationOptions *)defaultOptions {
|
23
|
|
- self = [super initWithDefaultOptions:defaultOptions];
|
24
|
|
- _componentRegistry = componentRegistry;
|
|
23
|
+ self = [super initWithDefaultOptions:defaultOptions];
|
|
24
|
+ _componentRegistry = componentRegistry;
|
25
|
25
|
_interactivePopGestureDelegate = [InteractivePopGestureDelegate new];
|
26
|
|
- return self;
|
|
26
|
+ return self;
|
27
|
27
|
}
|
28
|
28
|
|
29
|
29
|
- (void)bindViewController:(UINavigationController *)boundViewController {
|
|
@@ -46,149 +46,149 @@
|
46
|
46
|
}
|
47
|
47
|
|
48
|
48
|
- (void)applyOptions:(RNNNavigationOptions *)options {
|
49
|
|
- [super applyOptions:options];
|
50
|
|
- RNNStackController* stack = self.stackController;
|
51
|
|
- RNNNavigationOptions * withDefault = [options withDefault:[self defaultOptions]];
|
52
|
|
-
|
|
49
|
+ [super applyOptions:options];
|
|
50
|
+ RNNStackController* stack = self.stackController;
|
|
51
|
+ RNNNavigationOptions * withDefault = [options withDefault:[self defaultOptions]];
|
|
52
|
+
|
53
|
53
|
[_interactivePopGestureDelegate setEnabled:[withDefault.popGesture getWithDefaultValue:YES]];
|
54
|
|
- stack.interactivePopGestureRecognizer.delegate = _interactivePopGestureDelegate;
|
|
54
|
+ stack.interactivePopGestureRecognizer.delegate = _interactivePopGestureDelegate;
|
55
|
55
|
|
56
|
56
|
[stack setBarStyle:[RCTConvert UIBarStyle:[withDefault.topBar.barStyle getWithDefaultValue:@"default"]]];
|
57
|
|
- [stack setRootBackgroundImage:[withDefault.rootBackgroundImage getWithDefaultValue:nil]];
|
58
|
|
- [stack setNavigationBarTestId:[withDefault.topBar.testID getWithDefaultValue:nil]];
|
59
|
|
- [stack setNavigationBarVisible:[withDefault.topBar.visible getWithDefaultValue:YES] animated:[withDefault.topBar.animate getWithDefaultValue:YES]];
|
60
|
|
- [stack hideBarsOnScroll:[withDefault.topBar.hideOnScroll getWithDefaultValue:NO]];
|
|
57
|
+ [stack setRootBackgroundImage:[withDefault.rootBackgroundImage getWithDefaultValue:nil]];
|
|
58
|
+ [stack setNavigationBarTestId:[withDefault.topBar.testID getWithDefaultValue:nil]];
|
|
59
|
+ [stack setNavigationBarVisible:[withDefault.topBar.visible getWithDefaultValue:YES] animated:[withDefault.topBar.animate getWithDefaultValue:YES]];
|
|
60
|
+ [stack hideBarsOnScroll:[withDefault.topBar.hideOnScroll getWithDefaultValue:NO]];
|
61
|
61
|
|
62
|
62
|
[_topBarPresenter applyOptions:withDefault.topBar];
|
63
|
63
|
|
64
|
64
|
[stack setNavigationBarBlur:[withDefault.topBar.background.blur getWithDefaultValue:NO]];
|
65
|
65
|
[stack setNavigationBarLargeTitleVisible:[withDefault.topBar.largeTitle.visible getWithDefaultValue:NO]];
|
66
|
|
- [stack setNavigationBarClipsToBounds:[withDefault.topBar.background.clipToBounds getWithDefaultValue:NO]];
|
67
|
|
- [stack setBackButtonColor:[withDefault.topBar.backButton.color getWithDefaultValue:nil]];
|
|
66
|
+ [stack setNavigationBarClipsToBounds:[withDefault.topBar.background.clipToBounds getWithDefaultValue:NO]];
|
|
67
|
+ [stack setBackButtonColor:[withDefault.topBar.backButton.color getWithDefaultValue:nil]];
|
68
|
68
|
}
|
69
|
69
|
|
70
|
70
|
- (void)applyOptionsOnViewDidLayoutSubviews:(RNNNavigationOptions *)options {
|
71
|
|
- RNNNavigationOptions *withDefault = [options withDefault:[self defaultOptions]];
|
72
|
|
- if (withDefault.topBar.background.component.name.hasValue) {
|
73
|
|
- [self presentBackgroundComponent];
|
74
|
|
- }
|
|
71
|
+ RNNNavigationOptions *withDefault = [options withDefault:[self defaultOptions]];
|
|
72
|
+ if (withDefault.topBar.background.component.name.hasValue) {
|
|
73
|
+ [self presentBackgroundComponent];
|
|
74
|
+ }
|
75
|
75
|
}
|
76
|
76
|
|
77
|
77
|
- (void)applyOptionsBeforePopping:(RNNNavigationOptions *)options {
|
78
|
|
- RNNNavigationOptions *withDefault = [options withDefault:[self defaultOptions]];
|
79
|
|
- RNNStackController* navigationController = self.stackController;
|
80
|
|
- [navigationController setNavigationBarLargeTitleVisible:[withDefault.topBar.largeTitle.visible getWithDefaultValue:NO]];
|
|
78
|
+ RNNNavigationOptions *withDefault = [options withDefault:[self defaultOptions]];
|
|
79
|
+ RNNStackController* navigationController = self.stackController;
|
|
80
|
+ [navigationController setNavigationBarLargeTitleVisible:[withDefault.topBar.largeTitle.visible getWithDefaultValue:NO]];
|
81
|
81
|
[_topBarPresenter applyOptionsBeforePopping:options.topBar];
|
82
|
82
|
}
|
83
|
83
|
|
84
|
84
|
- (void)mergeOptions:(RNNNavigationOptions *)options resolvedOptions:(RNNNavigationOptions *)resolvedOptions {
|
85
|
85
|
[super mergeOptions:options resolvedOptions:resolvedOptions];
|
86
|
|
- RNNStackController* stack = self.stackController;
|
87
|
|
-
|
88
|
|
- if (options.popGesture.hasValue) {
|
89
|
|
- [_interactivePopGestureDelegate setEnabled:options.popGesture.get];
|
90
|
|
- }
|
91
|
|
-
|
92
|
|
- if (options.rootBackgroundImage.hasValue) {
|
93
|
|
- [stack setRootBackgroundImage:options.rootBackgroundImage.get];
|
94
|
|
- }
|
95
|
|
-
|
96
|
|
- if (options.topBar.testID.hasValue) {
|
97
|
|
- [stack setNavigationBarTestId:options.topBar.testID.get];
|
98
|
|
- }
|
99
|
|
-
|
100
|
|
- if (options.topBar.visible.hasValue) {
|
101
|
|
- [stack setNavigationBarVisible:options.topBar.visible.get animated:[options.topBar.animate getWithDefaultValue:YES]];
|
102
|
|
- }
|
103
|
|
-
|
104
|
|
- if (options.topBar.hideOnScroll.hasValue) {
|
105
|
|
- [stack hideBarsOnScroll:[options.topBar.hideOnScroll get]];
|
106
|
|
- }
|
107
|
|
-
|
108
|
|
- if (options.topBar.barStyle.hasValue) {
|
109
|
|
- [stack setBarStyle:[RCTConvert UIBarStyle:options.topBar.barStyle.get]];
|
110
|
|
- }
|
111
|
|
-
|
112
|
|
- if (options.topBar.background.clipToBounds.hasValue) {
|
113
|
|
- [stack setNavigationBarClipsToBounds:[options.topBar.background.clipToBounds get]];
|
114
|
|
- }
|
115
|
|
-
|
116
|
|
- if (options.topBar.background.blur.hasValue) {
|
117
|
|
- [stack setNavigationBarBlur:[options.topBar.background.blur get]];
|
118
|
|
- }
|
119
|
|
-
|
120
|
|
- if (options.topBar.largeTitle.visible.hasValue) {
|
121
|
|
- [stack setNavigationBarLargeTitleVisible:options.topBar.largeTitle.visible.get];
|
122
|
|
- }
|
123
|
|
-
|
124
|
|
- if (options.topBar.backButton.color.hasValue) {
|
125
|
|
- [stack setBackButtonColor:options.topBar.backButton.color.get];
|
126
|
|
- }
|
127
|
|
-
|
128
|
|
- if (options.topBar.background.component.name.hasValue) {
|
129
|
|
- [self setCustomNavigationComponentBackground:options perform:nil];
|
130
|
|
- }
|
|
86
|
+ RNNStackController* stack = self.stackController;
|
|
87
|
+
|
|
88
|
+ if (options.popGesture.hasValue) {
|
|
89
|
+ [_interactivePopGestureDelegate setEnabled:options.popGesture.get];
|
|
90
|
+ }
|
|
91
|
+
|
|
92
|
+ if (options.rootBackgroundImage.hasValue) {
|
|
93
|
+ [stack setRootBackgroundImage:options.rootBackgroundImage.get];
|
|
94
|
+ }
|
|
95
|
+
|
|
96
|
+ if (options.topBar.testID.hasValue) {
|
|
97
|
+ [stack setNavigationBarTestId:options.topBar.testID.get];
|
|
98
|
+ }
|
|
99
|
+
|
|
100
|
+ if (options.topBar.visible.hasValue) {
|
|
101
|
+ [stack setNavigationBarVisible:options.topBar.visible.get animated:[options.topBar.animate getWithDefaultValue:YES]];
|
|
102
|
+ }
|
|
103
|
+
|
|
104
|
+ if (options.topBar.hideOnScroll.hasValue) {
|
|
105
|
+ [stack hideBarsOnScroll:[options.topBar.hideOnScroll get]];
|
|
106
|
+ }
|
|
107
|
+
|
|
108
|
+ if (options.topBar.barStyle.hasValue) {
|
|
109
|
+ [stack setBarStyle:[RCTConvert UIBarStyle:options.topBar.barStyle.get]];
|
|
110
|
+ }
|
|
111
|
+
|
|
112
|
+ if (options.topBar.background.clipToBounds.hasValue) {
|
|
113
|
+ [stack setNavigationBarClipsToBounds:[options.topBar.background.clipToBounds get]];
|
|
114
|
+ }
|
|
115
|
+
|
|
116
|
+ if (options.topBar.background.blur.hasValue) {
|
|
117
|
+ [stack setNavigationBarBlur:[options.topBar.background.blur get]];
|
|
118
|
+ }
|
|
119
|
+
|
|
120
|
+ if (options.topBar.largeTitle.visible.hasValue) {
|
|
121
|
+ [stack setNavigationBarLargeTitleVisible:options.topBar.largeTitle.visible.get];
|
|
122
|
+ }
|
|
123
|
+
|
|
124
|
+ if (options.topBar.backButton.color.hasValue) {
|
|
125
|
+ [stack setBackButtonColor:options.topBar.backButton.color.get];
|
|
126
|
+ }
|
|
127
|
+
|
|
128
|
+ if (options.topBar.background.component.name.hasValue) {
|
|
129
|
+ [self setCustomNavigationComponentBackground:options perform:nil];
|
|
130
|
+ }
|
131
|
131
|
|
132
|
132
|
RNNNavigationOptions * withDefault = (RNNNavigationOptions *) [[options mergeInOptions:resolvedOptions] withDefault:[self defaultOptions]];
|
133
|
|
- [_topBarPresenter mergeOptions:options.topBar defaultOptions:withDefault.topBar];
|
|
133
|
+ [_topBarPresenter mergeOptions:options.topBar withDefault:withDefault.topBar];
|
134
|
134
|
}
|
135
|
135
|
|
136
|
136
|
- (void)renderComponents:(RNNNavigationOptions *)options perform:(RNNReactViewReadyCompletionBlock)readyBlock {
|
137
|
|
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
|
138
|
|
- dispatch_group_t group = dispatch_group_create();
|
139
|
|
-
|
140
|
|
- dispatch_group_enter(group);
|
141
|
|
- dispatch_async(dispatch_get_main_queue(), ^{
|
142
|
|
- [self setCustomNavigationComponentBackground:options perform:^{
|
143
|
|
- dispatch_group_leave(group);
|
144
|
|
- }];
|
145
|
|
- });
|
146
|
|
-
|
147
|
|
- dispatch_group_wait(group, DISPATCH_TIME_FOREVER);
|
148
|
|
-
|
149
|
|
- dispatch_async(dispatch_get_main_queue(), ^{
|
150
|
|
- if (readyBlock) {
|
151
|
|
- readyBlock();
|
152
|
|
- }
|
153
|
|
- });
|
154
|
|
- });
|
|
137
|
+ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
|
|
138
|
+ dispatch_group_t group = dispatch_group_create();
|
|
139
|
+
|
|
140
|
+ dispatch_group_enter(group);
|
|
141
|
+ dispatch_async(dispatch_get_main_queue(), ^{
|
|
142
|
+ [self setCustomNavigationComponentBackground:options perform:^{
|
|
143
|
+ dispatch_group_leave(group);
|
|
144
|
+ }];
|
|
145
|
+ });
|
|
146
|
+
|
|
147
|
+ dispatch_group_wait(group, DISPATCH_TIME_FOREVER);
|
|
148
|
+
|
|
149
|
+ dispatch_async(dispatch_get_main_queue(), ^{
|
|
150
|
+ if (readyBlock) {
|
|
151
|
+ readyBlock();
|
|
152
|
+ }
|
|
153
|
+ });
|
|
154
|
+ });
|
155
|
155
|
}
|
156
|
156
|
|
157
|
157
|
- (void)setCustomNavigationComponentBackground:(RNNNavigationOptions *)options perform:(RNNReactViewReadyCompletionBlock)readyBlock {
|
158
|
158
|
RNNNavigationOptions *withDefault = [options withDefault:[self defaultOptions]];
|
159
|
|
- RNNStackController* stack = self.stackController;
|
160
|
|
- if (![withDefault.topBar.background.component.waitForRender getWithDefaultValue:NO] && readyBlock) {
|
161
|
|
- readyBlock();
|
162
|
|
- readyBlock = nil;
|
163
|
|
- }
|
164
|
|
-
|
165
|
|
- if (withDefault.topBar.background.component.name.hasValue) {
|
166
|
|
- NSString* currentChildComponentId = [stack getCurrentChild].layoutInfo.componentId;
|
167
|
|
- _topBarBackgroundReactView = [_componentRegistry createComponentIfNotExists:withDefault.topBar.background.component parentComponentId:currentChildComponentId componentType:RNNComponentTypeTopBarBackground reactViewReadyBlock:readyBlock];
|
168
|
|
-
|
169
|
|
- } else {
|
|
159
|
+ RNNStackController* stack = self.stackController;
|
|
160
|
+ if (![withDefault.topBar.background.component.waitForRender getWithDefaultValue:NO] && readyBlock) {
|
|
161
|
+ readyBlock();
|
|
162
|
+ readyBlock = nil;
|
|
163
|
+ }
|
|
164
|
+
|
|
165
|
+ if (withDefault.topBar.background.component.name.hasValue) {
|
|
166
|
+ NSString* currentChildComponentId = [stack getCurrentChild].layoutInfo.componentId;
|
|
167
|
+ _topBarBackgroundReactView = [_componentRegistry createComponentIfNotExists:withDefault.topBar.background.component parentComponentId:currentChildComponentId componentType:RNNComponentTypeTopBarBackground reactViewReadyBlock:readyBlock];
|
|
168
|
+
|
|
169
|
+ } else {
|
170
|
170
|
[_topBarBackgroundReactView componentDidDisappear];
|
171
|
|
- [_customTopBarBackground removeFromSuperview];
|
172
|
|
- _customTopBarBackground = nil;
|
173
|
|
- if (readyBlock) {
|
174
|
|
- readyBlock();
|
175
|
|
- }
|
176
|
|
- }
|
|
171
|
+ [_customTopBarBackground removeFromSuperview];
|
|
172
|
+ _customTopBarBackground = nil;
|
|
173
|
+ if (readyBlock) {
|
|
174
|
+ readyBlock();
|
|
175
|
+ }
|
|
176
|
+ }
|
177
|
177
|
}
|
178
|
178
|
|
179
|
179
|
- (void)presentBackgroundComponent {
|
180
|
|
- RNNStackController* stack = self.stackController;
|
181
|
|
- if (_customTopBarBackground) {
|
182
|
|
- [_customTopBarBackground removeFromSuperview];
|
183
|
|
- }
|
184
|
|
- _customTopBarBackground = [[RNNCustomTitleView alloc] initWithFrame:stack.navigationBar.bounds subView:_topBarBackgroundReactView alignment:@"fill"];
|
185
|
|
-
|
186
|
|
- [stack.navigationBar insertSubview:_customTopBarBackground atIndex:1];
|
|
180
|
+ RNNStackController* stack = self.stackController;
|
|
181
|
+ if (_customTopBarBackground) {
|
|
182
|
+ [_customTopBarBackground removeFromSuperview];
|
|
183
|
+ }
|
|
184
|
+ _customTopBarBackground = [[RNNCustomTitleView alloc] initWithFrame:stack.navigationBar.bounds subView:_topBarBackgroundReactView alignment:@"fill"];
|
|
185
|
+
|
|
186
|
+ [stack.navigationBar insertSubview:_customTopBarBackground atIndex:1];
|
187
|
187
|
[_topBarBackgroundReactView componentDidAppear];
|
188
|
188
|
}
|
189
|
189
|
|
190
|
190
|
- (void)dealloc {
|
191
|
|
- [_componentRegistry removeComponent:self.boundComponentId];
|
|
191
|
+ [_componentRegistry removeComponent:self.boundComponentId];
|
192
|
192
|
}
|
193
|
193
|
|
194
|
194
|
@end
|