[ad_1]
I am constructing a CustomTextField View and wanting so as to add view modifiers.
Utilizing the usual .modifier(CustomViewModifier) is working simply high-quality. Now I wish to construct ViewModifier capabilities in order that I can use my modifiers similar to some other SwiftUI modifiers.
In my CustomTextField, I’ve acquired a number of strategies like this:
func setCustomPlaceholder(placeholder: String = "Enter Textual content") -> some View {
modifier(CustomTextFieldPlaceholderViewModifier(viewModel: viewModel, placeholder: placeholder))
}
These strategies work. Nonetheless, I can solely use one among these strategies at a time.
I’ve learn a number of articles and this thread. As a result of I do not need these modifiers accessible to any View, I would prefer to keep away from utilizing an extension to View.
In this thread, one of many solutions used an extension to Textual content. So I attempted putting my modifier strategies into an extension to my CustomTextField. Nonetheless, I am nonetheless going through the identical concern. The View is barely recognizing one modifier operate at a time.
That is how I am utilizing it:
VStack {
CustomTextField()
.setCustomPlaceholder()
.setBorder()
}
If I exploit solely one of many modifier strategies at a time, it really works.
How can I get the performance I am searching for? Do I have to construct a Protocol and make my CustomTextField conform to it? Thanks for any assist!
[ad_2]
