Skip to content

Commit

Permalink
[iOS] 增加从原生open flutter页面时,open操作完成后的回调能力
Browse files Browse the repository at this point in the history
  • Loading branch information
luckysmg authored and ColdPaleLight committed May 10, 2021
1 parent 6c90fa6 commit 7f55728
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 10 deletions.
5 changes: 3 additions & 2 deletions example/ios/Runner/MyFlutterBoostDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ - (void) pushNativeRoute:(NSString *) pageName arguments:(NSDictionary *) argume
}
}

- (void) pushFlutterRoute:(NSString *) pageName uniqueId:(NSString *)uniqueId arguments:(NSDictionary *) arguments {
- (void) pushFlutterRoute:(NSString *) pageName uniqueId:(NSString *)uniqueId arguments:(NSDictionary *) arguments completion:(void(^)(BOOL)) completion{

FlutterEngine* engine = [[FlutterBoost instance ] engine];
engine.viewController = nil;
Expand All @@ -39,10 +39,11 @@ - (void) pushFlutterRoute:(NSString *) pageName uniqueId:(NSString *)uniqueId ar
BOOL present= [arguments[@"present"] boolValue];
if(present){
[self.navigationController presentViewController:vc animated:animated completion:^{
completion(YES);
}];
}else{
[self.navigationController pushViewController:vc animated:animated];

completion(YES);
}
}

Expand Down
9 changes: 7 additions & 2 deletions example/ios/Runner/UIViewControllerDemo.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ - (void)viewDidLoad {
- (IBAction)pushFlutterPage:(id)sender {


[[FlutterBoost instance] open:@"flutterPage" arguments:@{@"animated":@(YES)} ];
[[FlutterBoost instance] open:@"flutterPage" arguments:@{@"animated":@(YES)} completion:^(BOOL completion) {

} ];


// [FlutterBoostPlugin open:@"first" urlParams:@{kPageCallBackId:@"MycallbackId#1"} exts:@{@"animated":@(YES)} onPageFinished:^(NSDictionary *result) {
Expand All @@ -40,7 +42,10 @@ - (IBAction)pushFlutterPage:(id)sender {

- (IBAction)present:(id)sender {

[[FlutterBoost instance] open:@"secondStateful" arguments:@{@"present":@(YES)}];
[[FlutterBoost instance] open:@"secondStateful" arguments:@{@"present":@(YES)} completion:^(BOOL completion) {


}];

// [FlutterBoostPlugin open:@"second" urlParams:@{@"present":@(YES),kPageCallBackId:@"MycallbackId#2"} exts:@{@"animated":@(YES)} onPageFinished:^(NSDictionary *result) {
// NSLog(@"call me when page finished, and your result is:%@", result);
Expand Down
4 changes: 2 additions & 2 deletions ios/Classes/FlutterBoost.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@
/// 通过arguments可以设置为以present方式打开页面:arguments:@{@"present":@(YES)}
/// @param pageName 打开的页面资源定位符
/// @param arguments 传入页面的参数; 若有特殊逻辑,可以通过这个参数设置回调的id
- (void)open:(NSString *)pageName
arguments:(NSDictionary *)arguments;
/// @param completion 页面open操作完成的回调,注意,从原生调用此方法跳转此参数才会生效
- (void)open:(NSString *)pageName arguments:(NSDictionary *)arguments completion:(void(^)(BOOL)) completion;


/// 将原生页面的数据回传到flutter侧的页面的的方法
Expand Down
4 changes: 2 additions & 2 deletions ios/Classes/FlutterBoost.m
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ - (FlutterViewController *) currentViewController{
}

#pragma mark - open/close Page
- (void)open:(NSString *)pageName arguments:(NSDictionary *)arguments {
- (void)open:(NSString *)pageName arguments:(NSDictionary *)arguments completion:(void(^)(BOOL)) completion {

[self.plugin.delegate pushFlutterRoute:pageName uniqueId:nil arguments:arguments];
[self.plugin.delegate pushFlutterRoute:pageName uniqueId:nil arguments:arguments completion:completion];

}

Expand Down
2 changes: 1 addition & 1 deletion ios/Classes/FlutterBoostDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
- (FlutterEngine*) engine;
@required
- (void) pushNativeRoute:(NSString *) pageName arguments:(NSDictionary *) arguments;
- (void) pushFlutterRoute:(NSString *) pageName uniqueId:(NSString *)uniqueId arguments:(NSDictionary *) arguments;
- (void) pushFlutterRoute:(NSString *) pageName uniqueId:(NSString *)uniqueId arguments:(NSDictionary *) arguments completion:(void(^)(BOOL)) completion;
- (void) popRoute:(NSString *)uniqueId;
@end

4 changes: 3 additions & 1 deletion ios/Classes/FlutterBoostPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ -(void)pushNativeRoute:(FBCommonParams*)input error:(FlutterError *_Nullable *_N
}

-(void)pushFlutterRoute:(FBCommonParams*)input error:(FlutterError *_Nullable *_Nonnull)error {
[self.delegate pushFlutterRoute:input.pageName uniqueId:input.uniqueId arguments:input.arguments];
[self.delegate pushFlutterRoute:input.pageName uniqueId:input.uniqueId arguments:input.arguments completion:^(BOOL completion) {
//因为这里是flutter端开启新容器push一个页面,所以这里原生用不着,所以这里completion传一个空的即可
}];
}

-(void)popRoute:(FBCommonParams*)input error:(FlutterError *_Nullable *_Nonnull)error {
Expand Down

0 comments on commit 7f55728

Please sign in to comment.