Skip to content

Commit fa4a570

Browse files
author
caven775
committed
iOS的dismiss手势节点优化
1 parent a82f6a8 commit fa4a570

21 files changed

+342
-119
lines changed

example/ios/Flutter/.last_build_id

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
f74dd5904491587016158cb099c86426
1+
3f715bff32baf5101070f62afcbad897

example/ios/Runner.xcodeproj/project.pbxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
3E2B2AC224F7C6F700BC7183 /* FourViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 3E2B2AC124F7C6F700BC7183 /* FourViewController.m */; };
1414
3E854E3D257A3616006EAB28 /* DemoFlutterViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 3E854E3C257A3616006EAB28 /* DemoFlutterViewController.m */; };
1515
3E854E47257A3C42006EAB28 /* DStackTestCase.m in Sources */ = {isa = PBXBuildFile; fileRef = 3E854E46257A3C42006EAB28 /* DStackTestCase.m */; };
16+
3EA9207E257F580300F3EB75 /* FiveViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 3EA9207D257F580300F3EB75 /* FiveViewController.m */; };
1617
3F043F4423F3944100FC83D9 /* DStackViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 3F043F4323F3944100FC83D9 /* DStackViewController.m */; };
1718
3FA943CE23F27D2D00DAC679 /* HomeViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 3FA943CD23F27D2D00DAC679 /* HomeViewController.m */; };
1819
3FA943D423F27D6A00DAC679 /* SecondViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 3FA943D323F27D6A00DAC679 /* SecondViewController.m */; };
@@ -50,6 +51,8 @@
5051
3E854E3C257A3616006EAB28 /* DemoFlutterViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = DemoFlutterViewController.m; sourceTree = "<group>"; };
5152
3E854E45257A3C42006EAB28 /* DStackTestCase.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DStackTestCase.h; sourceTree = "<group>"; };
5253
3E854E46257A3C42006EAB28 /* DStackTestCase.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = DStackTestCase.m; sourceTree = "<group>"; };
54+
3EA9207C257F580300F3EB75 /* FiveViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FiveViewController.h; sourceTree = "<group>"; };
55+
3EA9207D257F580300F3EB75 /* FiveViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FiveViewController.m; sourceTree = "<group>"; };
5356
3F043F4223F3944100FC83D9 /* DStackViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DStackViewController.h; sourceTree = "<group>"; };
5457
3F043F4323F3944100FC83D9 /* DStackViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = DStackViewController.m; sourceTree = "<group>"; };
5558
3FA943CC23F27D2D00DAC679 /* HomeViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = HomeViewController.h; sourceTree = "<group>"; };
@@ -151,6 +154,8 @@
151154
3E2B2ABE24F7C2DB00BC7183 /* ThirdViewController.m */,
152155
3E2B2AC024F7C6F700BC7183 /* FourViewController.h */,
153156
3E2B2AC124F7C6F700BC7183 /* FourViewController.m */,
157+
3EA9207C257F580300F3EB75 /* FiveViewController.h */,
158+
3EA9207D257F580300F3EB75 /* FiveViewController.m */,
154159
97C146FA1CF9000F007C117D /* Main.storyboard */,
155160
97C146FD1CF9000F007C117D /* Assets.xcassets */,
156161
97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */,
@@ -326,6 +331,7 @@
326331
978B8F6F1D3862AE00F588F7 /* AppDelegate.m in Sources */,
327332
97C146F31CF9000F007C117D /* main.m in Sources */,
328333
1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */,
334+
3EA9207E257F580300F3EB75 /* FiveViewController.m in Sources */,
329335
3FA943CE23F27D2D00DAC679 /* HomeViewController.m in Sources */,
330336
3E2B2ABF24F7C2DB00BC7183 /* ThirdViewController.m in Sources */,
331337
);

example/ios/Runner/AppDelegate.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ + (FlutterEngine *)dStackForFlutterEngine
7575

7676
- (nonnull UINavigationController *)dStack:(nonnull DStack *)stack navigationControllerForNode:(nonnull DStackNode *)node
7777
{
78-
return self.currentController.navigationController;
78+
return [[self currentController] navigationController];
7979
}
8080

8181
- (void)dStack:(nonnull DStack *)stack presentWithNode:(nonnull DStackNode *)node
@@ -87,7 +87,7 @@ - (void)dStack:(nonnull DStack *)stack presentWithNode:(nonnull DStackNode *)nod
8787
[navi.topViewController presentViewController:didPushController animated:node.animated completion:nil];
8888
}
8989
}
90-
90+
//navi = 0x000000016d5720b0
9191
- (void)dStack:(nonnull DStack *)stack pushWithNode:(nonnull DStackNode *)node
9292
{
9393
UIViewController *didPresentController = nil;

example/ios/Runner/DStackTestCase.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ NS_ASSUME_NONNULL_BEGIN
1313
@interface DStackTestCase : NSObject
1414

1515
@property (nonatomic, readonly) NSArray <NSDictionary *>*homeTestCases;
16+
@property (nonatomic, readonly) NSArray <NSDictionary *>*secondVCTestCases;
17+
@property (nonatomic, readonly) NSArray <NSDictionary *>*thirdVCTestCases;
18+
@property (nonatomic, readonly) NSArray <NSDictionary *>*fourVCTestCases;
19+
@property (nonatomic, readonly) NSArray <NSDictionary *>*fiveVCTestCases;
1620

1721
@end
1822

example/ios/Runner/DStackTestCase.m

Lines changed: 160 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,47 +8,180 @@
88
#import <DStack.h>
99
#import "DStackTestCase.h"
1010
#import "SecondViewController.h"
11+
#import "FiveViewController.h"
12+
#import "DStackViewController.h"
1113

1214
@implementation DStackTestCase
1315
{
14-
NSArray *_homeDatSource;
16+
NSArray *_homeDataSource;
17+
NSArray *_secondVCSource;
18+
NSArray *_thirdVCSource;
19+
NSArray *_fourVCSource;
20+
NSArray *_fiveVCSource;
1521
}
1622

1723
- (instancetype)init
1824
{
1925
if ([super init]) {
20-
_homeDatSource = @[
21-
@{
22-
@"text": @"打开SecondViewController",
23-
@"clicked": ^(UIViewController *controller) {
24-
SecondViewController *secondVC = [[SecondViewController alloc] init];
25-
secondVC.hidesBottomBarWhenPushed = YES;
26-
[controller.navigationController pushViewController:secondVC animated:YES];
27-
}
28-
},
29-
@{
30-
@"text": @"打开Flutter page4",
31-
@"clicked": ^(UIViewController *controller) {
32-
[[DStack sharedInstance] pushFlutterPageWithFlutterClass:DFlutterViewController.class
33-
route:@"page4"];
34-
}
35-
},
36-
@{
37-
@"text": @"打开Flutter page1 有参数",
38-
@"clicked": ^(UIViewController *controller) {
39-
[[DStack sharedInstance] pushFlutterPageWithFlutterClass:DFlutterViewController.class
40-
route:@"page1"
41-
params:@{@"fromNative": @"来自原生"}];
42-
}
43-
},
44-
];
26+
[self initData];
4527
}
4628
return self;
4729
}
4830

31+
- (void)initData
32+
{
33+
_homeDataSource = @[
34+
@{
35+
@"text": @"打开SecondViewController",
36+
@"clicked": ^(UIViewController *controller) {
37+
SecondViewController *secondVC = [[SecondViewController alloc] init];
38+
secondVC.hidesBottomBarWhenPushed = YES;
39+
[controller.navigationController pushViewController:secondVC animated:YES];
40+
}
41+
},
42+
@{
43+
@"text": @"打开Flutter page4",
44+
@"clicked": ^(UIViewController *controller) {
45+
[[DStack sharedInstance] pushFlutterPageWithFlutterClass:DFlutterViewController.class
46+
route:@"page4"];
47+
}
48+
},
49+
@{
50+
@"text": @"打开Flutter page1 有参数",
51+
@"clicked": ^(UIViewController *controller) {
52+
[[DStack sharedInstance] pushFlutterPageWithFlutterClass:DFlutterViewController.class
53+
route:@"page1"
54+
params:@{@"fromNative": @"来自原生"}];
55+
}
56+
},
57+
];
58+
59+
_secondVCSource = @[
60+
@{
61+
@"text": @"返回",
62+
@"clicked": ^(UIViewController *controller) {
63+
[controller.navigationController popViewControllerAnimated:YES];
64+
}
65+
},
66+
@{
67+
@"text": @"打开Flutter page5",
68+
@"clicked": ^(UIViewController *controller) {
69+
[[DStack sharedInstance] pushFlutterPageWithFlutterClass:DFlutterViewController.class
70+
route:@"page5"];
71+
}
72+
},
73+
@{
74+
@"text": @"弹窗",
75+
@"clicked": ^(UIViewController *controller) {
76+
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"弹窗"
77+
message:@"弹出来了" preferredStyle:UIAlertControllerStyleAlert];
78+
UIAlertAction *action = [UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleCancel handler:nil];
79+
[alert addAction:action];
80+
[controller presentViewController:alert animated:YES completion:nil];
81+
}
82+
},
83+
];
84+
85+
_thirdVCSource = @[
86+
@{
87+
@"text": @"返回",
88+
@"clicked": ^(UIViewController *controller) {
89+
[controller.navigationController popViewControllerAnimated:YES];
90+
}
91+
},
92+
@{
93+
@"text": @"打开Flutter page6",
94+
@"clicked": ^(UIViewController *controller) {
95+
[[DStack sharedInstance] pushFlutterPageWithFlutterClass:DFlutterViewController.class
96+
route:@"page6"];
97+
}
98+
},
99+
100+
];
101+
102+
_fourVCSource = @[
103+
@{
104+
@"text": @"返回",
105+
@"clicked": ^(UIViewController *controller) {
106+
[controller dismissViewControllerAnimated:YES completion:nil];
107+
}
108+
},
109+
@{
110+
@"text": @"弹窗",
111+
@"clicked": ^(UIViewController *controller) {
112+
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"弹窗"
113+
message:@"弹出来了" preferredStyle:UIAlertControllerStyleAlert];
114+
UIAlertAction *action = [UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleCancel handler:nil];
115+
[alert addAction:action];
116+
[controller presentViewController:alert animated:YES completion:nil];
117+
}
118+
},
119+
@{
120+
@"text": @"present 无navigation的FiveVC",
121+
@"clicked": ^(UIViewController *controller) {
122+
FiveViewController *five = [[FiveViewController alloc] init];
123+
[controller presentViewController:five animated:YES completion:nil];
124+
}
125+
},
126+
@{
127+
@"text": @"present 有navigation的FiveVC",
128+
@"clicked": ^(UIViewController *controller) {
129+
FiveViewController *five = [[FiveViewController alloc] init];
130+
DStackViewController *navi = [[DStackViewController alloc] initWithRootViewController:five];
131+
[controller presentViewController:navi animated:YES completion:nil];
132+
}
133+
},
134+
];
135+
136+
_fiveVCSource = @[
137+
@{
138+
@"text": @"返回",
139+
@"clicked": ^(UIViewController *controller) {
140+
[controller dismissViewControllerAnimated:YES completion:nil];
141+
}
142+
},
143+
@{
144+
@"text": @"打开Flutter page6",
145+
@"clicked": ^(UIViewController *controller) {
146+
[[DStack sharedInstance] pushFlutterPageWithFlutterClass:DFlutterViewController.class
147+
route:@"page6"];
148+
}
149+
},
150+
@{
151+
@"text": @"打开FiveViewController",
152+
@"clicked": ^(UIViewController *controller) {
153+
FiveViewController *five = [[FiveViewController alloc] init];
154+
[controller.navigationController pushViewController:five animated:YES];
155+
}
156+
},
157+
];
158+
}
159+
160+
161+
49162
- (NSArray<NSDictionary *> *)homeTestCases
50163
{
51-
return _homeDatSource;
164+
return _homeDataSource;
165+
}
166+
167+
- (NSArray<NSDictionary *> *)secondVCTestCases
168+
{
169+
return _secondVCSource;
170+
}
171+
172+
- (NSArray<NSDictionary *> *)thirdVCTestCases
173+
{
174+
return _thirdVCSource;
175+
}
176+
177+
- (NSArray<NSDictionary *> *)fourVCTestCases
178+
{
179+
return _fourVCSource;
180+
}
181+
182+
- (NSArray<NSDictionary *> *)fiveVCTestCases
183+
{
184+
return _fiveVCSource;
52185
}
53186

54187
@end
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//
2+
// FiveViewController.h
3+
// Runner
4+
//
5+
// Created by Caven on 2020/12/8.
6+
// Copyright © 2020 The Chromium Authors. All rights reserved.
7+
//
8+
9+
#import "HomeViewController.h"
10+
11+
NS_ASSUME_NONNULL_BEGIN
12+
13+
@interface FiveViewController : HomeViewController
14+
15+
@end
16+
17+
NS_ASSUME_NONNULL_END
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//
2+
// FiveViewController.m
3+
// Runner
4+
//
5+
// Created by Caven on 2020/12/8.
6+
// Copyright © 2020 The Chromium Authors. All rights reserved.
7+
//
8+
9+
#import "FiveViewController.h"
10+
11+
@interface FiveViewController ()
12+
13+
@end
14+
15+
@implementation FiveViewController
16+
17+
- (void)viewDidLoad {
18+
[super viewDidLoad];
19+
}
20+
21+
- (NSArray *)dataSource
22+
{
23+
return self.testCase.fiveVCTestCases;
24+
}
25+
26+
@end

example/ios/Runner/FourViewController.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
// Copyright © 2020 The Chromium Authors. All rights reserved.
77
//
88

9-
#import <UIKit/UIKit.h>
9+
#import "HomeViewController.h"
1010

1111
NS_ASSUME_NONNULL_BEGIN
1212

13-
@interface FourViewController : UIViewController
13+
@interface FourViewController : HomeViewController
1414

1515
@end
1616

example/ios/Runner/FourViewController.m

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,13 @@ @interface FourViewController ()
1414

1515
@implementation FourViewController
1616

17-
- (void)viewWillAppear:(BOOL)animated
18-
{
19-
[super viewWillAppear:animated];
20-
}
21-
2217
- (void)viewDidLoad {
2318
[super viewDidLoad];
24-
self.view.backgroundColor = [UIColor cyanColor];
25-
26-
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
27-
button.frame = CGRectMake(0, 100, 60, 35);
28-
[button setTitle:@"返回" forState:UIControlStateNormal];
29-
[button setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
30-
[button addTarget:self action:@selector(back:) forControlEvents:UIControlEventTouchUpInside];
31-
[self.view addSubview:button];
3219
}
3320

34-
- (void)back:(UIButton *)button
21+
- (NSArray *)dataSource
3522
{
36-
[self dismissViewControllerAnimated:YES completion:nil];
23+
return self.testCase.fourVCTestCases;
3724
}
3825

3926
@end

example/ios/Runner/HomeViewController.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,17 @@
77
//
88

99
#import <UIKit/UIKit.h>
10+
#import "DStackTestCase.h"
1011

1112
NS_ASSUME_NONNULL_BEGIN
1213

1314
@interface HomeViewController : UIViewController
1415

16+
@property (nonatomic, strong) DStackTestCase *testCase;
17+
18+
19+
- (NSArray *)dataSource;
20+
1521
@end
1622

1723
NS_ASSUME_NONNULL_END

0 commit comments

Comments
 (0)