Skip to content

Commit 1c6dc44

Browse files
author
caven775
committed
统一安卓和iOS的didPop消息
1 parent 9cfcbbd commit 1c6dc44

File tree

13 files changed

+13
-53
lines changed

13 files changed

+13
-53
lines changed

example/ios/Runner/AppDelegate.m

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ @interface AppDelegate () <DStackDelegate>
1313

1414
@end
1515

16-
static BOOL isFlutterProject = YES;
16+
static BOOL isFlutterProject = NO;
1717

1818
@implementation AppDelegate
1919

@@ -32,9 +32,14 @@ - (BOOL)application:(UIApplication *)application
3232
} else {
3333
HomeViewController *home = [[HomeViewController alloc] init];
3434
UITabBarController *tab = [[UITabBarController alloc] init];
35-
DStackViewController *navi = [[DStackViewController alloc] initWithRootViewController:home];
36-
navi.tabBarItem.title = @"home";
37-
[tab setViewControllers:@[navi]];
35+
DStackViewController *navi0 = [[DStackViewController alloc] initWithRootViewController:home];
36+
navi0.tabBarItem.title = @"home";
37+
38+
DemoFlutterViewController *flutter = [[DemoFlutterViewController alloc] init];
39+
DStackViewController *navi1 = [[DStackViewController alloc] initWithRootViewController:flutter];
40+
navi1.tabBarItem.title = @"flutter";
41+
42+
[tab setViewControllers:@[navi0, navi1]];
3843
rootVC = tab;
3944
}
4045
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];

ios/Classes/Node/DActionManager.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ + (void)closePageListWithNode:(DNode *)node willRemovedList:(nullable NSArray<DN
170170
[nativeNodes addObject:obj];
171171
} else if (obj.pageType == DNodePageTypeFlutter) {
172172
[flutterNodes addObject:obj];
173-
if (obj.isFlutterClass) {
173+
if (obj.boundary) {
174174
boundaryCount += 1;
175175
}
176176
}
@@ -234,8 +234,8 @@ + (void)sendMessageToFlutterWithFlutterNodes:(NSArray <DNode *>*)flutterNodes
234234
[nodeList addObject:wrap(flutterNodes.firstObject)];
235235
} else {
236236
for (DNode *x in flutterNodes) {
237-
if (!x.isFlutterHomePage) {
238-
// homePage 页面不能pop,不然会黑屏
237+
// homePage 页面不能pop,不然会黑屏
238+
if (!(x.isFlutterHomePage && x.boundary)) {
239239
[nodeList addObject:wrap(x)];
240240
}
241241
}

ios/Classes/Node/DNode.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,6 @@ NS_ASSUME_NONNULL_BEGIN
4949
/// DFlutterViewController_0x28268d1d0
5050
@property (nonatomic, copy) NSString *identifier;
5151

52-
/// 是否是flutterVC
53-
@property (nonatomic, assign) BOOL isFlutterClass;
54-
5552
/// 是否是根页面F
5653
@property (nonatomic, assign) BOOL isRootPage;
5754

ios/Classes/Node/DNodeManager.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,6 @@ NS_ASSUME_NONNULL_BEGIN
6868
/// @param state 应用的生命周期
6969
- (void)sendAppliccationLifeCicleToFlutter:(DStackApplicationState)state;
7070

71-
/// 更新根节点信息为flutter的信息
72-
- (void)updateRootNodeWithFlutter;
73-
7471
@end
7572

7673
NS_ASSUME_NONNULL_END

ios/Classes/Node/DNodeManager.m

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -371,16 +371,6 @@ - (void)sendPageLifeCicleToFlutterWithAppearNode:(DNode *)appear
371371
result:nil];
372372
}
373373

374-
- (void)updateRootNodeWithFlutter
375-
{
376-
DNode *rootNode = self.nodeList.firstObject;
377-
if (rootNode && rootNode.isRootPage) {
378-
rootNode.isFlutterHomePage = YES;
379-
rootNode.pageType = DNodePageTypeFlutter;
380-
rootNode.fromFlutter = YES;
381-
}
382-
}
383-
384374

385375
#pragma mark -- private
386376

ios/Classes/Stack/DStack.m

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,6 @@ - (void)openFlutterPageWithRoute:(NSString *)route
303303
node.identifier = identifier;
304304
node.boundary = YES;
305305
node.animated = animated;
306-
node.isFlutterClass = YES;
307306
[[DNodeManager sharedInstance] checkNode:node];
308307
}
309308

@@ -394,12 +393,6 @@ - (void)sendNodeListToFlutter:(FlutterResult)result
394393
}
395394
}
396395

397-
/// 设置根节点为flutter的信息
398-
- (void)setFlutterRootNode
399-
{
400-
[[DNodeManager sharedInstance] updateRootNodeWithFlutter];
401-
}
402-
403396
- (FlutterEngine *)engine
404397
{
405398
if (!_engine) {

ios/Classes/Stack/DStackPlugin.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ UIKIT_EXTERN DStackMethodChannelName const DStackMethodChannelSendActionToFlutte
1616
UIKIT_EXTERN DStackMethodChannelName const DStackMethodChannelSendRemoveFlutterPageNode; // flutter发送移除节点的指令到native
1717
UIKIT_EXTERN DStackMethodChannelName const DStackMethodChannelSendLifeCircle; // 生命周期通道
1818
UIKIT_EXTERN DStackMethodChannelName const DStackMethodChannelSendNodeList; // 节点列表
19-
UIKIT_EXTERN DStackMethodChannelName const DStackMethodChannelSendFlutterRootNode; // 设置flutter根节点
2019

2120
@interface DStackPlugin : NSObject<FlutterPlugin>
2221

ios/Classes/Stack/DStackPlugin.m

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
DStackMethodChannelName const DStackMethodChannelSendRemoveFlutterPageNode = @"sendRemoveFlutterPageNode";
1515
DStackMethodChannelName const DStackMethodChannelSendLifeCircle = @"sendLifeCycle";
1616
DStackMethodChannelName const DStackMethodChannelSendNodeList = @"sendNodeList";
17-
DStackMethodChannelName const DStackMethodChannelSendFlutterRootNode = @"sendFlutterRootNode";
1817

1918

2019
@interface DStackPlugin ()
@@ -52,11 +51,6 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
5251
if ([stack respondsToSelector:@selector(sendNodeListToFlutter:)]) {
5352
[stack sendNodeListToFlutter:result];
5453
}
55-
} else if ([DStackMethodChannelSendFlutterRootNode isEqualToString:call.method]) {
56-
DStack *stack = [DStack sharedInstance];
57-
if ([stack respondsToSelector:@selector(setFlutterRootNode)]) {
58-
[stack setFlutterRootNode];
59-
}
6054
} else {
6155
result(FlutterMethodNotImplemented);
6256
}

ios/Classes/Stack/DStackProvider.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,6 @@ typedef NS_ENUM(NSInteger, DStackApplicationState) {
7373
/// @param result result
7474
- (void)sendNodeListToFlutter:(FlutterResult)result;
7575

76-
/// 设置根节点为flutter的信息
77-
- (void)setFlutterRootNode;
7876

7977
@end
8078

lib/channel/dchannel.dart

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,6 @@ class DChannel {
4646
return _methodChannel.invokeMethod(DStackConstant.checkRemoved, arguments);
4747
}
4848

49-
/// 设置flutter根节点
50-
Future sendFlutterRootNode() async {
51-
return _methodChannel.invokeMethod(DStackConstant.sendFlutterRootNode);
52-
}
53-
5449
Future<List<DStackNode>> getNodeList() async {
5550
return _methodChannel
5651
.invokeMethod(DStackConstant.nodeList, null)

lib/constant/constant_config.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ class DStackConstant {
2424
static const String checkRemoved = "sendRemoveFlutterPageNode";
2525
static const String lifeCycle = "sendLifeCycle";
2626
static const String nodeList = "sendNodeList";
27-
static const String sendFlutterRootNode = "sendFlutterRootNode";
2827

2928
/// 其他标识
3029
static const String nativeDidPopGesture = "nativeDidPopGesture";

lib/d_stack.dart

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,6 @@ class DStack {
5858
bool get hasHomePage => _hasHomePage;
5959
set homePage(bool page) {
6060
_hasHomePage = page;
61-
if (_hasHomePage) {
62-
/// 如果设置了homePage,说明是以flutter为入口的工程
63-
/// 根节点设置为flutter页面的信息
64-
channel.sendFlutterRootNode();
65-
}
6661
}
6762

6863
final Map<String, DStackWidgetBuilder> _pageBuilders =

lib/navigator/dnavigator_manager.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
* tartget: flutter侧用户调用入口
88
*/
99

10-
import 'dart:io';
1110
import 'dart:ui';
1211

1312
import 'package:d_stack/constant/constant_config.dart';
@@ -258,11 +257,10 @@ class DNavigatorManager {
258257

259258
/// 移除flutter的节点
260259
static void removeFlutterNode(String target, {String identifier}) {
261-
String actionType = (Platform.isAndroid ? 'pop' : 'didPop');
262260
Map arguments = {
263261
'target': target,
264262
'pageType': 'flutter',
265-
'actionType': actionType,
263+
'actionType': 'didPop',
266264
'identifier': identifier
267265
};
268266
DStack.instance.channel.sendRemoveFlutterPageNode(arguments);

0 commit comments

Comments
 (0)