mirror of
https://github.com/metabolist/metatext.git
synced 2024-11-25 09:41:00 +00:00
Reblog andd favorite animations
This commit is contained in:
parent
c421da9a48
commit
232426c7fe
1 changed files with 42 additions and 8 deletions
|
@ -465,16 +465,10 @@ private extension StatusView {
|
||||||
favoriteButton.setTitle(nil, for: .normal)
|
favoriteButton.setTitle(nil, for: .normal)
|
||||||
}
|
}
|
||||||
|
|
||||||
let reblogColor: UIColor = viewModel.reblogged ? .systemGreen : .secondaryLabel
|
setReblogButtonColor(reblogged: viewModel.reblogged)
|
||||||
|
|
||||||
reblogButton.tintColor = reblogColor
|
|
||||||
reblogButton.setTitleColor(reblogColor, for: .normal)
|
|
||||||
reblogButton.isEnabled = viewModel.canBeReblogged && isAuthenticated
|
reblogButton.isEnabled = viewModel.canBeReblogged && isAuthenticated
|
||||||
|
|
||||||
let favoriteColor: UIColor = viewModel.favorited ? .systemYellow : .secondaryLabel
|
setFavoriteButtonColor(favorited: viewModel.favorited)
|
||||||
|
|
||||||
favoriteButton.tintColor = favoriteColor
|
|
||||||
favoriteButton.setTitleColor(favoriteColor, for: .normal)
|
|
||||||
favoriteButton.isEnabled = isAuthenticated
|
favoriteButton.isEnabled = isAuthenticated
|
||||||
|
|
||||||
shareButton.tag = viewModel.sharingURL?.hashValue ?? 0
|
shareButton.tag = viewModel.sharingURL?.hashValue ?? 0
|
||||||
|
@ -571,15 +565,55 @@ private extension StatusView {
|
||||||
favorite()
|
favorite()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func setReblogButtonColor(reblogged: Bool) {
|
||||||
|
let reblogColor: UIColor = reblogged ? .systemGreen : .secondaryLabel
|
||||||
|
|
||||||
|
reblogButton.tintColor = reblogColor
|
||||||
|
reblogButton.setTitleColor(reblogColor, for: .normal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func setFavoriteButtonColor(favorited: Bool) {
|
||||||
|
let favoriteColor: UIColor = favorited ? .systemYellow : .secondaryLabel
|
||||||
|
|
||||||
|
favoriteButton.tintColor = favoriteColor
|
||||||
|
favoriteButton.setTitleColor(favoriteColor, for: .normal)
|
||||||
|
}
|
||||||
|
|
||||||
func reblog() {
|
func reblog() {
|
||||||
UIImpactFeedbackGenerator(style: .medium).impactOccurred()
|
UIImpactFeedbackGenerator(style: .medium).impactOccurred()
|
||||||
|
|
||||||
|
if !UIAccessibility.isReduceMotionEnabled {
|
||||||
|
UIViewPropertyAnimator.runningPropertyAnimator(
|
||||||
|
withDuration: .defaultAnimationDuration,
|
||||||
|
delay: 0,
|
||||||
|
options: .curveLinear) {
|
||||||
|
self.setReblogButtonColor(reblogged: !self.statusConfiguration.viewModel.reblogged)
|
||||||
|
self.reblogButton.imageView?.transform =
|
||||||
|
self.reblogButton.imageView?.transform.rotated(by: .pi) ?? .identity
|
||||||
|
} completion: { _ in
|
||||||
|
self.reblogButton.imageView?.transform = .identity
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
statusConfiguration.viewModel.toggleReblogged()
|
statusConfiguration.viewModel.toggleReblogged()
|
||||||
}
|
}
|
||||||
|
|
||||||
func favorite() {
|
func favorite() {
|
||||||
UIImpactFeedbackGenerator(style: .medium).impactOccurred()
|
UIImpactFeedbackGenerator(style: .medium).impactOccurred()
|
||||||
|
|
||||||
|
if !UIAccessibility.isReduceMotionEnabled {
|
||||||
|
UIViewPropertyAnimator.runningPropertyAnimator(
|
||||||
|
withDuration: .defaultAnimationDuration,
|
||||||
|
delay: 0,
|
||||||
|
options: .curveLinear) {
|
||||||
|
self.setFavoriteButtonColor(favorited: !self.statusConfiguration.viewModel.favorited)
|
||||||
|
self.favoriteButton.imageView?.transform =
|
||||||
|
self.favoriteButton.imageView?.transform.rotated(by: .pi) ?? .identity
|
||||||
|
} completion: { _ in
|
||||||
|
self.favoriteButton.imageView?.transform = .identity
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
statusConfiguration.viewModel.toggleFavorited()
|
statusConfiguration.viewModel.toggleFavorited()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue