How to force TipKit to show a tip, regardless of history

447 views Asked by At

I'm curious, is there a way to get TipKit to show a tip on-demand in a reliable way? I want a tip to appear only when the user taps on a help button, but I can't get it to happen consistently (ie after every single tap).

In this example code, it will work once on each launch, only because I've called Tips.resetDatastore() on initialisation. I would normally not want to be calling that. I'd rather that my Tooltip didn't store or use event history at all. But it should still respond to new events.

import SwiftUI
import TipKit

struct extraHelp: Tip {
    static let tipRequested = Event(id: "extraHelpRequested")
    
    var title: Text { Text("Extra Help") }
    var message: Text { Text("Suitable amount of explanation here.")}
    
    var rules: [Rule] { [
        #Rule(Self.tipRequested) { $0.donations.count > 0 }
    ]}
    
    // This tip will always be visible when event received
    var options: [Option] {
        [IgnoresDisplayFrequency(true)]
    }
}


struct ViewWithOnScreenHelp: View {
    @State private var onscreenHelp = false
    
    var body: some View {
        VStack {
            Button("Help!") {
                Task { await extraHelp.tipRequested.donate() }
            }
            .popoverTip(extraHelp())
        }
        .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),
            ])
        }
    }
}

I know that this isn't the way Apple wants me to use TipKit, but it's the UX I have in mind and it would be a shame to not be able to use the parts they've supplied.

0

There are 0 answers