Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class CheckoutPlatformView: NSObject, FlutterPlatformView {
private let _view: CheckoutContainerView
private weak var paymentViewController: UIViewController?
private var checkout: Checkout?
private var uiMode: String?

private func deinitCheckout() {
guard let pvc = paymentViewController,
Expand Down Expand Up @@ -126,6 +127,10 @@ public class CheckoutPlatformView: NSObject, FlutterPlatformView {
@MainActor
func createNativeView(arguments: CheckoutArguments) {
debugPrint("createNativeView")

// Store uiMode from theme for applying to view controller
self.uiMode = arguments.theme?.uiMode

let theme = getCheckoutTheme(
arguments.theme, showPaymentDetails: arguments.showPaymentDetails)
let formsOfPayment =
Expand Down Expand Up @@ -183,8 +188,11 @@ public class CheckoutPlatformView: NSObject, FlutterPlatformView {

func tryAttachController() {
guard let pvc = self.paymentViewController else { return }

if let parentVC = UIApplication.shared.delegate?.window??.rootViewController as? FlutterViewController {
// Apply uiMode to override system appearance if specified
applyUserInterfaceStyle(to: pvc)

parentVC.addChild(pvc)
_view.addCheckoutView(pvc.view)
pvc.didMove(toParent: parentVC)
Expand All @@ -196,6 +204,23 @@ public class CheckoutPlatformView: NSObject, FlutterPlatformView {
}
}
}

private func applyUserInterfaceStyle(to viewController: UIViewController) {
guard let mode = uiMode?.lowercased() else { return }

let style: UIUserInterfaceStyle
switch mode {
case "light":
style = .light
case "dark":
style = .dark
default:
return // Don't override if not specified or "auto"
}

viewController.overrideUserInterfaceStyle = style
viewController.view.overrideUserInterfaceStyle = style
}

private func getApiTransactionDetails(_ transactionDetails: String) throws
-> TransactionDetailsResponse?
Expand Down