Created
June 7, 2023 16:19
-
-
Save rubencodes/d7b863d1c530ec0272a666c67f924b28 to your computer and use it in GitHub Desktop.
Conditional Modifier Extension
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Example Usage | |
struct ContentView: View { | |
let isRounded: Bool | |
var body: some View { | |
Color.blue | |
.conditionalModifier { view in | |
if isRounded { | |
view.clipShape(Circle()) | |
} else { | |
view | |
} | |
} | |
.padding() | |
} | |
} | |
*/ | |
extension View { | |
@ViewBuilder | |
func conditionalModifier(@ViewBuilder modifier: (_ view: Self) -> some View) -> some View { | |
modifier(self) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment