Multiple PopoverTip Modifiers in SwiftUI: Persistent Display Glitch
I've encountered an issue when attempting to add multiple popoverTip modifiers in my SwiftUI code. Regardless of whether there's a specified rule or parameter, the tips begin to constantly appear and disappear. Is this a recognized issue? How can we sequentially display multiple tip popovers on complex views? Even when one tip is invalidated, the glitch persists. Should this be used only for views without any state updates?
Here's a sample code that demonstrates the problem:
import SwiftUI
import TipKit
@main
struct testbedApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
init() {
try? Tips.configure()
}
}
struct PopoverTip1: Tip {
var title: Text {
Text("Test title 1").foregroundStyle(.indigo)
}
var message: Text? {
Text("Test message 1")
}
}
struct PopoverTip2: Tip {
var title: Text {
Text("Test title 2").foregroundStyle(.indigo)
}
var message: Text? {
Text("Test message 2")
}
}
struct ContentView: View {
private let timer = Timer.publish(every: 0.001, on: .main, in: .common).autoconnect()
@State private var counter = 1
var body: some View {
VStack(spacing: 20) {
Spacer()
Text("Counter value: \(counter)").popoverTip(PopoverTip1())
Spacer()
Text("Counter value multiplied by 2: \(counter * 2)")
.foregroundStyle(.tertiary)
.popoverTip(PopoverTip2())
Spacer()
}
.padding()
.onReceive(timer) { _ in
counter += 1
}
}
}
#Preview {
ContentView()
}
Comments
Post a Comment