Skip to content

Commit

Permalink
Fix crash on showing alert for in-app purchase
Browse files Browse the repository at this point in the history
  • Loading branch information
mojganii committed Jan 22, 2025
1 parent 8c94061 commit a8fb7eb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion ios/MullvadVPN/Coordinators/LocationCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ extension LocationCoordinator: @preconcurrency LocationViewControllerWrapperDele
preferredStyle: UIDevice.current.userInterfaceIdiom == .pad ? .alert : .actionSheet
)
actionSheet.overrideUserInterfaceStyle = .dark
actionSheet.view.tintColor = UIColor(red: 0.0, green: 0.59, blue: 1.0, alpha: 1)
actionSheet.view.tintColor = .AlertController.tintColor

let addCustomListAction = UIAlertAction(
title: NSLocalizedString(
Expand Down
16 changes: 11 additions & 5 deletions ios/MullvadVPN/Extensions/UIAlertController+InAppPurchase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,26 @@ extension UIAlertController {
value: "Add Time",
comment: ""
)
let alert = UIAlertController(title: localizedString, message: nil, preferredStyle: .actionSheet)
let actionSheet = UIAlertController(
title: localizedString,
message: nil,
preferredStyle: UIDevice.current.userInterfaceIdiom == .pad ? .alert : .actionSheet
)
actionSheet.overrideUserInterfaceStyle = .dark
actionSheet.view.tintColor = .AlertController.tintColor
products.sortedByPrice().forEach { product in
guard let localizedTitle = product.customLocalizedTitle else {
return
}
let action = UIAlertAction(title: localizedTitle, style: .default, handler: { _ in
alert.dismiss(animated: true, completion: {
actionSheet.dismiss(animated: true, completion: {
didRequestPurchase(product)
})
})
action
.accessibilityIdentifier =
"\(AccessibilityIdentifier.purchaseButton.asString)_\(product.productIdentifier)"
alert.addAction(action)
actionSheet.addAction(action)
}
let cancelAction = UIAlertAction(title: NSLocalizedString(
"PRODUCT_LIST_CANCEL_BUTTON",
Expand All @@ -42,7 +48,7 @@ extension UIAlertController {
comment: ""
), style: .cancel)
cancelAction.accessibilityIdentifier = AccessibilityIdentifier.cancelPurchaseListButton.asString
alert.addAction(cancelAction)
return alert
actionSheet.addAction(cancelAction)
return actionSheet
}
}
4 changes: 4 additions & 0 deletions ios/MullvadVPN/UI appearance/UIColor+Palette.swift
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ extension UIColor {
static let selectedColor = successColor
}

enum AlertController {
static let tintColor = UIColor(red: 0.0, green: 0.59, blue: 1.0, alpha: 1)
}

// Common colors
static let primaryColor = UIColor(red: 0.16, green: 0.30, blue: 0.45, alpha: 1.0)
static let secondaryColor = UIColor(red: 0.10, green: 0.18, blue: 0.27, alpha: 1.0)
Expand Down

0 comments on commit a8fb7eb

Please sign in to comment.