Skip to content

Instantly share code, notes, and snippets.

@evansunleyjames
Last active June 6, 2024 16:20
Show Gist options
  • Save evansunleyjames/00b804ea8cec001154c643540c3563f4 to your computer and use it in GitHub Desktop.
Save evansunleyjames/00b804ea8cec001154c643540c3563f4 to your computer and use it in GitHub Desktop.
A tip for showing TipKit tips conditionally in SwiftUI
/**
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