Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[HOLD MERGE] Update diff view for forthcoming Watchlist feature #4552

Merged
merged 18 commits into from
Jul 5, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 39 additions & 23 deletions Wikipedia/Code/DiffToolbarView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ protocol DiffToolbarViewDelegate: AnyObject {
func tappedNext()
func tappedShare(_ sender: UIBarButtonItem)
func tappedThankButton()
func tappedUndo()
func tappedRollback()
var isLoggedIn: Bool { get }
}

Expand Down Expand Up @@ -34,6 +36,29 @@ class DiffToolbarView: UIView {
return item
}()

lazy var moreButton: IconBarButtonItem = {
// DIFFTODO: Add menu item images
let menu = UIMenu(title: "", options: .displayInline, children: [
UIAction(title: CommonStrings.rollback, attributes: [.destructive], handler: { [weak self] _ in self?.tappedRollback() }),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just FYI, visibility of the rollback option may need to changed based on permissions data from the API. I can look into this once the API calls are merged.

UIAction(title: CommonStrings.shortShareTitle, image: UIImage(systemName: "square.and.arrow.up"), handler: { _ in }),
// DIFFTODO: Add when Watchlist ships
// UIAction(title: CommonStrings.watchlist, handler: { _ in }),
UIAction(title: CommonStrings.diffArticleEditHistory, handler: { _ in })
]
)

let item = IconBarButtonItem(title: nil, image: UIImage(systemName: "ellipsis.circle"), primaryAction: nil, menu: menu)

item.accessibilityLabel = CommonStrings.moreButton
return item
}()

lazy var undoButton: IconBarButtonItem = {
let item = IconBarButtonItem(iconName: "Revert", target: self, action: #selector(tappedUndo(_:)), for: .touchUpInside)
item.accessibilityLabel = CommonStrings.undo
return item
}()

lazy var shareButton: IconBarButtonItem = {
let item = IconBarButtonItem(iconName: "share", target: self, action: #selector(tappedShare(_:)), for: .touchUpInside)
item.accessibilityLabel = CommonStrings.accessibilityShareTitle
Expand Down Expand Up @@ -81,8 +106,16 @@ class DiffToolbarView: UIView {

setItems()
}

@objc func tappedUndo(_ sender: UIBarButtonItem) {
delegate?.tappedUndo()
}

@objc func tappedRollback() {
delegate?.tappedRollback()
}

@objc func tappedPrevious(_ sender: UIBarButtonItem) {
@objc func tappedPrevious(_ sender: UIBarButtonItem) {
delegate?.tappedPrevious()
}

Expand All @@ -105,28 +138,9 @@ class DiffToolbarView: UIView {
}

private func setItems() {
let trailingMarginSpacing = UIBarButtonItem(barButtonSystemItem: .fixedSpace, target: nil, action: nil)
switch (traitCollection.horizontalSizeClass, traitCollection.verticalSizeClass) {
case (.regular, .regular):
trailingMarginSpacing.width = 58
default:
trailingMarginSpacing.width = 24
}

let leadingMarginSpacing = UIBarButtonItem(barButtonSystemItem: .fixedSpace, target: nil, action: nil)
switch (traitCollection.horizontalSizeClass, traitCollection.verticalSizeClass) {
case (.regular, .regular):
leadingMarginSpacing.width = 42
default:
leadingMarginSpacing.width = 0
}

let largeFixedSize = UIBarButtonItem(barButtonSystemItem: .fixedSpace, target: nil, action: nil)
largeFixedSize.width = 30

let spacer = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil)

toolbar.items = [leadingMarginSpacing, nextButton, previousButton, spacer, thankButton, largeFixedSize, shareButton, trailingMarginSpacing]
let flexibleSpace = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil)

toolbar.items = [nextButton, flexibleSpace, previousButton, flexibleSpace, undoButton, flexibleSpace, thankButton, flexibleSpace, moreButton]
}

func setPreviousButtonState(isEnabled: Bool) {
Expand Down Expand Up @@ -172,7 +186,9 @@ extension DiffToolbarView: Themeable {
previousButton.apply(theme: theme)
nextButton.apply(theme: theme)
shareButton.apply(theme: theme)
undoButton.apply(theme: theme)
thankButton.apply(theme: theme)
moreButton.apply(theme: theme)

if let delegate = delegate,
!delegate.isLoggedIn {
Expand Down
16 changes: 16 additions & 0 deletions Wikipedia/Images.xcassets/Revert.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"images" : [
{
"filename" : "Revert.pdf",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"preserves-vector-representation" : true,
"template-rendering-intent" : "template"
}
}
Binary file not shown.