Skip to content

Commit

Permalink
bookmark state menu update (#1176)
Browse files Browse the repository at this point in the history
Rebuild posts view menu after (un)bookmarking.
  • Loading branch information
shaver committed Feb 17, 2024
1 parent 1b7e22a commit a448641
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// Copyright 2022 Awful Contributors. CC BY-NC-SA 3.0 US https://github.com/Awful/Awful.app

import Lottie
import UIKit

final class GetOutFrogRefreshSpinnerView: UIView, PostsPageRefreshControlContent {
private let animationView = LottieAnimationView(
Expand Down
18 changes: 13 additions & 5 deletions App/View Controllers/Posts/PostsPageViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ final class PostsPageViewController: ViewController {
let thread: AwfulThread
private var webViewDidLoadOnce = false

var threadActionsMenu: UIMenu {
UIMenu(title: thread.title ?? "", image: nil, identifier: nil, options: .displayInline, children: [
func threadActionsMenu() -> UIMenu {
return UIMenu(title: thread.title ?? "", image: nil, identifier: nil, options: .displayInline, children: [
// Bookmark
UIAction(
title: thread.bookmarked ? "Remove Bookmark" : "Bookmark Thread",
Expand Down Expand Up @@ -531,7 +531,9 @@ final class PostsPageViewController: ViewController {
}()


private lazy var actionsItem = UIBarButtonItem(title: "Menu", image: UIImage(named: "steamed-ham"), primaryAction: nil, menu: threadActionsMenu)
private func actionsItem() -> UIBarButtonItem {
UIBarButtonItem(title: "Menu", image: UIImage(named: "steamed-ham"), primaryAction: nil, menu: threadActionsMenu())
}

@objc private func externalStylesheetDidUpdate(_ rawNotification: Notification) {
guard let notification = PostsViewExternalStylesheetLoader.DidUpdateNotification(rawNotification) else {
Expand Down Expand Up @@ -1003,6 +1005,12 @@ final class PostsPageViewController: ViewController {
overlay.tintColor = theme["tintColor"]
try? await Task.sleep(timeInterval: 0.7)
overlay.dismiss(true)

// update toolbar so menu reflects new bookmarked state
var newItems = postsView.toolbarItems
newItems.removeLast()
newItems.append(actionsItem())
postsView.toolbarItems = newItems
}
} catch {
Log.e("error marking thread: \(error)")
Expand Down Expand Up @@ -1108,7 +1116,7 @@ final class PostsPageViewController: ViewController {
present(actionSheet, animated: false)

if let popover = actionSheet.popoverPresentationController {
popover.barButtonItem = actionsItem
popover.barButtonItem = actionsItem()
}
}
}
Expand Down Expand Up @@ -1493,7 +1501,7 @@ final class PostsPageViewController: ViewController {
postsView.toolbarItems = [
settingsItem, .flexibleSpace(),
backItem, .fixedSpace(spacer), currentPageItem, .fixedSpace(spacer), forwardItem,
.flexibleSpace(), actionsItem]
.flexibleSpace(), actionsItem()]

let longPress = UILongPressGestureRecognizer(target: self, action: #selector(didLongPressOnPostsView))
longPress.delegate = self
Expand Down

0 comments on commit a448641

Please sign in to comment.