I have created a tip with a parameter (Bool) I have tried to set it to true in a sheet which is presented modally over the view which should present the popover tip. After the sheet gets dismissed the popover tip is never presented. If I restart the app, the popover tip appears. Is there any way to trigger the presentation of a popover tip manually?
I have created a little demo app to demonstrate my problem:
Setup TipKit on app start:
import SwiftUI
import TipKit
@main
struct TipKitDemoApp: App {
var body: some Scene {
WindowGroup {
ContentView()
.task {
try? Tips.configure()
}
}
}
}
Simple tip:
import Foundation
import TipKit
struct DemoTip: Tip {
@Parameter
static var enabled: Bool = false
var title: Text {
Text("Demo Tip")
}
var rules: [Rule] {
[
#Rule(Self.$enabled) { $0 == true }
]
}
}
Content view which includes the popover tip and displays the sheet where the tip can be enabled:
import SwiftUI
struct ContentView: View {
@State private var presentDetail = false
let demoTip = DemoTip()
var body: some View {
VStack {
Image(systemName: "globe")
.imageScale(.large)
.foregroundStyle(.tint)
Text("Hello, world!")
.popoverTip(demoTip)
Button("Present Details") {
presentDetail.toggle()
}
}
.padding()
.sheet(isPresented: $presentDetail) {
DetailView()
}
}
}
In the detail view the tip gets enabled, but if I dismiss this view, the tip only appears after I restart the app:
import SwiftUI
struct DetailView: View {
@Environment(\.dismiss) private var dismiss
var body: some View {
Button("Enable demo tip") {
DemoTip.enabled = true
}
Button("Dismiss") {
dismiss()
}
}
}