Skip to content
Merged
Show file tree
Hide file tree
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
20 changes: 19 additions & 1 deletion Sources/FuturedArchitecture/Architecture/Alert/AlertModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,23 @@ public struct AlertModel: Identifiable {
}
}

public struct TextField {
let title: String
let text: Binding<String>

public init(title: String, text: Binding<String>) {
self.title = title
self.text = text
}
}

public var id: String? {
title + (message ?? "")
}

let title: String
let message: String?
let textField: TextField?
let primaryAction: ButtonAction?
let secondaryAction: ButtonAction?

Expand All @@ -78,9 +89,16 @@ public struct AlertModel: Identifiable {
/// - primaryAction: The specification of the alert primary action.
/// - secondaryAction: The specification of the alert secondary action.

public init(title: String, message: String?, primaryAction: ButtonAction? = nil, secondaryAction: ButtonAction? = nil) {
public init(
title: String,
message: String?,
textField: TextField? = nil,
primaryAction: ButtonAction? = nil,
secondaryAction: ButtonAction? = nil
) {
self.title = title
self.message = message
self.textField = textField
self.primaryAction = primaryAction
self.secondaryAction = secondaryAction
}
Expand Down
18 changes: 10 additions & 8 deletions Sources/FuturedArchitecture/Architecture/Alert/AlertModifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,22 @@ private struct AlertModifier: ViewModifier {
),
presenting: model,
actions: { model in
if let textField = model.textField {
TextField(textField.title, text: textField.text)
}
if let primaryAction = model.primaryAction {
Button(
primaryAction.title,
role: primaryAction.buttonRole,
action: primaryAction.action
)

if let secondaryAction = model.secondaryAction {
Button(
secondaryAction.title,
role: secondaryAction.buttonRole,
action: secondaryAction.action
)
}
}
if let secondaryAction = model.secondaryAction {
Button(
secondaryAction.title,
role: secondaryAction.buttonRole,
action: secondaryAction.action
)
}
},
message: { model in
Expand Down
Loading