feat: Resolving concurrency warnings
This commit is contained in:
@@ -1,15 +1,16 @@
|
||||
import SwiftUI
|
||||
|
||||
@MainActor
|
||||
public protocol TextLabelStyle {
|
||||
|
||||
associatedtype Body: View
|
||||
typealias Configuration = TextLabelConfiguration
|
||||
|
||||
@MainActor
|
||||
func makeBody(configuration: Self.Configuration) -> Self.Body
|
||||
}
|
||||
|
||||
extension TextLabelStyle {
|
||||
@MainActor
|
||||
public func combining<Other: TextLabelStyle>(_ style: Other) -> AnyTextLabelStyle {
|
||||
AnyTextLabelStyle(style: self).combining(style)
|
||||
}
|
||||
@@ -31,7 +32,7 @@ public struct TextLabelConfiguration {
|
||||
|
||||
@MainActor
|
||||
public struct AnyTextLabelStyle: TextLabelStyle {
|
||||
private var _makeBody: (Configuration) -> AnyView
|
||||
private let _makeBody: (Configuration) -> AnyView
|
||||
|
||||
internal init(makeBody: @escaping (Configuration) -> AnyView) {
|
||||
self._makeBody = makeBody
|
||||
@@ -59,22 +60,28 @@ public struct AnyTextLabelStyle: TextLabelStyle {
|
||||
}
|
||||
}
|
||||
|
||||
@MainActor
|
||||
public struct AutomaticTextLabelStyle: TextLabelStyle {
|
||||
@MainActor
|
||||
public func makeBody(configuration: Configuration) -> some View {
|
||||
configuration.label
|
||||
}
|
||||
}
|
||||
|
||||
private struct TextLabelStyleKey: EnvironmentKey {
|
||||
static let defaultValue = AnyTextLabelStyle(style: AutomaticTextLabelStyle())
|
||||
static let defaultValue = MainActor.assumeIsolated {
|
||||
AnyTextLabelStyle(style: AutomaticTextLabelStyle())
|
||||
}
|
||||
}
|
||||
|
||||
private struct SectionHeaderLabelStyleKey: EnvironmentKey {
|
||||
static let defaultValue = AnyTextLabelStyle(style: AutomaticTextLabelStyle())
|
||||
static let defaultValue = MainActor.assumeIsolated {
|
||||
AnyTextLabelStyle(style: AutomaticTextLabelStyle())
|
||||
}
|
||||
}
|
||||
|
||||
extension EnvironmentValues {
|
||||
|
||||
|
||||
public var textLabelStyle: AnyTextLabelStyle {
|
||||
get { self[TextLabelStyleKey.self] }
|
||||
set { self[TextLabelStyleKey.self] = newValue }
|
||||
@@ -117,6 +124,7 @@ public struct ColoredTextLabelStyle: TextLabelStyle {
|
||||
}
|
||||
}
|
||||
|
||||
@MainActor
|
||||
public func font(_ font: Font? = nil, fontWeight: Font.Weight? = nil) -> AnyTextLabelStyle {
|
||||
self.combining(.font(font, fontWeight: fontWeight))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user