Skip to content

Commit

Permalink
Merge branch 'joyceqin-bideprecation' of github.com:stripe/stripe-ios…
Browse files Browse the repository at this point in the history
… into joyceqin-bideprecation
  • Loading branch information
joyceqin-stripe committed Oct 1, 2024
2 parents f53ee19 + edc1956 commit e4a473f
Show file tree
Hide file tree
Showing 14 changed files with 419 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
413D18422C7FA30A0051AA42 /* TextInput.swift in Sources */ = {isa = PBXBuildFile; fileRef = 413D18412C7FA30A0051AA42 /* TextInput.swift */; };
413D18442C7FAE280051AA42 /* OptionListRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 413D18432C7FAE280051AA42 /* OptionListRow.swift */; };
413D184A2C7FCE5E0051AA42 /* StripeConnectExample.xctestplan in Resources */ = {isa = PBXBuildFile; fileRef = 413D18492C7FCE5E0051AA42 /* StripeConnectExample.xctestplan */; };
4161C2892CA1B438005BD67C /* StripeUICore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4161C2882CA1B438005BD67C /* StripeUICore.framework */; };
4161C28A2CA1B438005BD67C /* StripeUICore.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 4161C2882CA1B438005BD67C /* StripeUICore.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
4161C2822C9DBB92005BD67C /* OnboardingSettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4161C2812C9DBB92005BD67C /* OnboardingSettingsView.swift */; };
4161C2852C9DC235005BD67C /* OnboardingSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4161C2842C9DC235005BD67C /* OnboardingSettings.swift */; };
4161C2872C9DD035005BD67C /* URL+Valid.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4161C2862C9DD035005BD67C /* URL+Valid.swift */; };
4161C2892CA1B438005BD67C /* StripeUICore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4161C2882CA1B438005BD67C /* StripeUICore.framework */; };
4161C28A2CA1B438005BD67C /* StripeUICore.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 4161C2882CA1B438005BD67C /* StripeUICore.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
416E9E972C76BD4400A0B917 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 416E9E962C76BD4400A0B917 /* AppDelegate.swift */; };
416E9E992C76BD4400A0B917 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 416E9E982C76BD4400A0B917 /* SceneDelegate.swift */; };
416E9E9B2C76BD4400A0B917 /* AppStartViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 416E9E9A2C76BD4400A0B917 /* AppStartViewController.swift */; };
Expand All @@ -40,6 +40,8 @@
41E9A1C12C7CE30000EDE131 /* AppSettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 41E9A1C02C7CE30000EDE131 /* AppSettingsView.swift */; };
E62B3CD72C99EA020098B607 /* StripeCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E62B3CD62C99EA020098B607 /* StripeCore.framework */; };
E62B3CD82C99EA020098B607 /* StripeCore.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = E62B3CD62C99EA020098B607 /* StripeCore.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
E6C5E52B2CA76B0F0021444D /* PresentationSettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E6C5E52A2CA76B030021444D /* PresentationSettingsView.swift */; };
E6C5E52D2CA771730021444D /* PresentationSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = E6C5E52C2CA771700021444D /* PresentationSettings.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -75,10 +77,10 @@
413D18412C7FA30A0051AA42 /* TextInput.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextInput.swift; sourceTree = "<group>"; };
413D18432C7FAE280051AA42 /* OptionListRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OptionListRow.swift; sourceTree = "<group>"; };
413D18492C7FCE5E0051AA42 /* StripeConnectExample.xctestplan */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = StripeConnectExample.xctestplan; sourceTree = "<group>"; };
4161C2882CA1B438005BD67C /* StripeUICore.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = StripeUICore.framework; sourceTree = BUILT_PRODUCTS_DIR; };
4161C2812C9DBB92005BD67C /* OnboardingSettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OnboardingSettingsView.swift; sourceTree = "<group>"; };
4161C2842C9DC235005BD67C /* OnboardingSettings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OnboardingSettings.swift; sourceTree = "<group>"; };
4161C2862C9DD035005BD67C /* URL+Valid.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "URL+Valid.swift"; sourceTree = "<group>"; };
4161C2882CA1B438005BD67C /* StripeUICore.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = StripeUICore.framework; sourceTree = BUILT_PRODUCTS_DIR; };
416E9E932C76BD4400A0B917 /* StripeConnect Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "StripeConnect Example.app"; sourceTree = BUILT_PRODUCTS_DIR; };
416E9E962C76BD4400A0B917 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
416E9E982C76BD4400A0B917 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
Expand All @@ -102,6 +104,8 @@
41E9A1BE2C7CD3C700EDE131 /* UIViewController+NavigationEmbed.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIViewController+NavigationEmbed.swift"; sourceTree = "<group>"; };
41E9A1C02C7CE30000EDE131 /* AppSettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppSettingsView.swift; sourceTree = "<group>"; };
E62B3CD62C99EA020098B607 /* StripeCore.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = StripeCore.framework; sourceTree = BUILT_PRODUCTS_DIR; };
E6C5E52A2CA76B030021444D /* PresentationSettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PresentationSettingsView.swift; sourceTree = "<group>"; };
E6C5E52C2CA771700021444D /* PresentationSettings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PresentationSettings.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -147,8 +151,9 @@
4161C27F2C9DBB70005BD67C /* Settings */ = {
isa = PBXGroup;
children = (
4161C2802C9DBB7E005BD67C /* Components */,
41E9A1C02C7CE30000EDE131 /* AppSettingsView.swift */,
4161C2802C9DBB7E005BD67C /* Components */,
E6C5E5272CA76AD20021444D /* PresentationSettings */,
41810D742C8A004F00F10EB7 /* Appearance */,
);
path = Settings;
Expand Down Expand Up @@ -292,6 +297,15 @@
path = Helpers;
sourceTree = "<group>";
};
E6C5E5272CA76AD20021444D /* PresentationSettings */ = {
isa = PBXGroup;
children = (
E6C5E52C2CA771700021444D /* PresentationSettings.swift */,
E6C5E52A2CA76B030021444D /* PresentationSettingsView.swift */,
);
path = PresentationSettings;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand Down Expand Up @@ -405,13 +419,15 @@
41E9A1C12C7CE30000EDE131 /* AppSettingsView.swift in Sources */,
416E9ED62C78BD9900A0B917 /* API.swift in Sources */,
416E9E992C76BD4400A0B917 /* SceneDelegate.swift in Sources */,
E6C5E52D2CA771730021444D /* PresentationSettings.swift in Sources */,
4161C2822C9DBB92005BD67C /* OnboardingSettingsView.swift in Sources */,
416E9EDA2C78BDC300A0B917 /* AccountSessionResponse.swift in Sources */,
416E9EE32C7B988100A0B917 /* AppSettings.swift in Sources */,
416E9EDC2C78BE1300A0B917 /* APIError.swift in Sources */,
413D18422C7FA30A0051AA42 /* TextInput.swift in Sources */,
41E9A1BD2C7CC85100EDE131 /* SwiftUIContainerViewController.swift in Sources */,
4161C2852C9DC235005BD67C /* OnboardingSettings.swift in Sources */,
E6C5E52B2CA76B0F0021444D /* PresentationSettingsView.swift in Sources */,
416E9EDE2C78C0BA00A0B917 /* AppInfo.swift in Sources */,
41810D762C8A005D00F10EB7 /* AppearanceInfo.swift in Sources */,
41810D712C89F4CD00F10EB7 /* AppearanceSettings.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,38 +26,39 @@ class MainViewController: UITableViewController {

/// Rows that display inside this table
enum Row: String, CaseIterable {
case onboarding = "Onboarding"
case onboarding = "Account onboarding"
case payouts = "Payouts"

var label: String { rawValue }

var accessoryType: UITableViewCell.AccessoryType {
.disclosureIndicator
var attributedLabel: NSAttributedString {
let attributeString = NSMutableAttributedString(
string: label,
attributes: [
.font: UIFont.boldSystemFont(ofSize: UIFont.preferredFont(forTextStyle: .body).pointSize),
]
)
if isBeta {
attributeString.append(NSAttributedString(
string: " Beta",
attributes: [
.font: UIFont.preferredFont(forTextStyle: .footnote),
.foregroundColor: UIColor.secondaryLabel,
]
))
}
return attributeString
}

var labelColor: UIColor {
return .label
}
}
var isBeta: Bool { true }

/// Navbar button title view
lazy var navbarTitleButton: UIButton = {
let button = UIButton(type: .system)
button.setTitle(title, for: .normal)
button.setImage(UIImage(systemName: "chevron.down",
withConfiguration: UIImage.SymbolConfiguration(pointSize: 10)),
for: .normal)
button.semanticContentAttribute = .forceRightToLeft
button.tintColor = .label
button.addTarget(self, action: #selector(presentServerSettings), for: .touchUpInside)
button.titleLabel?.adjustsFontSizeToFitWidth = true
button.accessibilityLabel = "Configure server"
return button
}()

override var title: String? {
didSet {
navbarTitleButton.setTitle(title, for: .normal)
var detailText: String {
switch self {
case .onboarding:
return "Show a localized onboarding form that validates data."
case .payouts:
return "Show payout information and allow your users to perform payouts."
}
}
}

Expand All @@ -76,9 +77,16 @@ class MainViewController: UITableViewController {

override func viewDidLoad() {
super.viewDidLoad()
title = merchant.displayName ?? merchant.merchantId
navigationItem.titleView = navbarTitleButton
title = merchant.displayName.map { "Demo account: \($0)" } ?? merchant.merchantId
navigationController?.delegate = self
addChangeAppearanceButtonNavigationItem(to: self)

navigationItem.leftBarButtonItem = .init(
image: UIImage(systemName: "gearshape.fill"),
style: .plain,
target: self,
action: #selector(presentServerSettings)
)
}

func addChangeAppearanceButtonNavigationItem(to viewController: UIViewController) {
Expand All @@ -102,24 +110,57 @@ class MainViewController: UITableViewController {

/// Called when table row is selected
func performAction(_ row: Row, cell: UITableViewCell) {
let viewControllerToPush: UIViewController
var viewControllerToPresent: UIViewController

// Create a view controller for the selected component
switch row {
case .onboarding:
let savedOnboardingSettings = AppSettings.shared.onboardingSettings
viewControllerToPush = embeddedComponentManager.createAccountOnboardingViewController(
viewControllerToPresent = embeddedComponentManager.createAccountOnboardingViewController(
fullTermsOfServiceUrl: savedOnboardingSettings.fullTermsOfServiceUrl,
recipientTermsOfServiceUrl: savedOnboardingSettings.recipientTermsOfServiceUrl,
privacyPolicyUrl: savedOnboardingSettings.privacyPolicyUrl,
skipTermsOfServiceCollection: savedOnboardingSettings.skipTermsOfService.boolValue,
collectionOptions: savedOnboardingSettings.accountCollectionOptions)
case .payouts:
viewControllerToPush = embeddedComponentManager.createPayoutsViewController()
viewControllerToPresent = embeddedComponentManager.createPayoutsViewController()
}

viewControllerToPush.navigationItem.backButtonDisplayMode = .minimal
addChangeAppearanceButtonNavigationItem(to: viewControllerToPush)
navigationController?.pushViewController(viewControllerToPush, animated: true)
// Fetch ViewController presentation settings
let presentationSettings = AppSettings.shared.presentationSettings

if presentationSettings.embedInTabBar {
// Embed in a tab bar
let tabBarController = UITabBarController()
viewControllerToPresent.tabBarItem = .init(title: row.label, image: UIImage(systemName: "star"), tag: 0)

tabBarController.viewControllers = [viewControllerToPresent]

viewControllerToPresent = tabBarController
}

// Configure the component VC's navbar
viewControllerToPresent.navigationItem.backButtonDisplayMode = .minimal
addChangeAppearanceButtonNavigationItem(to: viewControllerToPresent)
viewControllerToPresent.title = row.label

if presentationSettings.presentationStyleIsPush {
// Push to navigation stack
navigationController?.pushViewController(viewControllerToPresent, animated: true)
} else {
// Modally present

// Add a close button
viewControllerToPresent.navigationItem.leftBarButtonItem = .init(systemItem: .close, primaryAction: .init(handler: { [weak viewControllerToPresent] _ in
viewControllerToPresent?.dismiss(animated: true)
}))

if presentationSettings.embedInNavBar {
// Embed inside a navbar
viewControllerToPresent = UINavigationController(rootViewController: viewControllerToPresent)
}
present(viewControllerToPresent, animated: true)
}
}

// MARK: - UITableViewDataSource
Expand All @@ -130,10 +171,11 @@ class MainViewController: UITableViewController {

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let row = Row.allCases[indexPath.row]
let cell = UITableViewCell()
cell.textLabel?.text = row.label
cell.textLabel?.textColor = row.labelColor
cell.accessoryType = row.accessoryType
let cell = UITableViewCell(style: .subtitle, reuseIdentifier: nil)
cell.textLabel?.attributedText = row.attributedLabel
cell.detailTextLabel?.text = row.detailText
cell.detailTextLabel?.numberOfLines = 0
cell.accessoryType = .disclosureIndicator
return cell
}

Expand Down Expand Up @@ -195,3 +237,35 @@ class MainViewController: UITableViewController {
return fontSources
}
}

extension MainViewController: UINavigationControllerDelegate {
func navigationController(_ navigationController: UINavigationController, willShow viewController: UIViewController, animated: Bool) {

// Hide the navbar on the component VC if it's disabled in presentation settings

navigationController.isNavigationBarHidden = !AppSettings.shared.presentationSettings.embedInNavBar && viewController != self

if navigationController.isNavigationBarHidden {

// Add floating back button so we can still navigate back

let backButton = UIButton(
type: .system,
primaryAction: UIAction(
title: "Back",
image: UIImage(systemName: "chevron.backward"),
handler: { _ in
navigationController.popViewController(animated: true)
}
))
backButton.backgroundColor = .systemBackground.withAlphaComponent(0.5)
backButton.layer.cornerRadius = 4
backButton.translatesAutoresizingMaskIntoConstraints = false
viewController.view.addSubview(backButton)
NSLayoutConstraint.activate([
backButton.topAnchor.constraint(equalTo: viewController.view.safeAreaLayoutGuide.topAnchor, constant: 20),
backButton.leadingAnchor.constraint(equalTo: viewController.view.safeAreaLayoutGuide.leadingAnchor, constant: 20),
])
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ struct AppSettingsView: View {
@State var selectedMerchant: MerchantInfo?
@State var serverURLString: String = AppSettings.shared.selectedServerBaseURL
@State var onboardingSettings = AppSettings.shared.onboardingSettings
@State var presentationSettings = AppSettings.shared.presentationSettings

var isCustomEndpointValid: Bool {
URL(string: serverURLString)?.isValid == true
Expand Down Expand Up @@ -98,13 +99,22 @@ struct AppSettingsView: View {
NavigationLink {
OnboardingSettingsView(onboardingSettings: $onboardingSettings)
} label: {
Text("Onboarding")
Text("Account onboarding")
.font(.body)
.foregroundColor(.primary)
}
} header: {
Text("Component Settings")
}

NavigationLink {
PresentationSettingsView(presentationSettings: $presentationSettings)
} label: {
Text("View Controller Options")
.font(.body)
.foregroundColor(.primary)
}

Section {
TextInput(label: "", placeholder: "https://example.com", text: $serverURLString, isValid: isCustomEndpointValid)
Button {
Expand All @@ -122,7 +132,7 @@ struct AppSettingsView: View {
.animation(.easeOut(duration: 0.2), value: selectedMerchant)
.autocorrectionDisabled()
.textInputAutocapitalization(.never)
.navigationTitle("Configure server")
.navigationTitle("Settings")
.navigationBarTitleDisplayMode(.inline)
.toolbar {
ToolbarItem(placement: .navigationBarLeading) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//
// PresentationSettings.swift
// StripeConnect Example
//
// Created by Mel Ludowise on 9/27/24.
//

struct PresentationSettings: Equatable {
var presentationStyleIsPush: Bool
var embedInTabBar: Bool
var embedInNavBar: Bool
}
Loading

0 comments on commit e4a473f

Please sign in to comment.