Action history is logged and displayed to the user's library. These are triggered whenever the magnet choice sheet is displayed. Also redo alerts and action sheets to avoid deprecation notices for >iOS 14. These will be removed when iOS 14 support is dropped. There was also a problem with sheet presentation not working after a sheet was dismissed. Disable the appropriate view when a sheet is being presented. Signed-off-by: kingbri <bdashore3@proton.me>
56 lines
1.7 KiB
Swift
56 lines
1.7 KiB
Swift
//
|
|
// DynamicAlert.swift
|
|
// Ferrite
|
|
//
|
|
// Created by Brian Dashore on 9/8/22.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
struct DynamicAlert: ViewModifier {
|
|
@Binding var isPresented: Bool
|
|
|
|
let title: String
|
|
let message: String?
|
|
let buttons: [AlertButton]
|
|
|
|
func body(content: Content) -> some View {
|
|
if #available(iOS 15, *) {
|
|
content
|
|
.alert(
|
|
title,
|
|
isPresented: $isPresented,
|
|
actions: {
|
|
ForEach(buttons) { button in
|
|
button.toButtonView()
|
|
}
|
|
},
|
|
message: {
|
|
if let message = message {
|
|
Text(message)
|
|
}
|
|
}
|
|
)
|
|
} else {
|
|
content
|
|
.alert(isPresented: $isPresented) {
|
|
if let primaryButton = buttons[safe: 0],
|
|
let secondaryButton = buttons[safe: 1]
|
|
{
|
|
return Alert(
|
|
title: Text(title),
|
|
message: message.map { Text($0) } ?? nil,
|
|
primaryButton: primaryButton.toActionButton(),
|
|
secondaryButton: secondaryButton.toActionButton()
|
|
)
|
|
} else {
|
|
return Alert(
|
|
title: Text(title),
|
|
message: message.map { Text($0) } ?? nil,
|
|
dismissButton: buttons[0].toActionButton()
|
|
)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|