|
@@ -5,26 +5,23 @@
|
5
|
5
|
#import "RNNTitleViewHelper.h"
|
6
|
6
|
#import "UIViewController+LayoutProtocol.h"
|
7
|
7
|
#import "RNNReactTitleView.h"
|
|
8
|
+#import "TopBarTitlePresenter.h"
|
8
|
9
|
|
9
|
|
-@interface RNNComponentPresenter() {
|
10
|
|
- RNNReactTitleView* _customTitleView;
|
11
|
|
- RNNTitleViewHelper* _titleViewHelper;
|
12
|
|
- RNNReactComponentRegistry* _componentRegistry;
|
13
|
|
-}
|
14
|
|
-
|
15
|
|
-@end
|
16
|
10
|
|
17
|
|
-@implementation RNNComponentPresenter
|
|
11
|
+@implementation RNNComponentPresenter {
|
|
12
|
+ TopBarTitlePresenter* _topBarTitlePresenter;
|
|
13
|
+}
|
18
|
14
|
|
19
|
|
-- (instancetype)initWithComponentRegistry:(RNNReactComponentRegistry *)componentRegistry:(RNNNavigationOptions *)defaultOptions {
|
20
|
|
- self = [self initWithDefaultOptions:defaultOptions];
|
21
|
|
- _componentRegistry = componentRegistry;
|
|
15
|
+- (instancetype)initWithComponentRegistry:(RNNReactComponentRegistry *)componentRegistry defaultOptions:(RNNNavigationOptions *)defaultOptions {
|
|
16
|
+ self = [super initWithComponentRegistry:componentRegistry defaultOptions:defaultOptions];
|
|
17
|
+ _topBarTitlePresenter = [[TopBarTitlePresenter alloc] initWithComponentRegistry:componentRegistry defaultOptions:defaultOptions];
|
22
|
18
|
return self;
|
23
|
19
|
}
|
24
|
20
|
|
25
|
21
|
- (void)bindViewController:(id)boundViewController {
|
26
|
22
|
[super bindViewController:boundViewController];
|
27
|
|
- _navigationButtons = [[RNNNavigationButtons alloc] initWithViewController:self.boundViewController componentRegistry:_componentRegistry];
|
|
23
|
+ [_topBarTitlePresenter bindViewController:boundViewController];
|
|
24
|
+ _navigationButtons = [[RNNNavigationButtons alloc] initWithViewController:boundViewController componentRegistry:self.componentRegistry];
|
28
|
25
|
}
|
29
|
26
|
|
30
|
27
|
- (void)componentDidAppear {
|
|
@@ -32,7 +29,7 @@
|
32
|
29
|
if ([component respondsToSelector:@selector(componentDidAppear)]) {
|
33
|
30
|
[component componentDidAppear];
|
34
|
31
|
}
|
35
|
|
- [_customTitleView componentDidAppear];
|
|
32
|
+ [_topBarTitlePresenter componentDidAppear];
|
36
|
33
|
[_navigationButtons componentDidAppear];
|
37
|
34
|
}
|
38
|
35
|
|
|
@@ -42,7 +39,7 @@
|
42
|
39
|
[component componentDidDisappear];
|
43
|
40
|
}
|
44
|
41
|
|
45
|
|
- [_customTitleView componentDidDisappear];
|
|
42
|
+ [_topBarTitlePresenter componentDidDisappear];
|
46
|
43
|
[_navigationButtons componentDidDisappear];
|
47
|
44
|
}
|
48
|
45
|
|
|
@@ -56,7 +53,6 @@
|
56
|
53
|
UIViewController* viewController = self.boundViewController;
|
57
|
54
|
RNNNavigationOptions *withDefault = [options withDefault:[self defaultOptions]];
|
58
|
55
|
[viewController setBackgroundImage:[withDefault.backgroundImage getWithDefaultValue:nil]];
|
59
|
|
- [viewController setNavigationItemTitle:[withDefault.topBar.title.text getWithDefaultValue:nil]];
|
60
|
56
|
[viewController setTopBarPrefersLargeTitle:[withDefault.topBar.largeTitle.visible getWithDefaultValue:NO]];
|
61
|
57
|
[viewController setTabBarItemBadgeColor:[withDefault.bottomTab.badgeColor getWithDefaultValue:nil]];
|
62
|
58
|
[viewController setStatusBarBlur:[withDefault.statusBar.blur getWithDefaultValue:NO]];
|
|
@@ -75,8 +71,8 @@
|
75
|
71
|
}
|
76
|
72
|
[viewController setSearchBarWithPlaceholder:[withDefault.topBar.searchBarPlaceholder getWithDefaultValue:@""] hideNavBarOnFocusSearchBar:hideNavBarOnFocusSearchBar];
|
77
|
73
|
}
|
78
|
|
-
|
79
|
|
- [self setTitleViewWithSubtitle:withDefault];
|
|
74
|
+
|
|
75
|
+ [_topBarTitlePresenter applyOptions:withDefault.topBar];
|
80
|
76
|
}
|
81
|
77
|
|
82
|
78
|
- (void)applyOptionsOnInit:(RNNNavigationOptions *)options {
|
|
@@ -96,7 +92,6 @@
|
96
|
92
|
[super mergeOptions:options resolvedOptions:currentOptions];
|
97
|
93
|
RNNNavigationOptions * withDefault = (RNNNavigationOptions *) [[currentOptions overrideOptions:options] withDefault:[self defaultOptions]];
|
98
|
94
|
UIViewController* viewController = self.boundViewController;
|
99
|
|
- [self removeTitleComponentIfNeeded:options];
|
100
|
95
|
|
101
|
96
|
if (options.backgroundImage.hasValue) {
|
102
|
97
|
[viewController setBackgroundImage:options.backgroundImage.get];
|
|
@@ -122,10 +117,6 @@
|
122
|
117
|
[viewController setDrawBehindTopBar:options.topBar.drawBehind.get];
|
123
|
118
|
}
|
124
|
119
|
|
125
|
|
- if (options.topBar.title.text.hasValue) {
|
126
|
|
- [viewController setNavigationItemTitle:options.topBar.title.text.get];
|
127
|
|
- }
|
128
|
|
-
|
129
|
120
|
if (options.topBar.largeTitle.visible.hasValue) {
|
130
|
121
|
[viewController setTopBarPrefersLargeTitle:options.topBar.largeTitle.visible.get];
|
131
|
122
|
}
|
|
@@ -167,68 +158,17 @@
|
167
|
158
|
RCTRootView* rootView = (RCTRootView*)viewController.view;
|
168
|
159
|
rootView.passThroughTouches = !options.overlay.interceptTouchOutside.get;
|
169
|
160
|
}
|
170
|
|
-
|
171
|
|
- if (options.topBar.title.component.name.hasValue) {
|
172
|
|
- [self setCustomNavigationTitleView:options perform:nil];
|
173
|
|
- }
|
174
|
|
-
|
175
|
|
- [self setTitleViewWithSubtitle:withDefault];
|
176
|
|
-}
|
177
|
|
-
|
178
|
|
-- (void)removeTitleComponentIfNeeded:(RNNNavigationOptions *)options {
|
179
|
|
- if (options.topBar.title.text.hasValue) {
|
180
|
|
- [_customTitleView componentDidDisappear];
|
181
|
|
- [_customTitleView removeFromSuperview];
|
182
|
|
- _customTitleView = nil;
|
183
|
|
- }
|
|
161
|
+
|
|
162
|
+ [_topBarTitlePresenter mergeOptions:options.topBar resolvedOptions:currentOptions.topBar];
|
184
|
163
|
}
|
185
|
164
|
|
186
|
165
|
- (void)renderComponents:(RNNNavigationOptions *)options perform:(RNNReactViewReadyCompletionBlock)readyBlock {
|
187
|
166
|
RNNNavigationOptions *withDefault = [options withDefault:[self defaultOptions]];
|
188
|
|
- [self setCustomNavigationTitleView:withDefault perform:readyBlock];
|
189
|
|
-}
|
190
|
|
-
|
191
|
|
-- (void)setCustomNavigationTitleView:(RNNNavigationOptions *)options perform:(RNNReactViewReadyCompletionBlock)readyBlock {
|
192
|
|
- UIViewController<RNNLayoutProtocol>* viewController = self.boundViewController;
|
193
|
|
- if (![options.topBar.title.component.waitForRender getWithDefaultValue:NO] && readyBlock) {
|
194
|
|
- readyBlock();
|
195
|
|
- readyBlock = nil;
|
196
|
|
- }
|
197
|
|
-
|
198
|
|
- if (options.topBar.title.component.name.hasValue) {
|
199
|
|
- _customTitleView = (RNNReactTitleView *)[_componentRegistry createComponentIfNotExists:options.topBar.title.component parentComponentId:viewController.layoutInfo.componentId componentType:RNNComponentTypeTopBarTitle reactViewReadyBlock:readyBlock];
|
200
|
|
- _customTitleView.backgroundColor = UIColor.clearColor;
|
201
|
|
- NSString* alignment = [options.topBar.title.component.alignment getWithDefaultValue:@""];
|
202
|
|
- [_customTitleView setAlignment:alignment inFrame:viewController.navigationController.navigationBar.frame];
|
203
|
|
- [_customTitleView layoutIfNeeded];
|
204
|
|
-
|
205
|
|
- viewController.navigationItem.titleView = nil;
|
206
|
|
- viewController.navigationItem.titleView = _customTitleView;
|
207
|
|
- [_customTitleView componentDidAppear];
|
208
|
|
- } else {
|
209
|
|
- [_customTitleView removeFromSuperview];
|
210
|
|
- if (readyBlock) {
|
211
|
|
- readyBlock();
|
212
|
|
- }
|
213
|
|
- }
|
|
167
|
+ [_topBarTitlePresenter renderComponents:withDefault.topBar perform:readyBlock];
|
214
|
168
|
}
|
215
|
169
|
|
216
|
|
-- (void)setTitleViewWithSubtitle:(RNNNavigationOptions *)options {
|
217
|
|
- if (!_customTitleView && ![options.topBar.largeTitle.visible getWithDefaultValue:NO]) {
|
218
|
|
- _titleViewHelper = [[RNNTitleViewHelper alloc] initWithTitleViewOptions:options.topBar.title subTitleOptions:options.topBar.subtitle viewController:self.boundViewController];
|
219
|
|
-
|
220
|
|
- if (options.topBar.title.text.hasValue) {
|
221
|
|
- [_titleViewHelper setTitleOptions:options.topBar.title];
|
222
|
|
- }
|
223
|
|
- if (options.topBar.subtitle.text.hasValue) {
|
224
|
|
- [_titleViewHelper setSubtitleOptions:options.topBar.subtitle];
|
225
|
|
- }
|
226
|
|
-
|
227
|
|
- [_titleViewHelper setup];
|
228
|
|
- }
|
229
|
|
-}
|
230
|
170
|
|
231
|
171
|
- (void)dealloc {
|
232
|
|
- [_componentRegistry clearComponentsForParentId:self.boundComponentId];
|
|
172
|
+ [self.componentRegistry clearComponentsForParentId:self.boundComponentId];
|
233
|
173
|
}
|
234
|
174
|
@end
|