-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
108 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
WordPress/Classes/ViewRelated/Post/AbstractPostHelper+Actions.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import UIKit | ||
|
||
extension AbstractPostHelper { | ||
// MARK: - Posts | ||
|
||
static func makeLeadingContextualActions(for post: AbstractPost, delegate: InteractivePostViewDelegate) -> [UIContextualAction] { | ||
var actions: [UIContextualAction] = [] | ||
|
||
if post.status != .trash { | ||
let viewAction = UIContextualAction(style: .normal, title: Strings.swipeActionView) { [weak delegate] _, _, completion in | ||
delegate?.view(post) | ||
completion(true) | ||
} | ||
viewAction.image = UIImage(systemName: "safari") | ||
viewAction.backgroundColor = .systemBlue | ||
actions.append(viewAction) | ||
} | ||
|
||
return actions | ||
} | ||
|
||
static func makeTrailingContextualActions(for post: AbstractPost, delegate: InteractivePostViewDelegate) -> [UIContextualAction] { | ||
var actions: [UIContextualAction] = [] | ||
|
||
let trashAction = UIContextualAction( | ||
style: .destructive, | ||
title: post.status == .trash ? Strings.swipeActionDeletePermanently : Strings.swipeActionTrash | ||
) { [weak delegate] _, _, completion in | ||
delegate?.trash(post) { | ||
completion(true) | ||
} | ||
} | ||
trashAction.image = UIImage(systemName: "trash") | ||
actions.append(trashAction) | ||
|
||
if post.status == .publish && post.hasRemote() { | ||
let shareAction = UIContextualAction(style: .normal, title: Strings.swipeActionShare) { [weak delegate] _, view, completion in | ||
delegate?.share(post, fromView: view) | ||
completion(true) | ||
} | ||
shareAction.image = UIImage(systemName: "square.and.arrow.up") | ||
actions.append(shareAction) | ||
} | ||
|
||
return actions | ||
} | ||
} | ||
|
||
private enum Strings { | ||
static let swipeActionView = NSLocalizedString("postList.swipeActionView", value: "View", comment: "Swipe action title") | ||
static let swipeActionShare = NSLocalizedString("postList.swipeActionShare", value: "Share", comment: "Swipe action title") | ||
static let swipeActionTrash = NSLocalizedString("postList.swipeActionDelete", value: "Trash", comment: "Swipe action title") | ||
static let swipeActionDeletePermanently = NSLocalizedString("postList.swipeActionDelete", value: "Delete Permanently", comment: "Swipe action title") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters