Skip to content

Commit e1851b2

Browse files
fix: Hide back button in Klarna vc if no stack
1 parent 1e75323 commit e1851b2

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

Sources/PrimerSDK/Classes/Extensions & Utilities/UINavigationController+Extensions.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
import UIKit
88

99
extension UINavigationController {
10+
11+
var canPop: Bool { viewControllers.count > 1 }
12+
1013
func pushViewController(viewController: UIViewController, animated: Bool, completion: (() -> Void)?) {
1114
pushViewController(viewController, animated: animated)
1215

Sources/PrimerSDK/Classes/User Interface/Klarna Categories Sheet/PrimerKlarnaCategoriesViewController.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ extension PrimerKlarnaCategoriesViewController: PrimerHeadlessErrorableDelegate,
171171
switch step {
172172
case .paymentSessionCreated(let clientToken, let paymentCategories):
173173
DispatchQueue.main.async { [weak self] in
174-
guard let self = self else { return }
174+
guard let self else { return }
175175

176176
// If only one payment category is available, skip the selection and continue with the only option
177177
if paymentCategories.count == 1, let onlyPaymentCategory = paymentCategories.first {
@@ -187,7 +187,11 @@ extension PrimerKlarnaCategoriesViewController: PrimerHeadlessErrorableDelegate,
187187

188188
hideLoader()
189189
self.clientToken = clientToken
190-
klarnaCategoriesVM.updatePaymentCategories(paymentCategories)
190+
klarnaCategoriesVM
191+
.updatePaymentCategories(
192+
paymentCategories,
193+
showBackButton: navigationController?.canPop ?? false
194+
)
191195
}
192196

193197
case .paymentSessionFinalizationRequired:

Sources/PrimerSDK/Classes/User Interface/Klarna Categories Sheet/PrimerKlarnaCategoriesViewModel.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@ final class PrimerKlarnaCategoriesViewModel: ObservableObject {
1515
@Published var isAuthorizing: Bool = false
1616
@Published var shouldDisableKlarnaViews: Bool = false
1717

18-
func updatePaymentCategories(_ paymentCategories: [KlarnaPaymentCategory]) {
18+
func updatePaymentCategories(
19+
_ paymentCategories: [KlarnaPaymentCategory],
20+
showBackButton: Bool
21+
) {
1922
self.paymentCategories = paymentCategories
20-
self.showBackButton = true
23+
self.showBackButton = showBackButton
2124
}
2225
}

0 commit comments

Comments
 (0)