I wish to inject my ViewModifier from a ViewModel which depends upon consumer configuration.
Beneath code is a View which has a ViewModel. ViewModel will be created with ViewConfiguration and consumer ought to be capable of both use a default type or customized type primarily based on preferences.
After I attempt to do that it provides me error on View which says
Kind ‘any ViewModifier’ can’t conform to ‘ViewModifier’
struct FeatureUnavailableView: View {
var viewModel = ViewModel(config: ViewConfiguration(titleStyle: DefaultTitleModifier()))
var physique: some View {
Textual content("Hiya World")
.modifier(viewModel.config.titleStyle)
}
}
class ViewModel {
let config: ViewConfiguration
init(config: ViewConfiguration) {
self.config = config
}
}
struct ViewConfiguration {
var titleStyle: any ViewModifier
}
public struct DefaultTitleModifier: ViewModifier {
public func physique(content material: Content material) -> some View {
content material
.lineLimit(1)
.foregroundColor(.purple)
.daring()
}
}