dismissWithCompletion

This commit is contained in:
Ben Guo 2016-10-21 14:41:43 -04:00
parent 123bf96609
commit 4100525890
5 changed files with 41 additions and 5 deletions

View File

@ -256,7 +256,7 @@ class CheckoutViewController: UIViewController, STPPaymentContextDelegate, STPSh
else {
self.shippingRow.detail = "Enter \(self.shippingString) Info"
}
self.shippingVC.dismiss(withHostViewController: self)
self.shippingVC.dismiss(completion: nil)
}
}

View File

@ -53,6 +53,13 @@ NS_ASSUME_NONNULL_BEGIN
*/
@property(nonatomic)STPUserInformation *prefilledInformation;
/**
* If you're pushing `STPPaymentMethodsViewController` onto an existing `UINavigationController`'s stack, you should use this method to dismiss it, since it may have pushed an additional add card view controller onto the navigation controller's stack.
*
* @param completion The callback to run after the view controller is dismissed. You may specify nil for this parameter.
*/
- (void)dismissWithCompletion:(nullable STPVoidBlock)completion;
@end
/**

View File

@ -47,9 +47,9 @@ NS_ASSUME_NONNULL_BEGIN
/**
* If you're pushing `STPShippingAddressViewController` onto an existing `UINavigationController`'s stack, you should use this method to dismiss it, since it may have pushed an additional shipping method view controller onto the navigation controller's stack.
*
* @param hostViewController the view controller that the shipping address view controller was pushed onto.
* @param completion The callback to run after the view controller is dismissed. You may specify nil for this parameter.
*/
- (void)dismissWithHostViewController:(UIViewController *)hostViewController;
- (void)dismissWithCompletion:(nullable STPVoidBlock)completion;
@end

View File

@ -27,6 +27,7 @@
#import "STPWeakStrongMacros.h"
#import "STPLocalizationUtils.h"
#import "STPDispatchFunctions.h"
#import "UINavigationController+Stripe_Completion.h"
@interface STPPaymentMethodsViewController()<STPPaymentMethodsInternalViewControllerDelegate, STPAddCardViewControllerDelegate>
@ -210,6 +211,22 @@
[self internalViewControllerDidCreateToken:token completion:completion];
}
- (void)dismissWithCompletion:(STPVoidBlock)completion {
if ([self stp_isAtRootOfNavigationController]) {
[self.presentingViewController dismissViewControllerAnimated:YES completion:completion];
}
else {
UIViewController *previous = self.navigationController.viewControllers.firstObject;
for (UIViewController *viewController in self.navigationController.viewControllers) {
if (viewController == self) {
break;
}
previous = viewController;
}
[self.navigationController stp_popToViewController:previous animated:YES completion:completion];
}
}
@end
@implementation STPPaymentMethodsViewController (Private)

View File

@ -263,8 +263,20 @@
[self presentViewController:alertController animated:YES completion:nil];
}
- (void)dismissWithHostViewController:(UIViewController *)hostViewController {
[self.navigationController stp_popToViewController:hostViewController animated:YES completion:nil];
- (void)dismissWithCompletion:(STPVoidBlock)completion {
if ([self stp_isAtRootOfNavigationController]) {
[self.presentingViewController dismissViewControllerAnimated:YES completion:completion];
}
else {
UIViewController *previous = self.navigationController.viewControllers.firstObject;
for (UIViewController *viewController in self.navigationController.viewControllers) {
if (viewController == self) {
break;
}
previous = viewController;
}
[self.navigationController stp_popToViewController:previous animated:YES completion:completion];
}
}
#pragma mark - STPAddressViewModelDelegate