Last active
June 6, 2024 16:20
-
-
Save evansunleyjames/00b804ea8cec001154c643540c3563f4 to your computer and use it in GitHub Desktop.
A tip for showing TipKit tips conditionally in SwiftUI
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
/** | |
Conditionally include a tip - could be achieved with parameters on the tip, but this could save repetition if there are enough tips that depend on the same condition. | |
Usage: | |
.showTipConditionally(someCondition) { view in | |
view | |
.popoverTip(myTip) | |
.whateverOtherModifiers() | |
} | |
*/ | |
extension View { | |
@ViewBuilder func `showTipConditionally`<Content: View>(_ condition: Bool, modifier: (Self) -> Content) -> some View { | |
if condition { | |
modifier(self) | |
} | |
else { | |
self | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment