Skip to content

Commit

Permalink
Add like animation in post list (#23827)
Browse files Browse the repository at this point in the history
  • Loading branch information
kean authored Nov 19, 2024
1 parent fa6caed commit 8949d19
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
18 changes: 16 additions & 2 deletions WordPress/Classes/ViewRelated/Reader/Cards/ReaderPostCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,21 @@ private final class ReaderPostCellView: UIView {
}

@objc private func buttonLikeTapped() {
viewModel?.toggleLike()
guard let viewModel else {
return wpAssertionFailure("missing ViewModel")
}
if !viewModel.toolbar.isLiked {
var toolbar = viewModel.toolbar
toolbar.isLiked = true
toolbar.likeCount += 1
configureToolbar(with: toolbar)
UINotificationFeedbackGenerator().notificationOccurred(.success)
buttons.like.imageView?.fadeInWithRotationAnimation { _ in
viewModel.toggleLike()
}
} else {
viewModel.toggleLike()
}
}

private func makeMoreMenu() -> [UIMenuElement] {
Expand Down Expand Up @@ -365,7 +379,7 @@ private func makeAuthorButton() -> UIButton {
private func makeButton(systemImage: String, font: UIFont = UIFont.preferredFont(forTextStyle: .footnote)) -> UIButton {
var configuration = UIButton.Configuration.plain()
configuration.image = UIImage(systemName: systemImage)
configuration.imagePadding = 8
configuration.imagePadding = 6
configuration.preferredSymbolConfigurationForImage = UIImage.SymbolConfiguration(font: font)
configuration.baseForegroundColor = .secondaryLabel
configuration.contentInsets = .init(top: 16, leading: 12, bottom: 14, trailing: 12)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ final class ReaderPostCellViewModel {
}

func toggleLike() {
ReaderLikeAction().execute(with: post)
ReaderLikeAction().execute(with: post, isFeedbackNeeded: false)
}
}

Expand All @@ -107,8 +107,8 @@ struct ReaderPostToolbarViewModel {
let isCommentsEnabled: Bool
let commentCount: Int
let isLikesEnabled: Bool
let likeCount: Int
let isLiked: Bool
var likeCount: Int
var isLiked: Bool

static func make(post: ReaderPost) -> ReaderPostToolbarViewModel {
ReaderPostToolbarViewModel(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
/// Encapsulates a command to toggle a post's liked status
final class ReaderLikeAction {
func execute(with post: ReaderPost, source: String? = nil, completion: (() -> Void)? = nil) {
func execute(with post: ReaderPost, source: String? = nil, isFeedbackNeeded: Bool = true, completion: (() -> Void)? = nil) {
if !post.isLiked {
// Consider a like from the list to be enough to push a page view.
// Solves a long-standing question from folks who ask 'why do I
// have more likes than page views?'.
ReaderHelpers.bumpPageViewForPost(post)
UINotificationFeedbackGenerator().notificationOccurred(.success)
if isFeedbackNeeded {
UINotificationFeedbackGenerator().notificationOccurred(.success)
}
}
let service = ReaderPostService(coreDataStack: ContextManager.shared)
service.toggleLiked(for: post, source: source, success: {
Expand Down

0 comments on commit 8949d19

Please sign in to comment.