Skip to content

Commit

Permalink
Merge pull request #324 from tangem/IOS-4741-app-change-ui-alert-cont…
Browse files Browse the repository at this point in the history
…roller-tint

IOS-4741 Added the ability to set the tint of the UIAlertController popups
  • Loading branch information
megakoko authored Oct 3, 2023
2 parents d765cc6 + 0bb86f5 commit 80fd179
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
6 changes: 6 additions & 0 deletions TangemSdk/TangemSdk/UI/Main/DefaultSessionViewDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,12 @@ extension DefaultSessionViewDelegate: SessionViewDelegate {
let title = TangemSdkError.cardVerificationFailed.localizedDescription
let message = isDevelopmentCard ? "attestation_failed_dev_card".localized
: "attestation_failed_card".localized
let tint = style.colors.tintUIColor

runInMainThread(UIAlertController.showShouldContinue(from: screen,
title: title,
message: message,
tint: tint,
onContinue: onContinue,
onCancel: onCancel))
}
Expand All @@ -121,10 +123,12 @@ extension DefaultSessionViewDelegate: SessionViewDelegate {

let title = "attestation_online_failed_title".localized
let message = "attestation_online_failed_body".localized
let tint = style.colors.tintUIColor

runInMainThread(UIAlertController.showShouldContinue(from: screen,
title: title,
message: message,
tint: tint,
onContinue: onContinue,
onCancel: onCancel,
onRetry: onRetry))
Expand All @@ -139,9 +143,11 @@ extension DefaultSessionViewDelegate: SessionViewDelegate {

let title = "common_warning".localized
let message = "attestation_warning_attest_wallets".localized
let tint = style.colors.tintUIColor
runInMainThread(UIAlertController.showAlert(from: screen,
title: title,
message: message,
tint: tint,
onContinue: onContinue))
}
}
9 changes: 6 additions & 3 deletions TangemSdk/TangemSdk/UI/Main/SessionViewDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,24 +59,27 @@ public enum SessionViewState {

@available(iOS 13.0, *)
extension UIAlertController {
static func showShouldContinue(from controller: UIViewController, title: String, message: String, onContinue: @escaping () -> Void, onCancel: @escaping () -> Void) {
static func showShouldContinue(from controller: UIViewController, title: String, message: String, tint: UIColor, onContinue: @escaping () -> Void, onCancel: @escaping () -> Void) {
let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "common_understand".localized, style: .destructive) { _ in onContinue() })
alert.addAction(UIAlertAction(title: "common_cancel".localized, style: .cancel) { _ in onCancel() } )
alert.view.tintColor = tint
controller.present(alert, animated: true)
}

static func showShouldContinue(from controller: UIViewController, title: String, message: String, onContinue: @escaping () -> Void, onCancel: @escaping () -> Void, onRetry: @escaping () -> Void) {
static func showShouldContinue(from controller: UIViewController, title: String, message: String, tint: UIColor, onContinue: @escaping () -> Void, onCancel: @escaping () -> Void, onRetry: @escaping () -> Void) {
let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "common_understand".localized, style: .destructive) { _ in onContinue() })
alert.addAction(UIAlertAction(title: "common_retry".localized, style: .default) { _ in onRetry() })
alert.addAction(UIAlertAction(title: "common_cancel".localized, style: .cancel) { _ in onCancel() } )
alert.view.tintColor = tint
controller.present(alert, animated: true)
}

static func showAlert(from controller: UIViewController, title: String, message: String, onContinue: @escaping () -> Void) {
static func showAlert(from controller: UIViewController, title: String, message: String, tint: UIColor, onContinue: @escaping () -> Void) {
let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "common_ok".localized, style: .default) { _ in onContinue() })
alert.view.tintColor = tint
controller.present(alert, animated: true)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@ final class ResetCodesViewDelegate: BaseViewDelegate {
func showError(_ error: TangemSdkError) {
guard let screen = screen else { return }

let tint = style.colors.tintUIColor
runInMainThread(UIAlertController.showAlert(from: screen,
title: "common_error".localized,
message: error.localizedDescription,
tint: tint,
onContinue: {}))
}

Expand All @@ -56,9 +58,11 @@ final class ResetCodesViewDelegate: BaseViewDelegate {
return
}

let tint = style.colors.tintUIColor
runInMainThread(UIAlertController.showAlert(from: screen,
title: title,
message: message,
tint: tint,
onContinue: onContinue))
}
}
2 changes: 2 additions & 0 deletions TangemSdk/TangemSdk/UI/TangemSdkStyle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ public class TangemSdkStyle: ObservableObject {
@available(iOS 13.0, *)
public extension TangemSdkStyle {
struct Colors {
/// Tint color of the interface. Note that due to the inability to convert SwiftUI.Color to UIKit.UIColor you have to set the two separately
public var tint: Color = .blue
public var tintUIColor: UIColor = .blue

public var errorTint: Color = .red

Expand Down

0 comments on commit 80fd179

Please sign in to comment.