mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 06:55:59 +00:00
Move AlertInfo's button types out of the generic type
With Swift 6.4, the default value for AlertInfo.primaryButton warned that T's Hashable conformance may be isolated and can't be used in a main actor-isolated context. The nested AlertButton/AlertTextField types don't depend on T, so move them to top level as AlertInfoButton and AlertInfoTextField, and keep typealiases so existing call sites compile. Constraining T to SendableMetatype isn't possible as the synthesized Hashable conformances of our main actor-isolated alert enums are isolated.
This commit is contained in:
@@ -45,20 +45,10 @@ extension View {
|
|||||||
/// .alert(item: $context.alertInfo)
|
/// .alert(item: $context.alertInfo)
|
||||||
/// ```
|
/// ```
|
||||||
struct AlertInfo<T: Hashable>: Identifiable, AlertProtocol {
|
struct AlertInfo<T: Hashable>: Identifiable, AlertProtocol {
|
||||||
struct AlertButton: Identifiable {
|
// The button types live outside this generic type, otherwise the default
|
||||||
let id = UUID()
|
// primaryButton would need T's (possibly isolated) Hashable conformance.
|
||||||
let title: String
|
typealias AlertButton = AlertInfoButton
|
||||||
var role: ButtonRole?
|
typealias AlertTextField = AlertInfoTextField
|
||||||
let action: (() -> Void)?
|
|
||||||
}
|
|
||||||
|
|
||||||
struct AlertTextField: Identifiable {
|
|
||||||
let id = UUID()
|
|
||||||
let placeholder: String
|
|
||||||
let text: Binding<String>
|
|
||||||
let autoCapitalization: TextInputAutocapitalization
|
|
||||||
let autoCorrectionDisabled: Bool
|
|
||||||
}
|
|
||||||
|
|
||||||
/// An identifier that can be used to distinguish one error from another.
|
/// An identifier that can be used to distinguish one error from another.
|
||||||
let id: T
|
let id: T
|
||||||
@@ -99,6 +89,21 @@ extension AlertInfo {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct AlertInfoButton: Identifiable {
|
||||||
|
let id = UUID()
|
||||||
|
let title: String
|
||||||
|
var role: ButtonRole?
|
||||||
|
let action: (() -> Void)?
|
||||||
|
}
|
||||||
|
|
||||||
|
struct AlertInfoTextField: Identifiable {
|
||||||
|
let id = UUID()
|
||||||
|
let placeholder: String
|
||||||
|
let text: Binding<String>
|
||||||
|
let autoCapitalization: TextInputAutocapitalization
|
||||||
|
let autoCorrectionDisabled: Bool
|
||||||
|
}
|
||||||
|
|
||||||
extension View {
|
extension View {
|
||||||
func alert<T: Hashable>(item: Binding<AlertInfo<T>?>) -> some View {
|
func alert<T: Hashable>(item: Binding<AlertInfo<T>?>) -> some View {
|
||||||
alert(item: item) { item in
|
alert(item: item) { item in
|
||||||
|
|||||||
Reference in New Issue
Block a user