-
Notifications
You must be signed in to change notification settings - Fork 995
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add VerticalSavedPaymentOptionsViewController (#3569)
## Summary - Adds VerticalSavedPaymentOptionsViewController - Adds scaffolding in place snapshot tests - Handles navigation between vertical PaymentSheet and VerticalSavedPaymentOptionsViewController https://github.com/stripe/stripe-ios/assets/88012362/b340e598-3300-4b40-9320-d36504958c5c ## Motivation https://jira.corp.stripe.com/browse/MOBILESDK-2023 ## Testing - Manual ## Changelog N/A
- Loading branch information
1 parent
e5e1685
commit 8d7dc51
Showing
12 changed files
with
178 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
.../PaymentSheet/Saved Payment Method Screen/VerticalSavedPaymentOptionsViewController.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
// | ||
// VerticalSavedPaymentOptionsViewController.swift | ||
// StripePaymentSheet | ||
// | ||
// Created by Nick Porter on 5/7/24. | ||
// | ||
|
||
import Foundation | ||
@_spi(STP) import StripeCore | ||
@_spi(STP) import StripeUICore | ||
import UIKit | ||
|
||
/// A view controller that shows a list of saved payment methods in a vertical orientation | ||
class VerticalSavedPaymentOptionsViewController: UIViewController { | ||
|
||
private let configuration: PaymentSheet.Configuration | ||
|
||
// MARK: - UI properties | ||
|
||
lazy var navigationBar: SheetNavigationBar = { | ||
let navBar = SheetNavigationBar(isTestMode: configuration.apiClient.isTestmode, | ||
appearance: configuration.appearance) | ||
navBar.setStyle(.back) | ||
navBar.delegate = self | ||
return navBar | ||
}() | ||
|
||
private lazy var headerLabel: UILabel = { | ||
let label = PaymentSheetUI.makeHeaderLabel(appearance: configuration.appearance) | ||
label.text = .Localized.select_payment_method | ||
return label | ||
}() | ||
|
||
private lazy var stackView: UIStackView = { | ||
let stackView = UIStackView(arrangedSubviews: [headerLabel]) | ||
stackView.directionalLayoutMargins = PaymentSheetUI.defaultMargins | ||
stackView.isLayoutMarginsRelativeArrangement = true | ||
stackView.axis = .vertical | ||
stackView.spacing = PaymentSheetUI.defaultPadding | ||
return stackView | ||
}() | ||
|
||
init(configuration: PaymentSheet.Configuration) { | ||
self.configuration = configuration | ||
super.init(nibName: nil, bundle: nil) | ||
} | ||
|
||
required init?(coder: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
view.backgroundColor = configuration.appearance.colors.background | ||
configuration.style.configure(self) | ||
|
||
view.addAndPinSubviewToSafeArea(stackView, insets: PaymentSheetUI.defaultSheetMargins) | ||
} | ||
} | ||
|
||
// MARK: - BottomSheetContentViewController | ||
extension VerticalSavedPaymentOptionsViewController: BottomSheetContentViewController { | ||
var allowsDragToDismiss: Bool { | ||
// TODO | ||
return true | ||
} | ||
|
||
func didTapOrSwipeToDismiss() { | ||
dismiss(animated: true) | ||
} | ||
|
||
var requiresFullScreen: Bool { | ||
// TODO | ||
return false | ||
} | ||
|
||
func didFinishAnimatingHeight() { | ||
// no-op | ||
} | ||
} | ||
|
||
// MARK: - SheetNavigationBarDelegate | ||
extension VerticalSavedPaymentOptionsViewController: SheetNavigationBarDelegate { | ||
func sheetNavigationBarDidClose(_ sheetNavigationBar: SheetNavigationBar) { | ||
// no-op we are in 'back' style mode | ||
} | ||
|
||
func sheetNavigationBarDidBack(_ sheetNavigationBar: SheetNavigationBar) { | ||
_ = bottomSheetController?.popContentViewController() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
...ymentSheetTests/PaymentSheet/VerticalSavedPaymentOptionsViewControllerSnapshotTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// | ||
// VerticalSavedPaymentOptionsViewControllerSnapshotTests.swift | ||
// StripePaymentSheet | ||
// | ||
// Created by Nick Porter on 5/7/24. | ||
// | ||
|
||
import StripeCoreTestUtils | ||
@_spi(STP) @testable import StripePaymentSheet | ||
@testable import StripePaymentsTestUtils | ||
import XCTest | ||
|
||
final class VerticalSavedPaymentOptionsViewControllerSnapshotTests: STPSnapshotTestCase { | ||
|
||
func test_VerticalSavedPaymentOptionsViewControllerSnapshotTestsDarkMode() { | ||
_test_VerticalSavedPaymentOptionsViewControllerSnapshotTests(darkMode: true) | ||
} | ||
|
||
func test_VerticalSavedPaymentOptionsViewControllerSnapshotTestsLightMode() { | ||
_test_VerticalSavedPaymentOptionsViewControllerSnapshotTests(darkMode: false) | ||
} | ||
|
||
func test_VerticalSavedPaymentOptionsViewControllerSnapshotTestsAppearance() { | ||
_test_VerticalSavedPaymentOptionsViewControllerSnapshotTests(darkMode: false, appearance: ._testMSPaintTheme) | ||
} | ||
|
||
func _test_VerticalSavedPaymentOptionsViewControllerSnapshotTests(darkMode: Bool, appearance: PaymentSheet.Appearance = .default) { | ||
var configuration = PaymentSheet.Configuration() | ||
configuration.appearance = appearance | ||
let sut = VerticalSavedPaymentOptionsViewController(configuration: configuration) | ||
let testWindow = UIWindow(frame: CGRect(x: 0, y: 0, width: 428, height: 500)) | ||
testWindow.isHidden = false | ||
if darkMode { | ||
testWindow.overrideUserInterfaceStyle = .dark | ||
} | ||
testWindow.rootViewController = sut | ||
sut.view.autosizeHeight(width: 375) | ||
STPSnapshotVerifyView(sut.view) | ||
} | ||
} |
Binary file added
BIN
+16.8 KB
...ts/test_VerticalSavedPaymentOptionsViewControllerSnapshotTestsAppearance@3x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+18.4 KB
...ests/test_VerticalSavedPaymentOptionsViewControllerSnapshotTestsDarkMode@3x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+17.3 KB
...sts/test_VerticalSavedPaymentOptionsViewControllerSnapshotTestsLightMode@3x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.