From e0c115fb59de27db51dfa798782d60f406fdbdeb Mon Sep 17 00:00:00 2001 From: Jax DesMarais-Leder Date: Thu, 12 Oct 2023 11:03:16 -0500 Subject: [PATCH 1/2] Convert BraintreeDemoBaseViewController and BraintreeDemoPaymentButtonBaseViewController to Swift --- .../BaseViewController.swift | 29 +++++++++++ .../BraintreeDemoBaseViewController.h | 12 ----- .../BraintreeDemoBaseViewController.m | 30 ----------- ...ntreeDemoPaymentButtonBaseViewController.h | 15 ------ ...ntreeDemoPaymentButtonBaseViewController.m | 39 -------------- .../PaymentButtonBaseViewController.swift | 51 +++++++++++++++++++ Demo/Demo.xcodeproj/project.pbxproj | 25 ++++----- 7 files changed, 90 insertions(+), 111 deletions(-) create mode 100644 Demo/Application/Base/Base View Controllers/BaseViewController.swift delete mode 100644 Demo/Application/Base/Base View Controllers/BraintreeDemoBaseViewController.h delete mode 100644 Demo/Application/Base/Base View Controllers/BraintreeDemoBaseViewController.m delete mode 100644 Demo/Application/Base/Base View Controllers/BraintreeDemoPaymentButtonBaseViewController.h delete mode 100644 Demo/Application/Base/Base View Controllers/BraintreeDemoPaymentButtonBaseViewController.m create mode 100644 Demo/Application/Base/Base View Controllers/PaymentButtonBaseViewController.swift diff --git a/Demo/Application/Base/Base View Controllers/BaseViewController.swift b/Demo/Application/Base/Base View Controllers/BaseViewController.swift new file mode 100644 index 0000000000..aa9913d75e --- /dev/null +++ b/Demo/Application/Base/Base View Controllers/BaseViewController.swift @@ -0,0 +1,29 @@ +import UIKit +import BraintreeCore + +// TODO: remove @objcMembers when final VC is Swift +@objcMembers class BaseViewController: UIViewController { + + var progressBlock: ((String?) -> Void) = { _ in } + var completionBlock: ((BTPaymentMethodNonce?) -> Void) = { _ in } + var transactionBlock: (() -> Void) = { } + + // TODO: remove @objc when final VC is Swift + @objc(initWithAuthorization:) + init(authorization: String) { + super.init(nibName: nil, bundle: nil) + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + override func viewDidLoad() { + let tapToDismissKeyboard = UITapGestureRecognizer(target: self, action: #selector(dismissKeyboard)) + view.addGestureRecognizer(tapToDismissKeyboard) + } + + @objc func dismissKeyboard() { + view.endEditing(true) + } +} diff --git a/Demo/Application/Base/Base View Controllers/BraintreeDemoBaseViewController.h b/Demo/Application/Base/Base View Controllers/BraintreeDemoBaseViewController.h deleted file mode 100644 index 9807faca11..0000000000 --- a/Demo/Application/Base/Base View Controllers/BraintreeDemoBaseViewController.h +++ /dev/null @@ -1,12 +0,0 @@ -#import -@class BTPaymentMethodNonce; - -@interface BraintreeDemoBaseViewController : UIViewController - -- (instancetype)initWithAuthorization:(NSString *)authorization NS_DESIGNATED_INITIALIZER; - -@property (nonatomic, weak) void (^progressBlock)(NSString *newStatus); -@property (nonatomic, weak) void (^completionBlock)(BTPaymentMethodNonce *paymentMethodNonce); -@property (nonatomic, weak) void (^transactionBlock)(void); - -@end diff --git a/Demo/Application/Base/Base View Controllers/BraintreeDemoBaseViewController.m b/Demo/Application/Base/Base View Controllers/BraintreeDemoBaseViewController.m deleted file mode 100644 index 497861e9d4..0000000000 --- a/Demo/Application/Base/Base View Controllers/BraintreeDemoBaseViewController.m +++ /dev/null @@ -1,30 +0,0 @@ -#import "BraintreeDemoBaseViewController.h" - -@implementation BraintreeDemoBaseViewController - -- (instancetype)initWithCoder:(__unused NSCoder *)aDecoder { - return [self initWithAuthorization:nil]; -} - -- (instancetype)initWithNibName:(__unused NSString *)nibNameOrNil bundle:(__unused NSBundle *)nibBundleOrNil { - return [self initWithAuthorization:nil]; -} - -- (instancetype)initWithAuthorization:(__unused NSString *)authorization { - if ([self class] == [BraintreeDemoBaseViewController class]) { - @throw [NSException exceptionWithName:NSInternalInconsistencyException reason:@"Subclasses must override initWithAuthorization:" userInfo:nil]; - } - - return [super initWithNibName:nil bundle:nil]; -} - -- (void) viewDidLoad { - UITapGestureRecognizer *tapToDismissKeyboard = [[UITapGestureRecognizer new] initWithTarget: self action: @selector(dismissKeyboard)]; - [self.view addGestureRecognizer: tapToDismissKeyboard]; -} - --(void) dismissKeyboard { - [self.view endEditing: YES]; -} - -@end diff --git a/Demo/Application/Base/Base View Controllers/BraintreeDemoPaymentButtonBaseViewController.h b/Demo/Application/Base/Base View Controllers/BraintreeDemoPaymentButtonBaseViewController.h deleted file mode 100644 index aa9e6def1b..0000000000 --- a/Demo/Application/Base/Base View Controllers/BraintreeDemoPaymentButtonBaseViewController.h +++ /dev/null @@ -1,15 +0,0 @@ -#import -#import -#import "BraintreeDemoBaseViewController.h" -@class BTAPIClient; - -@interface BraintreeDemoPaymentButtonBaseViewController : BraintreeDemoBaseViewController - -@property (nonatomic, strong) BTAPIClient *apiClient; -@property (nonatomic, strong) UIView *paymentButton; -@property (nonatomic, readwrite) CGFloat centerYConstant; - -/// A factory method that subclasses must implement to return a payment button view. -- (UIView *)createPaymentButton; - -@end diff --git a/Demo/Application/Base/Base View Controllers/BraintreeDemoPaymentButtonBaseViewController.m b/Demo/Application/Base/Base View Controllers/BraintreeDemoPaymentButtonBaseViewController.m deleted file mode 100644 index 59e32e7e22..0000000000 --- a/Demo/Application/Base/Base View Controllers/BraintreeDemoPaymentButtonBaseViewController.m +++ /dev/null @@ -1,39 +0,0 @@ -#import "BraintreeDemoPaymentButtonBaseViewController.h" -@import BraintreeCore; - -@implementation BraintreeDemoPaymentButtonBaseViewController - -- (instancetype)initWithAuthorization:(NSString *)authorization { - self = [super initWithAuthorization:authorization]; - if (self) { - self.apiClient = [[BTAPIClient alloc] initWithAuthorization:authorization]; - } - return self; -} - -- (void)viewDidLoad { - [super viewDidLoad]; - - self.title = NSLocalizedString(@"Payment Button", nil); - - [self.view setBackgroundColor:UIColor.systemBackgroundColor]; - - self.paymentButton = [self createPaymentButton]; - self.paymentButton.translatesAutoresizingMaskIntoConstraints = NO; - [self.view addSubview:self.paymentButton]; - - [NSLayoutConstraint activateConstraints:@[ - [self.paymentButton.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor constant:20], - [self.paymentButton.trailingAnchor constraintEqualToAnchor:self.view.trailingAnchor constant:-20], - [self.paymentButton.centerYAnchor constraintEqualToAnchor:self.view.centerYAnchor constant:self.centerYConstant], - [self.paymentButton.heightAnchor constraintEqualToConstant:100.0] - ]]; -} - -- (UIView *)createPaymentButton { - @throw [NSException exceptionWithName:NSInternalInconsistencyException - reason:@"Subclasses of BraintreeDemoPaymentButtonViewController must override createPaymentButton. BraintreeDemoPaymentButtonViewController should not be initialized directly." - userInfo:nil]; -} - -@end diff --git a/Demo/Application/Base/Base View Controllers/PaymentButtonBaseViewController.swift b/Demo/Application/Base/Base View Controllers/PaymentButtonBaseViewController.swift new file mode 100644 index 0000000000..ba48e1a77b --- /dev/null +++ b/Demo/Application/Base/Base View Controllers/PaymentButtonBaseViewController.swift @@ -0,0 +1,51 @@ +import UIKit +import BraintreeCore + +class PaymentButtonBaseViewController: BaseViewController { + + let apiClient: BTAPIClient + + private var paymentButton: UIView = UIView() + + override init(authorization: String) { + apiClient = BTAPIClient(authorization: authorization)! + super.init(authorization: authorization) + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + override func viewDidLoad() { + super.viewDidLoad() + + title = "Payment Button" + view.backgroundColor = .systemBackground + + paymentButton = createPaymentButton() + view.addSubview(paymentButton) + + NSLayoutConstraint.activate([ + paymentButton.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 20), + paymentButton.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -20), + paymentButton.centerYAnchor.constraint(equalTo: view.centerYAnchor), + paymentButton.heightAnchor.constraint(equalToConstant: 100) + ]) + } + + /// A factory method that subclasses must implement to return a payment button view. + func createPaymentButton() -> UIView { + UIView() + } + + func createButton(title: String, action: Selector) -> UIButton { + let button = UIButton(type: .system) + button.setTitle(title, for: .normal) + button.setTitleColor(.blue, for: .normal) + button.setTitleColor(.lightGray, for: .highlighted) + button.setTitleColor(.lightGray, for: .disabled) + button.translatesAutoresizingMaskIntoConstraints = false + button.addTarget(self, action: action, for: .touchUpInside) + return button + } +} diff --git a/Demo/Demo.xcodeproj/project.pbxproj b/Demo/Demo.xcodeproj/project.pbxproj index 8a45a26e7c..6fe73721de 100644 --- a/Demo/Demo.xcodeproj/project.pbxproj +++ b/Demo/Demo.xcodeproj/project.pbxproj @@ -19,7 +19,6 @@ 42C574D525FA6CAC008B3681 /* AppSwitcher.swift in Sources */ = {isa = PBXBuildFile; fileRef = 42C574D425FA6CAC008B3681 /* AppSwitcher.swift */; }; 42C5BDD625A4CE4800E8FF40 /* AmericanExpress_UITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 42C5BDD525A4CE4800E8FF40 /* AmericanExpress_UITests.swift */; }; 57108A152832E789004EB870 /* PayPalNativeCheckoutViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57108A142832E789004EB870 /* PayPalNativeCheckoutViewController.swift */; }; - 57108A152832E789004EB870 /* BraintreeDemoPayPalNativeCheckoutViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57108A142832E789004EB870 /* BraintreeDemoPayPalNativeCheckoutViewController.swift */; }; 57108A172832EA04004EB870 /* BraintreePayPalNativeCheckout.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 57108A162832EA04004EB870 /* BraintreePayPalNativeCheckout.framework */; }; 57108A182832EA04004EB870 /* BraintreePayPalNativeCheckout.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 57108A162832EA04004EB870 /* BraintreePayPalNativeCheckout.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 803D64F5256DAF9A00ACE692 /* BraintreeAmericanExpress.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 803D64EA256DAF9A00ACE692 /* BraintreeAmericanExpress.framework */; }; @@ -40,17 +39,15 @@ 803D6508256DAF9A00ACE692 /* BraintreeVenmo.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 803D64F3256DAF9A00ACE692 /* BraintreeVenmo.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 803FB9DE26D93146002BF92D /* BTCardFormView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 803FB9DD26D93146002BF92D /* BTCardFormView.swift */; }; 80581A5F2553170000006F53 /* Venmo_UITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80581A5D2553152A00006F53 /* Venmo_UITests.swift */; }; - 80D36DEE2A7967F20035380E /* VenmoViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80D36DED2A7967F20035380E /* VenmoViewController.swift */; }; 809E86A62AD00AF4004998B0 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 809E86A52AD00AF4004998B0 /* AppDelegate.swift */; }; 809E86A82AD01FE7004998B0 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 809E86A72AD01FE7004998B0 /* SceneDelegate.swift */; }; + 80D36DEE2A7967F20035380E /* VenmoViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80D36DED2A7967F20035380E /* VenmoViewController.swift */; }; 9C36BD2926B3071B00F0A559 /* PPRiskMagnes.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9C36BD2826B3071A00F0A559 /* PPRiskMagnes.xcframework */; }; 9C36BD4C26B311D900F0A559 /* CardinalMobile.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9C36BD4826B3102B00F0A559 /* CardinalMobile.xcframework */; }; 9C36BD4D26B311D900F0A559 /* CardinalMobile.xcframework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 9C36BD4826B3102B00F0A559 /* CardinalMobile.xcframework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; A0988F9124DB44B20095EEEE /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = A0988E7B24DB44B10095EEEE /* Localizable.strings */; }; A0988F9224DB44B20095EEEE /* BraintreeDemoSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = A0988E7E24DB44B10095EEEE /* BraintreeDemoSettings.swift */; }; A0988F9324DB44B20095EEEE /* Settings.bundle in Resources */ = {isa = PBXBuildFile; fileRef = A0988E7F24DB44B10095EEEE /* Settings.bundle */; }; - A0988F9424DB44B20095EEEE /* BraintreeDemoPaymentButtonBaseViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = A0988E8124DB44B10095EEEE /* BraintreeDemoPaymentButtonBaseViewController.m */; }; - A0988F9524DB44B20095EEEE /* BraintreeDemoBaseViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = A0988E8224DB44B10095EEEE /* BraintreeDemoBaseViewController.m */; }; A0988F9724DB44B20095EEEE /* BraintreeDemoContainmentViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = A0988E8624DB44B10095EEEE /* BraintreeDemoContainmentViewController.m */; }; A0988F9824DB44B20095EEEE /* Launch Screen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = A0988E8824DB44B10095EEEE /* Launch Screen.storyboard */; }; A0988FE324DB44B20095EEEE /* Main.strings in Resources */ = {isa = PBXBuildFile; fileRef = A0988F5224DB44B10095EEEE /* Main.strings */; }; @@ -64,6 +61,8 @@ BE35FCD82A1BD162008F0326 /* BraintreeLocalPayment.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BE35FCD72A1BD162008F0326 /* BraintreeLocalPayment.framework */; }; BE35FCD92A1BD162008F0326 /* BraintreeLocalPayment.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = BE35FCD72A1BD162008F0326 /* BraintreeLocalPayment.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; BE777AC427D9370400487D23 /* SEPADirectDebitViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BE777AC327D9370400487D23 /* SEPADirectDebitViewController.swift */; }; + BE994B0B2AD8377D00470773 /* BaseViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BE994B0A2AD8377D00470773 /* BaseViewController.swift */; }; + BE994B0D2AD838A500470773 /* PaymentButtonBaseViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BE994B0C2AD838A500470773 /* PaymentButtonBaseViewController.swift */; }; BE9BD75928872E4D00022983 /* BraintreeSEPADirectDebit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BE9BD75828872E4D00022983 /* BraintreeSEPADirectDebit.framework */; }; BE9BD75A28872E4D00022983 /* BraintreeSEPADirectDebit.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = BE9BD75828872E4D00022983 /* BraintreeSEPADirectDebit.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; BEAAAA342A98E5E6001ECA63 /* IdealViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BEAAAA332A98E5E6001ECA63 /* IdealViewController.swift */; }; @@ -150,9 +149,9 @@ 803D64F3256DAF9A00ACE692 /* BraintreeVenmo.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = BraintreeVenmo.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 803FB9DD26D93146002BF92D /* BTCardFormView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BTCardFormView.swift; sourceTree = ""; }; 80581A5D2553152A00006F53 /* Venmo_UITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Venmo_UITests.swift; sourceTree = ""; }; - 80D36DED2A7967F20035380E /* VenmoViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VenmoViewController.swift; sourceTree = ""; }; 809E86A52AD00AF4004998B0 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 809E86A72AD01FE7004998B0 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = ""; }; + 80D36DED2A7967F20035380E /* VenmoViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VenmoViewController.swift; sourceTree = ""; }; 9C030582267BDF9E00DB7A68 /* Demo.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Demo.entitlements; sourceTree = ""; }; 9C36BD2826B3071A00F0A559 /* PPRiskMagnes.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = PPRiskMagnes.xcframework; path = ../Frameworks/XCFrameworks/PPRiskMagnes.xcframework; sourceTree = ""; }; 9C36BD4826B3102B00F0A559 /* CardinalMobile.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = CardinalMobile.xcframework; path = ../Frameworks/XCFrameworks/CardinalMobile.xcframework; sourceTree = ""; }; @@ -160,10 +159,6 @@ A0988E7B24DB44B10095EEEE /* Localizable.strings */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; path = Localizable.strings; sourceTree = ""; }; A0988E7E24DB44B10095EEEE /* BraintreeDemoSettings.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BraintreeDemoSettings.swift; sourceTree = ""; }; A0988E7F24DB44B10095EEEE /* Settings.bundle */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.plug-in"; path = Settings.bundle; sourceTree = ""; }; - A0988E8124DB44B10095EEEE /* BraintreeDemoPaymentButtonBaseViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BraintreeDemoPaymentButtonBaseViewController.m; sourceTree = ""; }; - A0988E8224DB44B10095EEEE /* BraintreeDemoBaseViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BraintreeDemoBaseViewController.m; sourceTree = ""; }; - A0988E8324DB44B10095EEEE /* BraintreeDemoPaymentButtonBaseViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BraintreeDemoPaymentButtonBaseViewController.h; sourceTree = ""; }; - A0988E8424DB44B10095EEEE /* BraintreeDemoBaseViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BraintreeDemoBaseViewController.h; sourceTree = ""; }; A0988E8624DB44B10095EEEE /* BraintreeDemoContainmentViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BraintreeDemoContainmentViewController.m; sourceTree = ""; }; A0988E8824DB44B10095EEEE /* Launch Screen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = "Launch Screen.storyboard"; sourceTree = ""; }; A0988E8924DB44B10095EEEE /* BraintreeDemoContainmentViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BraintreeDemoContainmentViewController.h; sourceTree = ""; }; @@ -184,6 +179,8 @@ BE24C66A28E490F30067B11A /* PayPalCheckout.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = PayPalCheckout.xcframework; path = ../Frameworks/XCFrameworks/PayPalCheckout.xcframework; sourceTree = ""; }; BE35FCD72A1BD162008F0326 /* BraintreeLocalPayment.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = BraintreeLocalPayment.framework; sourceTree = BUILT_PRODUCTS_DIR; }; BE777AC327D9370400487D23 /* SEPADirectDebitViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SEPADirectDebitViewController.swift; sourceTree = ""; }; + BE994B0A2AD8377D00470773 /* BaseViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseViewController.swift; sourceTree = ""; }; + BE994B0C2AD838A500470773 /* PaymentButtonBaseViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PaymentButtonBaseViewController.swift; sourceTree = ""; }; BE9BD75828872E4D00022983 /* BraintreeSEPADirectDebit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = BraintreeSEPADirectDebit.framework; sourceTree = BUILT_PRODUCTS_DIR; }; BEAAAA332A98E5E6001ECA63 /* IdealViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IdealViewController.swift; sourceTree = ""; }; BEAAAD042970A70D000BD296 /* BTSEPADirectDebitTestHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BTSEPADirectDebitTestHelper.swift; sourceTree = ""; }; @@ -336,10 +333,8 @@ A0988E8024DB44B10095EEEE /* Base View Controllers */ = { isa = PBXGroup; children = ( - A0988E8424DB44B10095EEEE /* BraintreeDemoBaseViewController.h */, - A0988E8224DB44B10095EEEE /* BraintreeDemoBaseViewController.m */, - A0988E8324DB44B10095EEEE /* BraintreeDemoPaymentButtonBaseViewController.h */, - A0988E8124DB44B10095EEEE /* BraintreeDemoPaymentButtonBaseViewController.m */, + BE994B0A2AD8377D00470773 /* BaseViewController.swift */, + BE994B0C2AD838A500470773 /* PaymentButtonBaseViewController.swift */, ); path = "Base View Controllers"; sourceTree = ""; @@ -678,8 +673,8 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - A0988F9524DB44B20095EEEE /* BraintreeDemoBaseViewController.m in Sources */, BEAAAA342A98E5E6001ECA63 /* IdealViewController.swift in Sources */, + BE994B0D2AD838A500470773 /* PaymentButtonBaseViewController.swift in Sources */, BED7C4CA2ABDD35700EF8550 /* PayPalWebCheckoutViewController.swift in Sources */, BEBD52872AABA513005D6687 /* ThreeDSecureViewController.swift in Sources */, 803FB9DE26D93146002BF92D /* BTCardFormView.swift in Sources */, @@ -690,7 +685,7 @@ A0988F9724DB44B20095EEEE /* BraintreeDemoContainmentViewController.m in Sources */, BEE9304B2A992F6200C85779 /* CardTokenizationViewController.swift in Sources */, BED461832AD072D9001B0DDF /* CardHelpers.swift in Sources */, - A0988F9424DB44B20095EEEE /* BraintreeDemoPaymentButtonBaseViewController.m in Sources */, + BE994B0B2AD8377D00470773 /* BaseViewController.swift in Sources */, 80D36DEE2A7967F20035380E /* VenmoViewController.swift in Sources */, BEE930492A98FE9200C85779 /* DataCollectorViewController.swift in Sources */, BEAAAD052970A70D000BD296 /* BTSEPADirectDebitTestHelper.swift in Sources */, From 643d64ab87eb71943db5f3233ea66fd810596935 Mon Sep 17 00:00:00 2001 From: Jax DesMarais-Leder Date: Thu, 12 Oct 2023 11:03:44 -0500 Subject: [PATCH 2/2] update all feature VCs with updated base ViewControllers --- Demo/Application/Base/AppDelegate.swift | 1 + .../BraintreeDemoContainmentViewController.m | 11 +++--- Demo/Application/Base/SceneDelegate.swift | 1 + .../Features/AmexViewController.swift | 18 ++-------- .../Features/ApplePayViewController.swift | 6 ++-- .../CardTokenizationViewController.swift | 20 +++-------- .../DataCollectorViewController.swift | 19 +++------- .../Features/IdealViewController.swift | 14 ++------ .../PayPalNativeCheckoutViewController.swift | 25 ++++--------- .../PayPalWebCheckoutViewController.swift | 22 +++--------- .../SEPADirectDebitViewController.swift | 35 ++++++------------- .../Features/ThreeDSecureViewController.swift | 12 ++----- .../Features/VenmoViewController.swift | 26 ++++---------- .../Supporting Files/Demo-Bridging-Header.h | 3 -- 14 files changed, 56 insertions(+), 157 deletions(-) diff --git a/Demo/Application/Base/AppDelegate.swift b/Demo/Application/Base/AppDelegate.swift index 274e295cf3..cc50fe8884 100644 --- a/Demo/Application/Base/AppDelegate.swift +++ b/Demo/Application/Base/AppDelegate.swift @@ -1,4 +1,5 @@ import Foundation +import BraintreeCore @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { diff --git a/Demo/Application/Base/BraintreeDemoContainmentViewController.m b/Demo/Application/Base/BraintreeDemoContainmentViewController.m index 2c69d93dd7..705be103ba 100644 --- a/Demo/Application/Base/BraintreeDemoContainmentViewController.m +++ b/Demo/Application/Base/BraintreeDemoContainmentViewController.m @@ -1,5 +1,4 @@ #import "BraintreeDemoContainmentViewController.h" -#import "BraintreeDemoBaseViewController.h" #import "Demo-Swift.h" @import InAppSettingsKit; @import BraintreeCore; @@ -9,7 +8,7 @@ @interface BraintreeDemoContainmentViewController () @property (nonatomic, strong) UIBarButtonItem *statusItem; @property (nonatomic, strong) BTPaymentMethodNonce *latestTokenizedPayment; @property (nonatomic, strong) NSString *latestTokenizedPaymentString; -@property (nonatomic, strong) BraintreeDemoBaseViewController *currentDemoViewController; +@property (nonatomic, strong) BaseViewController *currentDemoViewController; @end @@ -190,7 +189,7 @@ - (void)reloadIntegration { } } -- (void)setCurrentDemoViewController:(BraintreeDemoBaseViewController *)currentDemoViewController { +- (void)setCurrentDemoViewController:(BaseViewController *)currentDemoViewController { _currentDemoViewController = currentDemoViewController; if (!_currentDemoViewController) { @@ -208,18 +207,18 @@ - (void)setCurrentDemoViewController:(BraintreeDemoBaseViewController *)currentD self.title = _currentDemoViewController.title; } -- (BraintreeDemoBaseViewController *)instantiateCurrentIntegrationViewControllerWithAuthorization:(NSString *)authorization { +- (BaseViewController *)instantiateCurrentIntegrationViewControllerWithAuthorization:(NSString *)authorization { NSString *integrationName = [[NSUserDefaults standardUserDefaults] stringForKey:@"BraintreeDemoSettingsIntegration"]; NSLog(@"Loading integration: %@", integrationName); // The prefix "Demo." is required for integration view controllers written in Swift Class integrationClass = NSClassFromString(integrationName) ?: NSClassFromString([NSString stringWithFormat:@"Demo.%@", integrationName]); - if (![integrationClass isSubclassOfClass:[BraintreeDemoBaseViewController class]]) { + if (![integrationClass isSubclassOfClass:[BaseViewController class]]) { NSLog(@"%@ is not a valid BraintreeDemoBaseViewController", integrationName); return nil; } - return [(BraintreeDemoBaseViewController *)[integrationClass alloc] initWithAuthorization:authorization]; + return [(BaseViewController *)[integrationClass alloc] initWithAuthorization:authorization]; } - (void)containIntegrationViewController:(UIViewController *)viewController { diff --git a/Demo/Application/Base/SceneDelegate.swift b/Demo/Application/Base/SceneDelegate.swift index 43b00d90f6..8f1d250cc6 100644 --- a/Demo/Application/Base/SceneDelegate.swift +++ b/Demo/Application/Base/SceneDelegate.swift @@ -1,4 +1,5 @@ import Foundation +import BraintreeCore class SceneDelegate: UIResponder, UIWindowSceneDelegate { diff --git a/Demo/Application/Features/AmexViewController.swift b/Demo/Application/Features/AmexViewController.swift index bdb17fc438..8972d5a853 100644 --- a/Demo/Application/Features/AmexViewController.swift +++ b/Demo/Application/Features/AmexViewController.swift @@ -1,8 +1,8 @@ -import Foundation +import UIKit import BraintreeAmericanExpress import BraintreeCard -class AmexViewController: BraintreeDemoPaymentButtonBaseViewController { +class AmexViewController: PaymentButtonBaseViewController { lazy var amexClient = BTAmericanExpressClient(apiClient: apiClient) lazy var cardClient = BTCardClient(apiClient: apiClient) @@ -12,7 +12,7 @@ class AmexViewController: BraintreeDemoPaymentButtonBaseViewController { title = "Amex" } - override func createPaymentButton() -> UIView! { + override func createPaymentButton() -> UIView { let validCardButton = createButton(title: "Valid card", action: #selector(tappedValidCard)) let insufficientPointsCardButton = createButton(title: "Insufficient points card", action: #selector(tappedInsufficientPointsCard)) let ineligibleCardButton = createButton(title: "Ineligible card", action: #selector(tappedIneligibleCard)) @@ -72,16 +72,4 @@ class AmexViewController: BraintreeDemoPaymentButtonBaseViewController { } } } - - // TODO: move this helper into BraintreeDemoPaymentButtonBaseViewController once converted so all buttons share the same characteristics - private func createButton(title: String, action: Selector) -> UIButton { - let button = UIButton(type: .system) - button.setTitle(title, for: .normal) - button.setTitleColor(.blue, for: .normal) - button.setTitleColor(.lightGray, for: .highlighted) - button.setTitleColor(.lightGray, for: .disabled) - button.translatesAutoresizingMaskIntoConstraints = false - button.addTarget(self, action: action, for: .touchUpInside) - return button - } } diff --git a/Demo/Application/Features/ApplePayViewController.swift b/Demo/Application/Features/ApplePayViewController.swift index fbca4539e8..3c1bab9f7b 100644 --- a/Demo/Application/Features/ApplePayViewController.swift +++ b/Demo/Application/Features/ApplePayViewController.swift @@ -2,7 +2,7 @@ import Foundation import BraintreeApplePay import PassKit -class ApplePayViewController: BraintreeDemoPaymentButtonBaseViewController { +class ApplePayViewController: PaymentButtonBaseViewController { lazy var applePayClient = BTApplePayClient(apiClient: apiClient) @@ -12,13 +12,13 @@ class ApplePayViewController: BraintreeDemoPaymentButtonBaseViewController { title = "Apple Pay" } - override func createPaymentButton() -> UIView! { + override func createPaymentButton() -> UIView { if !PKPaymentAuthorizationViewController.canMakePayments() { progressBlock("canMakePayments returned false, hiding Apple Pay button") - return nil } let applePayButton = PKPaymentButton(paymentButtonType: .plain, paymentButtonStyle: .automatic) + applePayButton.translatesAutoresizingMaskIntoConstraints = false applePayButton.addTarget(self, action: #selector(tappedApplePayButton), for: .touchUpInside) NSLayoutConstraint.activate([applePayButton.heightAnchor.constraint(equalToConstant: 50)]) diff --git a/Demo/Application/Features/CardTokenizationViewController.swift b/Demo/Application/Features/CardTokenizationViewController.swift index 49cead0e50..198f72f245 100644 --- a/Demo/Application/Features/CardTokenizationViewController.swift +++ b/Demo/Application/Features/CardTokenizationViewController.swift @@ -1,10 +1,10 @@ import UIKit import BraintreeCard -class CardTokenizationViewController: BraintreeDemoPaymentButtonBaseViewController { +class CardTokenizationViewController: PaymentButtonBaseViewController { private let cardFormView = BTCardFormView() - private let autofillButton = UIButton(type: .system) + private var autofillButton = UIButton(type: .system) override func viewDidLoad() { super.viewDidLoad() @@ -12,15 +12,8 @@ class CardTokenizationViewController: BraintreeDemoPaymentButtonBaseViewControll layoutConstraints() } - override func createPaymentButton() -> UIView! { - let submitButton = UIButton(type: .system) - submitButton.setTitle("Submit", for: .normal) - submitButton.setTitleColor(.blue, for: .normal) - submitButton.setTitleColor(.lightGray, for: .highlighted) - submitButton.setTitleColor(.lightGray, for: .disabled) - submitButton.addTarget(self, action: #selector(tappedSubmit), for: .touchUpInside) - submitButton.translatesAutoresizingMaskIntoConstraints = false - + override func createPaymentButton() -> UIView { + let submitButton = createButton(title: "Submit", action: #selector(tappedSubmit)) return submitButton } @@ -62,10 +55,7 @@ class CardTokenizationViewController: BraintreeDemoPaymentButtonBaseViewControll cardFormView.hidePostalCodeField = true setFieldsEnabled(true) - autofillButton.setTitle("Autofill", for: .normal) - autofillButton.setTitleColor(.blue, for: .normal) - autofillButton.addTarget(self, action: #selector(tappedAutofill), for: .touchUpInside) - autofillButton.translatesAutoresizingMaskIntoConstraints = false + autofillButton = createButton(title: "Autofill", action: #selector(tappedAutofill)) view.addSubview(cardFormView) view.addSubview(autofillButton) diff --git a/Demo/Application/Features/DataCollectorViewController.swift b/Demo/Application/Features/DataCollectorViewController.swift index ffed02fa5d..07f21eece3 100644 --- a/Demo/Application/Features/DataCollectorViewController.swift +++ b/Demo/Application/Features/DataCollectorViewController.swift @@ -2,7 +2,7 @@ import UIKit import BraintreeDataCollector import BraintreeCore -class DataCollectorViewController: BraintreeDemoPaymentButtonBaseViewController { +class DataCollectorViewController: PaymentButtonBaseViewController { var dataLabel = UILabel() @@ -11,15 +11,8 @@ class DataCollectorViewController: BraintreeDemoPaymentButtonBaseViewController title = "Braintree Data Collector" } - override func createPaymentButton() -> UIView! { - let dataCollectorButton = UIButton(type: .system) - dataCollectorButton.setTitle("Collect Device Data", for: .normal) - dataCollectorButton.setTitleColor(.blue, for: .normal) - dataCollectorButton.setTitleColor(.lightGray, for: .highlighted) - dataCollectorButton.setTitleColor(.lightGray, for: .disabled) - dataCollectorButton.addTarget(self, action: #selector(tappedCollect), for: .touchUpInside) - dataCollectorButton.translatesAutoresizingMaskIntoConstraints = false - + override func createPaymentButton() -> UIView { + let dataCollectorButton = createButton(title: "Collect Device Data", action: #selector(tappedCollect)) let label = UILabel() label.numberOfLines = 0 label.adjustsFontSizeToFitWidth = true @@ -31,13 +24,9 @@ class DataCollectorViewController: BraintreeDemoPaymentButtonBaseViewController stackView.axis = .vertical stackView.spacing = 5 stackView.alignment = .center + stackView.distribution = .fillEqually stackView.translatesAutoresizingMaskIntoConstraints = false - NSLayoutConstraint.activate([ - dataCollectorButton.heightAnchor.constraint(equalToConstant: 19.5), - label.heightAnchor.constraint(equalToConstant: 19.5) - ]) - return stackView } diff --git a/Demo/Application/Features/IdealViewController.swift b/Demo/Application/Features/IdealViewController.swift index b132457fb5..d009d8a5ba 100644 --- a/Demo/Application/Features/IdealViewController.swift +++ b/Demo/Application/Features/IdealViewController.swift @@ -2,7 +2,7 @@ import Foundation import BraintreeLocalPayment import BraintreeCore -class IdealViewController: BraintreeDemoPaymentButtonBaseViewController { +class IdealViewController: PaymentButtonBaseViewController { var localPaymentClient: BTLocalPaymentClient! var paymentIDLabel: UILabel = UILabel() @@ -11,20 +11,12 @@ class IdealViewController: BraintreeDemoPaymentButtonBaseViewController { super.viewDidLoad() progressBlock("Loading iDEAL Merchant Account...") - paymentButton.isHidden = false progressBlock("Ready!") title = "iDEAL" } - override func createPaymentButton() -> UIView! { - let iDEALButton = UIButton(type: .custom) - iDEALButton.setTitle("Pay with iDEAL", for: .normal) - iDEALButton.setTitleColor(.blue, for: .normal) - iDEALButton.setTitleColor(.lightGray, for: .highlighted) - iDEALButton.setTitleColor(.lightGray, for: .disabled) - iDEALButton.addTarget(self, action: #selector(tappedIDEAL), for: .touchUpInside) - iDEALButton.translatesAutoresizingMaskIntoConstraints = false - + override func createPaymentButton() -> UIView { + let iDEALButton = createButton(title: "Pay with iDEAL", action: #selector(tappedIDEAL)) let label = UILabel() label.numberOfLines = 0 label.translatesAutoresizingMaskIntoConstraints = false diff --git a/Demo/Application/Features/PayPalNativeCheckoutViewController.swift b/Demo/Application/Features/PayPalNativeCheckoutViewController.swift index e354d1b0e5..ad1aa0703b 100644 --- a/Demo/Application/Features/PayPalNativeCheckoutViewController.swift +++ b/Demo/Application/Features/PayPalNativeCheckoutViewController.swift @@ -2,30 +2,19 @@ import Foundation import UIKit import BraintreePayPalNativeCheckout -class PayPalNativeCheckoutViewController: BraintreeDemoPaymentButtonBaseViewController { +class PayPalNativeCheckoutViewController: PaymentButtonBaseViewController { lazy var payPalNativeCheckoutClient = BTPayPalNativeCheckoutClient(apiClient: apiClient) - func checkoutPaymentButton(title: String, action: Selector) -> UIButton { - let button = UIButton(type: .system) - button.setTitle(title, for: .normal) - button.setTitleColor(.blue, for: .normal) - button.setTitleColor(.lightGray, for: .highlighted) - button.setTitleColor(.lightGray, for: .disabled) - button.translatesAutoresizingMaskIntoConstraints = false - button.addTarget(self, action: action, for: .touchUpInside) - return button - } - - override func createPaymentButton() -> UIView! { - let payPalCheckoutButton = checkoutPaymentButton(title: "One Time Checkout", action: #selector(tappedPayPalCheckout)) + override func createPaymentButton() -> UIView { + let payPalCheckoutButton = createButton(title: "One Time Checkout", action: #selector(tappedPayPalCheckout)) // Buyers are shown a billing agreement without purchase - // For more information: https://developer.paypal.com/braintree/docs/guides/paypal/vault/ios/v5 - let vaultCheckoutButton = checkoutPaymentButton(title: "Vault Checkout", action: #selector(tappedVaultCheckout)) + // For more information: https://developer.paypal.com/braintree/docs/guides/paypal/vault/ios/v6 + let vaultCheckoutButton = createButton(title: "Vault Checkout", action: #selector(tappedVaultCheckout)) // Buyers are shown a billing agreement with purchase - // For more information: https://developer.paypal.com/braintree/docs/guides/paypal/checkout-with-vault/ios/v5 - let checkoutWithVaultButton = checkoutPaymentButton(title: "Checkout With Vault", action: #selector(tappedCheckoutWithVault)) + // For more information: https://developer.paypal.com/braintree/docs/guides/paypal/checkout-with-vault/ios/v6 + let checkoutWithVaultButton = createButton(title: "Checkout With Vault", action: #selector(tappedCheckoutWithVault)) let stackView = UIStackView(arrangedSubviews: [payPalCheckoutButton, vaultCheckoutButton, checkoutWithVaultButton]) stackView.axis = .vertical diff --git a/Demo/Application/Features/PayPalWebCheckoutViewController.swift b/Demo/Application/Features/PayPalWebCheckoutViewController.swift index 4490d4b739..cc6c73db22 100644 --- a/Demo/Application/Features/PayPalWebCheckoutViewController.swift +++ b/Demo/Application/Features/PayPalWebCheckoutViewController.swift @@ -2,14 +2,14 @@ import Foundation import UIKit import BraintreePayPal -class PayPalWebCheckoutViewController: BraintreeDemoPaymentButtonBaseViewController { +class PayPalWebCheckoutViewController: PaymentButtonBaseViewController { lazy var payPalClient = BTPayPalClient(apiClient: apiClient) - override func createPaymentButton() -> UIView! { - let payPalCheckoutButton = paymentButton(title: "PayPal Checkout", action: #selector(tappedPayPalCheckout)) - let payPalVaultButton = paymentButton(title: "PayPal Vault", action: #selector(tappedPayPalVault)) - let payPalPayLaterButton = paymentButton(title: "PayPal with Pay Later Offered", action: #selector(tappedPayPalPayLater)) + override func createPaymentButton() -> UIView { + let payPalCheckoutButton = createButton(title: "PayPal Checkout", action: #selector(tappedPayPalCheckout)) + let payPalVaultButton = createButton(title: "PayPal Vault", action: #selector(tappedPayPalVault)) + let payPalPayLaterButton = createButton(title: "PayPal with Pay Later Offered", action: #selector(tappedPayPalPayLater)) let buttons = [payPalCheckoutButton, payPalVaultButton, payPalPayLaterButton] let stackView = UIStackView(arrangedSubviews: buttons) @@ -78,16 +78,4 @@ class PayPalWebCheckoutViewController: BraintreeDemoPaymentButtonBaseViewControl self.completionBlock(nonce) } } - - // TODO: move into a shared class once the base ViewControllers are converted to Swift - func paymentButton(title: String, action: Selector) -> UIButton { - let button = UIButton(type: .system) - button.setTitle(title, for: .normal) - button.setTitleColor(.blue, for: .normal) - button.setTitleColor(.lightGray, for: .highlighted) - button.setTitleColor(.lightGray, for: .disabled) - button.translatesAutoresizingMaskIntoConstraints = false - button.addTarget(self, action: action, for: .touchUpInside) - return button - } } diff --git a/Demo/Application/Features/SEPADirectDebitViewController.swift b/Demo/Application/Features/SEPADirectDebitViewController.swift index 88361d09ca..576838d316 100644 --- a/Demo/Application/Features/SEPADirectDebitViewController.swift +++ b/Demo/Application/Features/SEPADirectDebitViewController.swift @@ -1,35 +1,20 @@ import UIKit import AuthenticationServices +import BraintreeCore import BraintreeSEPADirectDebit -class SEPADirectDebitViewController: BraintreeDemoBaseViewController { - private let sepaDirectDebitClient: BTSEPADirectDebitClient - private let sepaDirectDebitButton = UIButton(type: .system) - - override init?(authorization: String!) { - guard let apiClient = BTAPIClient(authorization: authorization) else { return nil } - - sepaDirectDebitClient = BTSEPADirectDebitClient(apiClient: apiClient) +class SEPADirectDebitViewController: PaymentButtonBaseViewController { + + lazy var sepaDirectDebitClient = BTSEPADirectDebitClient(apiClient: apiClient) - super.init(authorization: authorization) - + override func viewDidLoad() { + super.viewDidLoad() title = "SEPA Direct Debit" - - sepaDirectDebitButton.setTitle("SEPA Direct Debit", for: .normal) - sepaDirectDebitButton.translatesAutoresizingMaskIntoConstraints = false - sepaDirectDebitButton.addTarget(self, action: #selector(sepaDirectDebitButtonTapped), for: .touchUpInside) - view.addSubview(sepaDirectDebitButton) - - NSLayoutConstraint.activate( - [ - sepaDirectDebitButton.centerXAnchor.constraint(equalTo: view.centerXAnchor), - sepaDirectDebitButton.centerYAnchor.constraint(equalTo: view.centerYAnchor) - ] - ) } - - required init?(coder: NSCoder) { - fatalError("init(coder:) has not been implemented") + + override func createPaymentButton() -> UIView { + let sepaDirectDebitButton = createButton(title: "SEPA Direct Debit", action: #selector(sepaDirectDebitButtonTapped)) + return sepaDirectDebitButton } // MARK: - SEPA Direct Debit implementation diff --git a/Demo/Application/Features/ThreeDSecureViewController.swift b/Demo/Application/Features/ThreeDSecureViewController.swift index 9c8214e30b..748b86e81a 100644 --- a/Demo/Application/Features/ThreeDSecureViewController.swift +++ b/Demo/Application/Features/ThreeDSecureViewController.swift @@ -2,7 +2,7 @@ import Foundation import BraintreeCard import BraintreeThreeDSecure -class ThreeDSecureViewController: BraintreeDemoPaymentButtonBaseViewController { +class ThreeDSecureViewController: PaymentButtonBaseViewController { private let cardFormView = BTCardFormView() private let autofillButton = UIButton(type: .system) @@ -20,14 +20,8 @@ class ThreeDSecureViewController: BraintreeDemoPaymentButtonBaseViewController { layoutConstraints() } - override func createPaymentButton() -> UIView! { - let verifyNewCardButton = UIButton(type: .system) - verifyNewCardButton.setTitle("Tokenize and Verify New Card", for: .normal) - verifyNewCardButton.setTitleColor(.blue, for: .normal) - verifyNewCardButton.setTitleColor(.lightGray, for: .highlighted) - verifyNewCardButton.setTitleColor(.lightGray, for: .disabled) - verifyNewCardButton.addTarget(self, action: #selector(tappedToVerifyNewCard), for: .touchUpInside) - verifyNewCardButton.translatesAutoresizingMaskIntoConstraints = false + override func createPaymentButton() -> UIView { + let verifyNewCardButton = createButton(title: "Tokenize and Verify New Card", action: #selector(tappedToVerifyNewCard)) callbackCountLabel.translatesAutoresizingMaskIntoConstraints = false callbackCountLabel.textAlignment = .center diff --git a/Demo/Application/Features/VenmoViewController.swift b/Demo/Application/Features/VenmoViewController.swift index 8e26d46b60..1dfbdc797f 100644 --- a/Demo/Application/Features/VenmoViewController.swift +++ b/Demo/Application/Features/VenmoViewController.swift @@ -1,7 +1,7 @@ import UIKit import BraintreeVenmo -class VenmoViewController: BraintreeDemoPaymentButtonBaseViewController { +class VenmoViewController: PaymentButtonBaseViewController { var venmoClient: BTVenmoClient! @@ -11,16 +11,9 @@ class VenmoViewController: BraintreeDemoPaymentButtonBaseViewController { title = "Custom Venmo Button" } - override func createPaymentButton() -> UIView! { - let venmoButton = UIButton(type: .system) - venmoButton.setTitle("Venmo", for: .normal) - venmoButton.setTitleColor(.blue, for: .normal) - venmoButton.setTitleColor(.lightGray, for: .highlighted) - venmoButton.setTitleColor(.lightGray, for: .disabled) - venmoButton.addTarget(self, action: #selector(tappedVenmo), for: .touchUpInside) - venmoButton.translatesAutoresizingMaskIntoConstraints = false - - let venmoECDButton = UIButton(type: .system) + override func createPaymentButton() -> UIView { + let venmoButton = createButton(title: "Venmo", action: #selector(tappedVenmo)) + let venmoECDButton = createButton(title: "Venmo (with ECD options)", action: #selector(tappedVenmoWithECD)) venmoECDButton.setTitle("Venmo (with ECD options)", for: .normal) venmoECDButton.setTitleColor(.blue, for: .normal) venmoECDButton.setTitleColor(.lightGray, for: .highlighted) @@ -32,16 +25,9 @@ class VenmoViewController: BraintreeDemoPaymentButtonBaseViewController { stackView.axis = .vertical stackView.spacing = 5 stackView.alignment = .center + stackView.distribution = .fillEqually stackView.translatesAutoresizingMaskIntoConstraints = false - - NSLayoutConstraint.activate([ - venmoButton.topAnchor.constraint(equalTo: stackView.topAnchor), - venmoButton.heightAnchor.constraint(equalToConstant: 19.5), - - venmoECDButton.topAnchor.constraint(equalTo: venmoButton.bottomAnchor, constant: 5), - venmoECDButton.heightAnchor.constraint(equalToConstant: 19.5) - ]) - + return stackView } diff --git a/Demo/Application/Supporting Files/Demo-Bridging-Header.h b/Demo/Application/Supporting Files/Demo-Bridging-Header.h index 5c4d4b215e..7cbb0eb6b4 100644 --- a/Demo/Application/Supporting Files/Demo-Bridging-Header.h +++ b/Demo/Application/Supporting Files/Demo-Bridging-Header.h @@ -1,4 +1 @@ -#import "BraintreeDemoBaseViewController.h" -#import -#import "BraintreeDemoPaymentButtonBaseViewController.h" #import "BraintreeDemoContainmentViewController.h"