Skip to content

Commit

Permalink
Fix new Recommendations widget tip displaying at every launch (#1000)
Browse files Browse the repository at this point in the history
* fix(tips): use a static uuid for tips

* feat(tips): add tip events to better control when tips are displayed
  • Loading branch information
Gio2018 authored Apr 29, 2024
1 parent 87388a1 commit 150e134
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ class ReadableViewController: UIViewController {
super.viewDidAppear(animated)
scrollToLastKnownPosition()
if #available(iOS 17.0, *) {
PocketTipEvents.showSwipeHighlightsTip.sendDonation()
displayTip(SwipeHighlightsTip(), configuration: nil, sourceView: nil)
}
}
Expand Down
1 change: 1 addition & 0 deletions PocketKit/Sources/PocketKit/Home/HomeViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ class HomeViewController: UIViewController {
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
if #available(iOS 17.0, *), let sourceView = navigationController?.view ?? view {
PocketTipEvents.showNewRecommendationsWidgetTip.sendDonation()
let x = view.bounds.width / 2
let y: CGFloat = 0
let sourceRect = CGRect(x: x, y: y, width: 0, height: 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class ItemsListViewController<ViewModel: ItemsListViewModel>: UIViewController,
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
if #available(iOS 17.0, *) {
PocketTipEvents.showSwipeArchiveTip.sendDonation()
displayTip(SwipeArchiveTip(), configuration: nil, sourceView: nil)
}
}
Expand Down
32 changes: 27 additions & 5 deletions PocketKit/Sources/PocketKit/Tips/PocketTips.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,51 @@ import TipKit
/// Swipe highlights, Reader
@available(iOS 17.0, *)
struct SwipeHighlightsTip: Tip {
var id = UUID()
let id = "pocketTips.reader.swipeHighlights"
let title: Text = Text(Localization.Tips.SwipeHighlights.title)
let message: Text? = Text(Localization.Tips.SwipeHighlights.message)
let image: Image? = Image(uiImage: UIImage(asset: .highlights))
let options = [Tips.MaxDisplayCount(3)]
let options = [Tips.MaxDisplayCount(1)]
var rules: [Rule] {
#Rule(PocketTipEvents.showSwipeHighlightsTip) {
$0.donations.count == 1
}
}
}

/// Swipe to archive, Saves
@available(iOS 17.0, *)
struct SwipeArchiveTip: Tip {
var id = UUID()
let id = "pocketTips.saves.swipeArchive"
let title = Text(Localization.Tips.SwipeToArchive.title)
let message: Text? = Text(Localization.Tips.SwipeToArchive.message)
let image: Image? = Image(uiImage: UIImage(asset: .archive))
let options = [Tips.MaxDisplayCount(3)]
let options = [Tips.MaxDisplayCount(1)]
var rules: [Rule] {
#Rule(PocketTipEvents.showSwipeArchiveTip) {
$0.donations.count == 1
}
}
}

/// New Recommendation Widget, Home
@available(iOS 17.0, *)
struct NewRecommendationsWidgetTip: Tip {
var id = UUID()
let id = "pocketTips.home.newRecommendationsWidget"
let title = Text(Localization.Tips.RecommendationsWidget.SelectTopic.title)
let message: Text? = Text(Localization.Tips.RecommendationsWidget.SelectTopic.message)
let image: Image? = nil
let options = [Tips.MaxDisplayCount(1)]
var rules: [Rule] {
#Rule(PocketTipEvents.showNewRecommendationsWidgetTip) {
$0.donations.count == 1
}
}
}

@available(iOS 17.0, *)
enum PocketTipEvents {
static let showNewRecommendationsWidgetTip = Tips.Event(id: "pocketTips.events.showNewRecommendationsWidgetTip")
static let showSwipeHighlightsTip = Tips.Event(id: "pocketTips.events.showSwipeHighlightsTip")
static let showSwipeArchiveTip = Tips.Event(id: "pocketTips.events.showSwipeArchiveTip")
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ struct TipUIConfiguration {
extension TippableViewController {
@available(iOS 17.0, *)
func displayTip<T: Tip>(_ tip: T, configuration: TipUIConfiguration?, sourceView: UIView?) {
tipObservationTask = tipObservationTask ?? Task.delayed(byTimeInterval: 0.3) { @MainActor [weak self] in
tipObservationTask = tipObservationTask ?? Task.delayed(byTimeInterval: 0.5) { @MainActor [weak self] in
guard let self else {
return
}
Expand Down

0 comments on commit 150e134

Please sign in to comment.