I want to use the default padding on the trailing edge but only if a condition is true.
It is important for me to use the default padding and not a value so SwiftUI can set it for me.
This is my current setup using a ternary operator:
MyView()
.padding(condition ? .trailing : /* what here?*/)
using nil or .none do not work and will give me an error
Any Ideas?
>Solution :
The documentation for padding’s length parameter says: “If you set the value to nil, SwiftUI uses a platform-specific default amount.”
So you can always specify a trailing padding but set the length to nil to get the default and to 0 for no padding:
MyView()
.padding(.trailing, condition ? nil : 0)