Skip to content

Commit

Permalink
GDDViewControllerTransition support completion block
Browse files Browse the repository at this point in the history
  • Loading branch information
alonsolu committed Aug 29, 2017
1 parent 3accacf commit a68fcc7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ NS_ASSUME_NONNULL_BEGIN

- (GDDViewControllerTransition *(^)(id data))data;
- (GDDViewControllerTransition *(^)(GDDPBViewOption *viewOption))viewOption;
- (GDDViewControllerTransition *(^)(void (^completion)()))completion;

/**
* 总是创建新的 ViewController 实例, 并显示
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ @implementation GDDViewControllerTransition {
enum GDDViewControllerTransitionStackMode _stackMode;
BOOL _alreadyInStack; // 是否已经显示过了
Class _viewControllerClass;
void (^_completion)(void);
}

- (GDDViewControllerTransition *(^)(id data))data {
Expand All @@ -32,6 +33,13 @@ @implementation GDDViewControllerTransition {
};
}

- (GDDViewControllerTransition *(^)(void (^completion)()))completion {
return ^GDDViewControllerTransition *(void (^completion)()) {
_completion = completion;
return self;
};
}

- (id <GDDTransitionBuilder> (^)(Class viewControllerClass))toClass {
return ^id <GDDTransitionBuilder>(Class viewControllerClass) {
if (_viewOption.launchMode) {
Expand Down Expand Up @@ -124,7 +132,7 @@ - (instancetype)foundAndMergeViewOption:(UIViewController *)found {
}
UIViewController *rootViewController = UIApplication.sharedApplication.keyWindow.rootViewController;
if (rootViewController.presentedViewController) { // 避免内存泄漏, 以释放 rootViewController 和 rootViewController.presentedViewController
[rootViewController dismissViewControllerAnimated:_viewOption.animated != GDPBBool_False completion:nil];
[rootViewController dismissViewControllerAnimated:_viewOption.animated != GDPBBool_False completion:_completion];
}
UIWindow *window = UIApplication.sharedApplication.delegate.window;
if (!window) {
Expand All @@ -149,7 +157,7 @@ - (instancetype)foundAndMergeViewOption:(UIViewController *)found {
// bring viewController to front
UIViewController *controller = self.viewController;
if (controller.presentedViewController) {
[controller dismissViewControllerAnimated:_viewOption.animated != GDPBBool_False completion:nil];
[controller dismissViewControllerAnimated:_viewOption.animated != GDPBBool_False completion:_completion];
}
UIViewController *current = controller;
while (current.parentViewController) {
Expand Down Expand Up @@ -200,7 +208,7 @@ - (void)displayAndRefresh {
}

[self config:YES]; // 某些 ViewOption 需要在 present 之前设置才会生效
[top presentViewController:_stackMode == PRESENT ? controller : [[UINavigationController alloc] initWithRootViewController:controller] animated:_viewOption.animated != GDPBBool_False completion:nil];
[top presentViewController:_stackMode == PRESENT ? controller : [[UINavigationController alloc] initWithRootViewController:controller] animated:_viewOption.animated != GDPBBool_False completion:_completion];
[self updateData];
}

Expand Down Expand Up @@ -383,4 +391,4 @@ + (UIViewController *)getVisibleChildViewController:(UIViewController *)parent {
return nil;
}
}
@end
@end

0 comments on commit a68fcc7

Please sign in to comment.