Opens Error Log upon tapping ToastView showing logged error

This commit is contained in:
Riley Testut
2022-10-26 16:46:21 -05:00
parent 17f28439fe
commit 42d433a11d
7 changed files with 68 additions and 0 deletions

View File

@@ -16,10 +16,17 @@ extension TimeInterval
static let longToastViewDuration = 8.0
}
extension ToastView
{
static let openErrorLogNotification = Notification.Name("ALTOpenErrorLogNotification")
}
class ToastView: RSTToastView
{
var preferredDuration: TimeInterval
var opensErrorLog: Bool = false
override init(text: String, detailText detailedText: String?)
{
if detailedText == nil
@@ -43,7 +50,10 @@ class ToastView: RSTToastView
// RSTToastView does not expose stack view containing labels,
// so we access it indirectly as the labels' superview.
stackView.spacing = (detailedText != nil) ? 4.0 : 0.0
stackView.alignment = .leading
}
self.addTarget(self, action: #selector(ToastView.showErrorLog), for: .touchUpInside)
}
convenience init(error: Error)
@@ -99,6 +109,23 @@ class ToastView: RSTToastView
override func show(in view: UIView, duration: TimeInterval)
{
if self.opensErrorLog, #available(iOS 13, *),
case let configuration = UIImage.SymbolConfiguration(font: self.textLabel.font),
let icon = UIImage(systemName: "chevron.right.circle", withConfiguration: configuration)
{
let tintedIcon = icon.withTintColor(.white, renderingMode: .alwaysOriginal)
let moreIconImageView = UIImageView(image: tintedIcon)
moreIconImageView.translatesAutoresizingMaskIntoConstraints = false
self.addSubview(moreIconImageView)
NSLayoutConstraint.activate([
moreIconImageView.trailingAnchor.constraint(equalTo: self.trailingAnchor, constant: -self.layoutMargins.right),
moreIconImageView.centerYAnchor.constraint(equalTo: self.textLabel.centerYAnchor),
moreIconImageView.leadingAnchor.constraint(greaterThanOrEqualToSystemSpacingAfter: self.textLabel.trailingAnchor, multiplier: 1.0)
])
}
super.show(in: view, duration: duration)
let announcement = (self.textLabel.text ?? "") + ". " + (self.detailTextLabel.text ?? "")
@@ -115,3 +142,13 @@ class ToastView: RSTToastView
self.show(in: view, duration: self.preferredDuration)
}
}
private extension ToastView
{
@objc func showErrorLog()
{
guard self.opensErrorLog else { return }
NotificationCenter.default.post(name: ToastView.openErrorLogNotification, object: self)
}
}