Skip to content

Commit 0d38f04

Browse files
author
maxu
committed
增加插件逻辑
2 parents 79cfc31 + 20d63c9 commit 0d38f04

File tree

9 files changed

+113
-33
lines changed

9 files changed

+113
-33
lines changed

example/ios/Runner/DStackTestCase.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ - (instancetype)init
2222
@"text": @"打开SecondViewController",
2323
@"clicked": ^(UIViewController *controller) {
2424
SecondViewController *secondVC = [[SecondViewController alloc] init];
25+
secondVC.hidesBottomBarWhenPushed = YES;
2526
[controller.navigationController pushViewController:secondVC animated:YES];
2627
}
2728
},

example/pubspec.lock

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,42 +7,42 @@ packages:
77
name: async
88
url: "https://pub.flutter-io.cn"
99
source: hosted
10-
version: "2.5.0-nullsafety.3"
10+
version: "2.5.0-nullsafety.1"
1111
boolean_selector:
1212
dependency: transitive
1313
description:
1414
name: boolean_selector
1515
url: "https://pub.flutter-io.cn"
1616
source: hosted
17-
version: "2.1.0-nullsafety.3"
17+
version: "2.1.0-nullsafety.1"
1818
characters:
1919
dependency: transitive
2020
description:
2121
name: characters
2222
url: "https://pub.flutter-io.cn"
2323
source: hosted
24-
version: "1.1.0-nullsafety.5"
24+
version: "1.1.0-nullsafety.3"
2525
charcode:
2626
dependency: transitive
2727
description:
2828
name: charcode
2929
url: "https://pub.flutter-io.cn"
3030
source: hosted
31-
version: "1.2.0-nullsafety.3"
31+
version: "1.2.0-nullsafety.1"
3232
clock:
3333
dependency: transitive
3434
description:
3535
name: clock
3636
url: "https://pub.flutter-io.cn"
3737
source: hosted
38-
version: "1.1.0-nullsafety.3"
38+
version: "1.1.0-nullsafety.1"
3939
collection:
4040
dependency: transitive
4141
description:
4242
name: collection
4343
url: "https://pub.flutter-io.cn"
4444
source: hosted
45-
version: "1.15.0-nullsafety.5"
45+
version: "1.15.0-nullsafety.3"
4646
cupertino_icons:
4747
dependency: "direct main"
4848
description:
@@ -57,20 +57,13 @@ packages:
5757
relative: true
5858
source: path
5959
version: "1.2.8+4"
60-
d_stack_spy:
61-
dependency: "direct dev"
62-
description:
63-
path: "../../d_stack_spy"
64-
relative: true
65-
source: path
66-
version: "0.0.1"
6760
fake_async:
6861
dependency: transitive
6962
description:
7063
name: fake_async
7164
url: "https://pub.flutter-io.cn"
7265
source: hosted
73-
version: "1.2.0-nullsafety.3"
66+
version: "1.2.0-nullsafety.1"
7467
flutter:
7568
dependency: "direct main"
7669
description: flutter
@@ -87,21 +80,21 @@ packages:
8780
name: matcher
8881
url: "https://pub.flutter-io.cn"
8982
source: hosted
90-
version: "0.12.10-nullsafety.3"
83+
version: "0.12.10-nullsafety.1"
9184
meta:
9285
dependency: transitive
9386
description:
9487
name: meta
9588
url: "https://pub.flutter-io.cn"
9689
source: hosted
97-
version: "1.3.0-nullsafety.6"
90+
version: "1.3.0-nullsafety.3"
9891
path:
9992
dependency: transitive
10093
description:
10194
name: path
10295
url: "https://pub.flutter-io.cn"
10396
source: hosted
104-
version: "1.8.0-nullsafety.3"
97+
version: "1.8.0-nullsafety.1"
10598
sky_engine:
10699
dependency: transitive
107100
description: flutter
@@ -113,56 +106,56 @@ packages:
113106
name: source_span
114107
url: "https://pub.flutter-io.cn"
115108
source: hosted
116-
version: "1.8.0-nullsafety.4"
109+
version: "1.8.0-nullsafety.2"
117110
stack_trace:
118111
dependency: transitive
119112
description:
120113
name: stack_trace
121114
url: "https://pub.flutter-io.cn"
122115
source: hosted
123-
version: "1.10.0-nullsafety.6"
116+
version: "1.10.0-nullsafety.1"
124117
stream_channel:
125118
dependency: transitive
126119
description:
127120
name: stream_channel
128121
url: "https://pub.flutter-io.cn"
129122
source: hosted
130-
version: "2.1.0-nullsafety.3"
123+
version: "2.1.0-nullsafety.1"
131124
string_scanner:
132125
dependency: transitive
133126
description:
134127
name: string_scanner
135128
url: "https://pub.flutter-io.cn"
136129
source: hosted
137-
version: "1.1.0-nullsafety.3"
130+
version: "1.1.0-nullsafety.1"
138131
term_glyph:
139132
dependency: transitive
140133
description:
141134
name: term_glyph
142135
url: "https://pub.flutter-io.cn"
143136
source: hosted
144-
version: "1.2.0-nullsafety.3"
137+
version: "1.2.0-nullsafety.1"
145138
test_api:
146139
dependency: transitive
147140
description:
148141
name: test_api
149142
url: "https://pub.flutter-io.cn"
150143
source: hosted
151-
version: "0.2.19-nullsafety.6"
144+
version: "0.2.19-nullsafety.2"
152145
typed_data:
153146
dependency: transitive
154147
description:
155148
name: typed_data
156149
url: "https://pub.flutter-io.cn"
157150
source: hosted
158-
version: "1.3.0-nullsafety.5"
151+
version: "1.3.0-nullsafety.3"
159152
vector_math:
160153
dependency: transitive
161154
description:
162155
name: vector_math
163156
url: "https://pub.flutter-io.cn"
164157
source: hosted
165-
version: "2.1.0-nullsafety.5"
158+
version: "2.1.0-nullsafety.3"
166159
sdks:
167-
dart: ">=2.12.0-0.0 <3.0.0"
168-
flutter: ">=1.20.0 <2.0.0"
160+
dart: ">=2.10.0-110 <2.11.0"
161+
flutter: ">=1.17.0"

ios/Classes/Node/DActionManager.m

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ + (void)gesture:(DNode *)node willRemovedList:(NSArray<DNode *> *)nodeList
5959
[self sendMessageToFlutterWithFlutterNodes:nodeList
6060
node:popNode];
6161
}
62+
[self _checkTabBarWithNode:node popNodeList:nodeList];
6263
}
6364
}
6465

@@ -74,8 +75,8 @@ + (NSDictionary *)getPageTypeNodeList:(NSArray<DNode *> *)nodeList
7475
+ (void)enterPageWithNode:(DNode *)node
7576
{
7677
if (node.fromFlutter) {
77-
// 只处理来自Flutter消息通道的Node,并且是打开Native页面
7878
if (node.pageType == DNodePageTypeNative) {
79+
// 处理来自Flutter消息通道的Node,并且是打开Native页面
7980
// flutter打开naive页面
8081
DStackNode *stackNode = [self stackNodeFromNode:node];
8182
if (node.action == DNodeActionTypePush) {
@@ -87,6 +88,10 @@ + (void)enterPageWithNode:(DNode *)node
8788
[stack.delegate dStack:stack presentWithNode:stackNode];
8889
}];
8990
}
91+
} else if (node.pageType == DNodePageTypeFlutter) {
92+
// flutter打开flutter页面,检查tabBar是否隐藏
93+
[[NSNotificationCenter defaultCenter] postNotificationName:DStackNotificationNameChangeBottomBarVisible
94+
object:nil];
9095
}
9196
} else {
9297
// 来自Native的Node,并且是需要打开Flutter页面的,发消息至flutter,打开页面
@@ -152,6 +157,7 @@ + (void)closePageWithNode:(DNode *)node willRemovedList:(nullable NSArray<DNode
152157
} else if (currentNode.pageType == DNodePageTypeNative) {
153158
DStackLog(@"当前页面是Native,直接返回上一个页面,不需要处理");
154159
}
160+
[self _checkTabBarWithNode:node popNodeList:nodeList];
155161
}
156162

157163
/// 关闭一组页面
@@ -185,29 +191,55 @@ + (void)closePageListWithNode:(DNode *)node willRemovedList:(nullable NSArray<DN
185191
[self sendMessageToFlutterWithFlutterNodes:flutterNodes node:node];
186192
}
187193
if (!node.fromFlutter) { return;}
188-
189194
UINavigationController *navigation = [self currentNavigationControllerWithNode:node];
190195
if (node.action == DNodeActionTypePopToRoot ||
191196
node.action == DNodeActionTypePopToNativeRoot) {
192197
[navigation setValue:@(YES) forKey:@"dStackFlutterNodeMessage"];
193198
[navigation popToRootViewControllerAnimated:YES];
194199
[navigation setValue:@(NO) forKey:@"dStackFlutterNodeMessage"];
200+
[self _checkTabBarWithNode:node popNodeList:nodeList];
195201
return;
196202
}
197203

198204
NSInteger index = navigation.viewControllers.count - boundaryCount - nativeNodes.count - 1;
199205
index = index < 0 ? 0 : index;
200206
UIViewController *target = navigation.viewControllers[index];
201207
if (target) {
202-
if (target == navigation.topViewController) {return;}
208+
if (target == navigation.topViewController) {
209+
[self _checkTabBarWithNode:node popNodeList:nodeList];
210+
return;
211+
}
203212
[navigation setValue:@(YES) forKey:@"dStackFlutterNodeMessage"];
204213
[navigation popToViewController:target animated:NO];
205214
[navigation setValue:@(NO) forKey:@"dStackFlutterNodeMessage"];
215+
[self _checkTabBarWithNode:node popNodeList:nodeList];
206216
} else {
207217
DStackError(@"%@", @"没有找到需要关闭的controller");
208218
}
209219
}
210220

221+
/// 检查tabBar 的显示状态
222+
/// @param node node消息
223+
/// @param nodeList 节点列表
224+
+ (void)_checkTabBarWithNode:(DNode *)node popNodeList:(NSArray <DNode *>*)nodeList
225+
{
226+
DNode *preNode = nil;
227+
DNode *target = nodeList.lastObject;
228+
if (node.action == DNodeActionTypePopToRoot ||
229+
node.action == DNodeActionTypePopToNativeRoot) {
230+
target = nodeList.firstObject;
231+
}
232+
NSInteger index = [[DNodeManager sharedInstance].currentNodeList indexOfObject:target];
233+
if (index >= 1) {
234+
preNode = [[DNodeManager sharedInstance].currentNodeList objectAtIndex:index - 1];
235+
}
236+
if (preNode && preNode.isRootPage) {
237+
[[NSNotificationCenter defaultCenter] postNotificationName:DStackNotificationNameChangeBottomBarVisible
238+
object:nil
239+
userInfo:@{@"hidden": @(NO)}];
240+
}
241+
}
242+
211243
/// 发消息至Flutter
212244
/// @param flutterNodes 需要发送至flutter的节点信息
213245
/// @param node 目标节点信息

ios/Classes/Node/DNodeManager.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,7 @@ - (void)operationNode:(DNode *)node {
387387
@"homePage": @(node.isFlutterHomePage),
388388
@"boundary": @(node.boundary),
389389
@"animated": @(node.animated),
390+
@"identifier": node.identifier != nil ? node.identifier : @"unknown",
390391
};
391392
} else {
392393
params = @{};

ios/Classes/Stack/DFlutterViewController.m

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ - (instancetype)init
1717
if(self = [super initWithEngine:[DStack sharedInstance].engine
1818
nibName:nil
1919
bundle:nil]) {
20-
self.view.backgroundColor = [UIColor whiteColor];
20+
[self config];
2121
}
2222
return self;
2323
}
@@ -27,11 +27,17 @@ - (instancetype)initWithCoder:(NSCoder *)coder
2727
if(self = [super initWithEngine:[DStack sharedInstance].engine
2828
nibName:nil
2929
bundle:nil]) {
30-
self.view.backgroundColor = [UIColor whiteColor];
30+
[self config];
3131
}
3232
return self;
3333
}
3434

35+
- (void)config
36+
{
37+
self.view.backgroundColor = [UIColor whiteColor];
38+
[self addNotification];
39+
}
40+
3541
- (void)viewWillAppear:(BOOL)animated
3642
{
3743
// 必须在页面显示之前判断engine是否存在FlutterViewController
@@ -70,4 +76,32 @@ - (void)_surfaceUpdated:(BOOL)appeared
7076
}
7177
}
7278

79+
- (void)addNotification
80+
{
81+
[[NSNotificationCenter defaultCenter] addObserver:self
82+
selector:@selector(changeBottomBarVisible:)
83+
name:DStackNotificationNameChangeBottomBarVisible
84+
object:nil];
85+
}
86+
87+
- (void)changeBottomBarVisible:(NSNotification *)notification
88+
{
89+
NSDictionary *userInfo = notification.userInfo;
90+
if (!userInfo) {
91+
if (self.tabBarController.tabBar.hidden == NO) {
92+
[self.tabBarController.tabBar setHidden:YES];
93+
}
94+
} else {
95+
BOOL hidden = [userInfo[@"hidden"] boolValue];
96+
if (self.tabBarController.tabBar.hidden) {
97+
[self.tabBarController.tabBar setHidden:hidden];
98+
}
99+
}
100+
}
101+
102+
- (void)dealloc
103+
{
104+
[[NSNotificationCenter defaultCenter] removeObserver:self];
105+
}
106+
73107
@end

ios/Classes/Stack/DNavigator.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,9 @@ - (void)d_stackPushViewController:(UIViewController *)controller animated:(BOOL)
594594
}
595595

596596
if ([controller isFlutterViewController]) {
597-
controller.hidesBottomBarWhenPushed = YES;
597+
if (self.dStackRootViewController != controller && self.viewControllers.count == 1) {
598+
controller.hidesBottomBarWhenPushed = YES;
599+
}
598600
}
599601

600602
if (!controller.isFlutterViewController && self.dStackRootViewController != controller) {

ios/Classes/Stack/DStack.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,5 +289,11 @@ applicationState:(DStackApplicationState)state
289289

290290
@end
291291

292+
293+
#pragma mark -DStackNotificationName
294+
295+
typedef NSString *DStackNotificationName;
296+
UIKIT_EXTERN DStackNotificationName const DStackNotificationNameChangeBottomBarVisible; // tabBar显示状态
297+
292298
NS_ASSUME_NONNULL_END
293299

ios/Classes/Stack/DStack.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,3 +543,9 @@ static void _dstack_engine_dyld_callback(const struct mach_header * mhp, intptr_
543543
__attribute__((constructor)) void _dstack_registerDyldCallback() {
544544
_dyld_register_func_for_add_image(_dstack_engine_dyld_callback);
545545
}
546+
547+
548+
549+
#pragma mark -DStackNotificationName
550+
551+
DStackNotificationName const DStackNotificationNameChangeBottomBarVisible = @"__DStackNotificationNameChangeBottomBarVisible";

lib/navigator/node_entity.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,17 @@ class DNode {
6565
/// 是否为临界节点
6666
bool boundary;
6767

68+
/// 页面唯一id
69+
String identifier;
70+
6871
DNode.fromJson(Map json) {
6972
target = json["target"];
7073
action = json["action"];
7174
params = json["params"];
7275
homePage = json["homePage"] ?? false;
7376
animated = json["animated"] ?? true;
7477
boundary = json["boundary"] ?? false;
78+
identifier = json["identifier"];
7579
String pageString = json["pageType"];
7680
if (pageString.toLowerCase() == "flutter") {
7781
pageType = PageType.flutter;
@@ -88,6 +92,7 @@ class DNode {
8892
json["homePage"] = this.homePage;
8993
json["boundary"] = this.boundary;
9094
json["animated"] = this.animated;
95+
json["identifier"] = this.identifier;
9196
switch (this.pageType) {
9297
case PageType.flutter:
9398
{

0 commit comments

Comments
 (0)