Reputation: 1478
I have custom view with different content inside including Button.
For example:
VStack {
Text("Some text")
Button() // 1-th
Button() // 2-th
.disabled(false) // This doesn't help, despite it logical
}
.disabled(true) // Line with disabling
I want 2-th button to be always enabled no matter what is set in "Line with disabling".
Upvotes: 0
Views: 343
Reputation: 84
And what do you think about this:
VStack {
Text("Some text")
Button(action: {
print("Button Action 1")
}, label: {
Text("Button 1")
})
Button(action: {
print("Button Action 1")
}, label: {
Text("Button 1")
})
.environment(\.isEnabled, true)
}
.disabled(true)
Based on SwiftUI Documentation:
You can set or override some values using the environment(::) view modifier:
MyView()
.environment(\.lineLimit, 2)
So why couldn't you override .environment(\.isEnabled, true)
like in example above? It works like a charm, but I have no idea what problems or other shortcomings it could cause when using it.
Upvotes: 1
Reputation: 7754
According to the documentation this does not work that way. It works the other way around. As you allready discovered the .disable
on the parent overrides the value set in the child.
Possible solution would be to not use the parent .disable
instead use it on each child element.
Upvotes: 3