mirror of
https://github.com/oxen-io/session-ios.git
synced 2023-12-13 21:30:14 +01:00
Fixed a bug where the time label would no longer appear in the context menu Fixed a bug where the tile label in the context menu could be clipped Tweaked the context menu appearance animation to look less jumpy when at the edges of the screen
114 lines
3.4 KiB
Swift
114 lines
3.4 KiB
Swift
// Copyright © 2022 Rangeproof Pty Ltd. All rights reserved.
|
|
|
|
import UIKit
|
|
import SessionUIKit
|
|
import SessionUtilitiesKit
|
|
|
|
extension ContextMenuVC {
|
|
final class EmojiReactsView: UIView {
|
|
private let action: Action
|
|
private let dismiss: () -> Void
|
|
|
|
// MARK: - Settings
|
|
|
|
private static let size: CGFloat = 40
|
|
|
|
// MARK: - Lifecycle
|
|
|
|
init(for action: Action, dismiss: @escaping () -> Void) {
|
|
self.action = action
|
|
self.dismiss = dismiss
|
|
|
|
super.init(frame: CGRect.zero)
|
|
|
|
setUpViewHierarchy()
|
|
}
|
|
|
|
override init(frame: CGRect) {
|
|
preconditionFailure("Use init(for:) instead.")
|
|
}
|
|
|
|
required init?(coder: NSCoder) {
|
|
preconditionFailure("Use init(for:) instead.")
|
|
}
|
|
|
|
private func setUpViewHierarchy() {
|
|
let emojiLabel: UILabel = UILabel()
|
|
emojiLabel.font = .systemFont(ofSize: Values.veryLargeFontSize)
|
|
emojiLabel.text = self.action.title
|
|
emojiLabel.set(.height, to: ContextMenuVC.EmojiReactsView.size)
|
|
addSubview(emojiLabel)
|
|
emojiLabel.pin(to: self)
|
|
|
|
// Tap gesture recognizer
|
|
let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(handleTap))
|
|
addGestureRecognizer(tapGestureRecognizer)
|
|
}
|
|
|
|
// MARK: - Interaction
|
|
|
|
@objc private func handleTap() {
|
|
action.work()
|
|
dismiss()
|
|
}
|
|
}
|
|
|
|
final class EmojiPlusButton: UIView {
|
|
private let action: Action?
|
|
private let dismiss: () -> Void
|
|
|
|
// MARK: - Settings
|
|
|
|
public static let size: CGFloat = 28
|
|
private let iconSize: CGFloat = 14
|
|
|
|
// MARK: - Lifecycle
|
|
|
|
init(action: Action?, dismiss: @escaping () -> Void) {
|
|
self.action = action
|
|
self.dismiss = dismiss
|
|
|
|
super.init(frame: CGRect.zero)
|
|
|
|
setUpViewHierarchy()
|
|
}
|
|
|
|
override init(frame: CGRect) {
|
|
preconditionFailure("Use init(for:) instead.")
|
|
}
|
|
|
|
required init?(coder: NSCoder) {
|
|
preconditionFailure("Use init(for:) instead.")
|
|
}
|
|
|
|
private func setUpViewHierarchy() {
|
|
// Icon image
|
|
let iconImageView = UIImageView(image: #imageLiteral(resourceName: "ic_plus_24").withRenderingMode(.alwaysTemplate))
|
|
iconImageView.themeTintColor = .textPrimary
|
|
iconImageView.set(.width, to: iconSize)
|
|
iconImageView.set(.height, to: iconSize)
|
|
iconImageView.contentMode = .scaleAspectFit
|
|
addSubview(iconImageView)
|
|
iconImageView.center(in: self)
|
|
|
|
// Background
|
|
isUserInteractionEnabled = true
|
|
themeBackgroundColor = .reactions_contextMoreBackground
|
|
|
|
// Tap gesture recognizer
|
|
let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(handleTap))
|
|
addGestureRecognizer(tapGestureRecognizer)
|
|
}
|
|
|
|
// MARK: - Interaction
|
|
|
|
@objc private func handleTap() {
|
|
dismiss()
|
|
|
|
DispatchQueue.main.asyncAfter(deadline: .now() + 0.25, execute: { [weak self] in
|
|
self?.action?.work()
|
|
})
|
|
}
|
|
}
|
|
}
|