Skip to content

Commit

Permalink
feat(widgets): add tip for the new recommendations widget on home
Browse files Browse the repository at this point in the history
  • Loading branch information
Gio2018 committed Apr 19, 2024
1 parent 5da883c commit 56a0479
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -364,3 +364,5 @@
"tips.swipeToArchive.message" = "Swipe left on an article to archive it quickly.";
"tips.swipeHighlights.title" = "Swipe Highlights";
"tips.swipeHighlights.message" = "Swipe left on a paragraph to highlight it. Alternatively, swipe and select 'Delete Highlights' to remove any existing highlighting.";
"tips.recommendationsWidget.selectTopic.title" = "New Recommendations Widget!";
"tips.recommendationsWidget.selectTopic.message" = "Long-press on the Recommendations Widget to choose a topic of interest.\nInstall multiple widgets to keep track of all your favorite topics.";
9 changes: 9 additions & 0 deletions PocketKit/Sources/Localization/Strings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,15 @@ public enum Localization {
}
}
public enum Tips {
public enum RecommendationsWidget {
public enum SelectTopic {
/// Long-press on the Recommendations Widget to choose a topic of interest.
/// Install multiple widgets to keep track of all your favorite topics.
public static let message = Localization.tr("Localizable", "tips.recommendationsWidget.selectTopic.message", fallback: "Long-press on the Recommendations Widget to choose a topic of interest.\nInstall multiple widgets to keep track of all your favorite topics.")
/// New Recommendations Widget!
public static let title = Localization.tr("Localizable", "tips.recommendationsWidget.selectTopic.title", fallback: "New Recommendations Widget!")
}
}
public enum SwipeHighlights {
/// Swipe left on a paragraph to highlight it. Alternatively, swipe and select 'Delete Highlights' to remove any existing highlighting.
public static let message = Localization.tr("Localizable", "tips.swipeHighlights.message", fallback: "Swipe left on a paragraph to highlight it. Alternatively, swipe and select 'Delete Highlights' to remove any existing highlighting.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class ReadableViewController: UIViewController {
private var isReloading = false

private var userScrollProgress: IndexPath?

// Tippable view controller properties
var tipObservationTask: Task<Void, Error>?
weak var tipViewController: UIViewController?

Expand Down
17 changes: 17 additions & 0 deletions PocketKit/Sources/PocketKit/Home/HomeViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ class HomeViewController: UIViewController {

private var collectionSubscriptions = SubscriptionsStack()

// Tippable view controller properties
var tipObservationTask: Task<Void, Error>?
weak var tipViewController: UIViewController?

private lazy var layout = UICollectionViewCompositionalLayout { [weak self] sectionIndex, env in
guard let self = self,
let section = self.dataSource.sectionIdentifier(for: sectionIndex) else {
Expand Down Expand Up @@ -165,6 +169,17 @@ class HomeViewController: UIViewController {
handleRefresh()
}

override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
if #available(iOS 17.0, *), let sourceView = navigationController?.view ?? view {
let x = view.bounds.width / 2
let y: CGFloat = 0
let sourceRect = CGRect(x: x, y: y, width: 0, height: 0)
let configuration = TipUIConfiguration(sourceRect: sourceRect, permittedArrowDirections: .init(rawValue: 0), backgroundColor: nil, tintColor: nil)
displayTip(NewRecommendationsWidgetTip(), configuration: configuration, sourceView: sourceView)
}
}

private func handleRefresh(isForced: Bool = false) {
model.refresh(isForced: isForced) { [weak self] in
DispatchQueue.main.async {
Expand Down Expand Up @@ -744,6 +759,8 @@ extension HomeViewController: SFSafariViewControllerDelegate {
}
}

extension HomeViewController: TippableViewController {}

private extension Style {
static let overscroll = Style.header.sansSerif.p3.with { $0.with(alignment: .center) }
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ItemsListViewController<ViewModel: ItemsListViewModel>: UIViewController,
private var progressView: UIProgressView!
private var dataSource: UICollectionViewDiffableDataSource<ItemsListSection, ItemsListCell<ViewModel.ItemIdentifier>>!
private var itemSectionLayout: NSCollectionLayoutSection!

// Tippable view controller properties
var tipObservationTask: Task<Void, Error>?
weak var tipViewController: UIViewController?

Expand Down
10 changes: 10 additions & 0 deletions PocketKit/Sources/PocketKit/Tips/PocketTips.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,13 @@ struct SwipeArchiveTip: Tip {
let image: Image? = Image(uiImage: UIImage(asset: .archive))
let options = [Tips.MaxDisplayCount(3)]
}

/// New Recommendation Widget, Home
@available(iOS 17.0, *)
struct NewRecommendationsWidgetTip: Tip {
var id = UUID()
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)]
}

0 comments on commit 56a0479

Please sign in to comment.