Skip to content

Commit

Permalink
fix(GiniHealthSDK): Fix navigation flow
Browse files Browse the repository at this point in the history
IPC-429
  • Loading branch information
razvancapra committed Nov 20, 2024
1 parent 0e31d11 commit bee9b1f
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import UIKit
public enum PaymentComponentScreenType {
case paymentComponent
case bankPicker
case paymentReview
}

public struct PaymentComponentsConfiguration {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//
// UINavigationController.swift
//
// Copyright © 2024 Gini GmbH. All rights reserved.
//

import UIKit

extension UINavigationController {
public func pushViewController(viewController: UIViewController, animated: Bool, completion: @escaping () -> Void) {
pushViewController(viewController, animated: animated)

if animated, let coordinator = transitionCoordinator {
coordinator.animate(alongsideTransition: nil) { _ in
completion()
}
} else {
completion()
}
}

public func popViewController(animated: Bool, completion: @escaping () -> Void) {
popViewController(animated: animated)

if animated, let coordinator = transitionCoordinator {
coordinator.animate(alongsideTransition: nil) { _ in
completion()
}
} else {
completion()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ extension PaymentComponentsController {
- Returns: A configured `UIViewController` for displaying the payment bottom view.
*/
public func paymentViewBottomSheet(documentId: String?) -> UIViewController {
previousPresentedView = .paymentComponent
previousPresentedView = [.paymentComponent]
let paymentComponentBottomView = PaymentComponentBottomView(paymentView: paymentView(), bottomSheetConfiguration: configurationProvider.bottomSheetConfiguration)
return paymentComponentBottomView
}
Expand Down Expand Up @@ -150,7 +150,10 @@ extension PaymentComponentsController {
- Returns: A configured `UIViewController` for displaying the bank selection options.
*/
public func bankSelectionBottomSheet() -> UIViewController {
previousPresentedView = .bankPicker
if previousPresentedView.first != .paymentReview {
previousPresentedView.removeAll()
}
previousPresentedView.append(.bankPicker)
let paymentProvidersBottomViewModel = BanksBottomViewModel(paymentProviders: paymentProviders,
selectedPaymentProvider: healthSelectedPaymentProvider,
configuration: configurationProvider.bankSelectionConfiguration,
Expand Down Expand Up @@ -179,7 +182,7 @@ extension PaymentComponentsController {
`GiniHealthError` once the loading process is complete.
*/
func loadPaymentReviewScreenFor(trackingDelegate: GiniHealthTrackingDelegate?, completion: @escaping (UIViewController?, GiniHealthError?) -> Void) {
previousPresentedView = nil
previousPresentedView.append(.paymentReview)
if !GiniHealthConfiguration.shared.useInvoiceWithoutDocument {
guard let documentId else {
completion(nil, nil)
Expand All @@ -205,7 +208,6 @@ extension PaymentComponentsController {
}

private func loadPaymentReviewScreenWithoutDocument(paymentInfo: GiniInternalPaymentSDK.PaymentInfo?, trackingDelegate: GiniHealthTrackingDelegate?, completion: @escaping (UIViewController?, GiniHealthError?) -> Void) {
previousPresentedView = nil
preparePaymentReviewViewController(data: nil, paymentInfo: paymentInfo, completion: completion)
}

Expand Down Expand Up @@ -266,7 +268,7 @@ extension PaymentComponentsController {
- Returns: A configured `BottomSheetViewController` for the app installation process.
*/
public func installAppBottomSheet() -> BottomSheetViewController {
previousPresentedView = nil
previousPresentedView.removeAll()
let installAppBottomViewModel = InstallAppBottomViewModel(selectedPaymentProvider: healthSelectedPaymentProvider,
installAppConfiguration: configurationProvider.installAppConfiguration,
strings: stringsProvider.installAppStrings,
Expand All @@ -289,7 +291,7 @@ extension PaymentComponentsController {
- Returns: A configured `BottomSheetViewController` for sharing invoices.
*/
public func shareInvoiceBottomSheet() -> BottomSheetViewController {
previousPresentedView = nil
previousPresentedView.removeAll()
let shareInvoiceBottomViewModel = ShareInvoiceBottomViewModel(selectedPaymentProvider: healthSelectedPaymentProvider,
configuration: configurationProvider.shareInvoiceConfiguration,
strings: stringsProvider.shareInvoiceStrings,
Expand Down Expand Up @@ -334,12 +336,17 @@ extension PaymentComponentsController {

@objc
private func paymentInfoDissapeared() {
if previousPresentedView == .bankPicker {
didTapOnBankPicker()
} else if previousPresentedView == .paymentComponent {
didTapOnPayButton()
switch previousPresentedView.first {
case .bankPicker:
didTapOnBankPicker(documentId: documentId)
case .paymentComponent:
presentPaymentViewBottomSheet()
case .paymentReview:
didTapOnPayInvoice()
default:
break
}
previousPresentedView = nil
previousPresentedView.removeAll()
}

/// Checks if the payment provider app can be opened based on the selected payment provider and GPC(Gini Pay Connect) support.
Expand Down Expand Up @@ -612,9 +619,23 @@ extension PaymentComponentsController: PaymentComponentViewProtocol {
}

private func pushOrDismissAndPush(_ viewController: UIViewController) {
if let presentedVC = navigationControllerProvided?.presentedViewController {
if let doublePresentedVC = navigationControllerProvided?.presentedViewController?.presentedViewController {
doublePresentedVC.dismiss(animated: true) { [weak self] in
if let presentedVC = self?.navigationControllerProvided?.presentedViewController {
presentedVC.dismiss(animated: true) { [weak self] in
self?.navigationControllerProvided?.pushViewController(viewController, animated: true)
}
}
}
} else if let presentedVC = navigationControllerProvided?.presentedViewController {
presentedVC.dismiss(animated: true) { [weak self] in
self?.navigationControllerProvided?.pushViewController(viewController, animated: true)
if self?.navigationControllerProvided?.viewControllers.last is PaymentReviewViewController {
self?.navigationControllerProvided?.popViewController(animated: true, completion: {
self?.navigationControllerProvided?.pushViewController(viewController, animated: true)
})
} else {
self?.navigationControllerProvided?.pushViewController(viewController, animated: true)
}
}
} else {
navigationControllerProvided?.pushViewController(viewController, animated: true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public final class PaymentComponentsController: BottomSheetsProviderProtocol, Gi
}

/// Previous presented view
var previousPresentedView: PaymentComponentScreenType?
var previousPresentedView: [PaymentComponentScreenType] = []
// Client's navigation controller provided in order to handle all HealthSDK flows
weak var navigationControllerProvided: UINavigationController?
// Payment Information from the invoice that contains a document or not
Expand Down

0 comments on commit bee9b1f

Please sign in to comment.