The solution from jaredsinclair doesn't work for me. So I modified his solution to make it work.
I like the PopoverTip and want to use it to display details of the data the user taps on. That's why I added generating the displayed text when the button is pressed to the example.
import SwiftUI
import TipKit
struct SomeTip: Tip {
let id: String
let titleString: String
let messageString: String
@Parameter static var shownTips: [String: Bool] = [:]
var title: Text {
Text(titleString)
}
var message: Text? {
Text(messageString)
}
var rules: [Rule] {
[
#Rule(Self.$shownTips) { tip in
tip[id] == true
}
]
}
var options: [TipOption] {
[
Tip.IgnoresDisplayFrequency(true)
]
}
}
struct ViewWithOnScreenHelp: View {
@State private var onscreenHelp = false
@State var message = ""
@State var garbage = ""
@State var tip = SomeTip(
id: "",
titleString: "",
messageString: ""
)
var body: some View {
VStack {
Button("Tip") {
garbage = UUID().uuidString
message = "\(Int.random(in: 0...1000))"
tip = SomeTip(
id: garbage,
titleString: "Tip",
messageString: "Messge: \(message)")
SomeTip.shownTips[tip.id] = true
}
.background {
Color.clear
.popoverTip(tip)
.id(garbage)
}
}
.padding()
.task { // This .task would normally go on the app root-view
try? Tips.resetDatastore() // not normal use
try? Tips.configure([
.displayFrequency(.immediate),
.datastoreLocation(.applicationDefault),
])
}
}
}
#Preview {
ViewWithOnScreenHelp()
}