1
0
mirror of https://github.com/mastodon/mastodon-ios.git synced 2024-12-13 17:17:35 +01:00
mastodon-app-ufficiale-ipho.../MastodonSDK/Sources/MastodonUI/View/Control/ProfileStatusDashboardView.swift

117 lines
4.6 KiB
Swift
Raw Normal View History

2021-04-01 08:39:15 +02:00
//
// ProfileStatusDashboardView.swift
// Mastodon
//
// Created by MainasuK Cirno on 2021-3-30.
//
import os.log
import UIKit
import MastodonAsset
import MastodonLocalization
2021-04-01 08:39:15 +02:00
public protocol ProfileStatusDashboardViewDelegate: AnyObject {
2021-11-01 12:54:07 +01:00
func profileStatusDashboardView(_ dashboardView: ProfileStatusDashboardView, dashboardMeterViewDidPressed dashboardMeterView: ProfileStatusDashboardMeterView, meter: ProfileStatusDashboardView.Meter)
2021-04-01 08:39:15 +02:00
}
public final class ProfileStatusDashboardView: UIView {
2021-04-01 08:39:15 +02:00
public let postDashboardMeterView = ProfileStatusDashboardMeterView()
public let followingDashboardMeterView = ProfileStatusDashboardMeterView()
public let followersDashboardMeterView = ProfileStatusDashboardMeterView()
2021-04-01 08:39:15 +02:00
public weak var delegate: ProfileStatusDashboardViewDelegate?
2021-04-01 08:39:15 +02:00
public override init(frame: CGRect) {
2021-04-01 08:39:15 +02:00
super.init(frame: frame)
_init()
}
public required init?(coder: NSCoder) {
2021-04-01 08:39:15 +02:00
super.init(coder: coder)
_init()
}
}
2021-11-01 12:54:07 +01:00
extension ProfileStatusDashboardView {
public enum Meter: Hashable {
2021-11-01 12:54:07 +01:00
case post
case following
case follower
}
}
2021-04-01 08:39:15 +02:00
extension ProfileStatusDashboardView {
private func _init() {
let containerStackView = UIStackView()
containerStackView.translatesAutoresizingMaskIntoConstraints = false
addSubview(containerStackView)
NSLayoutConstraint.activate([
containerStackView.topAnchor.constraint(equalTo: topAnchor),
containerStackView.leadingAnchor.constraint(equalTo: leadingAnchor),
trailingAnchor.constraint(equalTo: containerStackView.trailingAnchor),
bottomAnchor.constraint(equalTo: containerStackView.bottomAnchor),
containerStackView.heightAnchor.constraint(equalToConstant: 44).priority(.defaultHigh),
])
let spacing: CGFloat = UIView.isZoomedMode ? 4 : 12
2021-04-01 08:39:15 +02:00
containerStackView.spacing = spacing
containerStackView.axis = .horizontal
containerStackView.distribution = .fillEqually
containerStackView.alignment = .top
containerStackView.addArrangedSubview(postDashboardMeterView)
containerStackView.setCustomSpacing(spacing - 2, after: postDashboardMeterView)
containerStackView.addArrangedSubview(followingDashboardMeterView)
containerStackView.setCustomSpacing(spacing + 2, after: followingDashboardMeterView)
containerStackView.addArrangedSubview(followersDashboardMeterView)
postDashboardMeterView.textLabel.text = L10n.Scene.Profile.Dashboard.posts
followingDashboardMeterView.textLabel.text = L10n.Scene.Profile.Dashboard.following
followersDashboardMeterView.textLabel.text = L10n.Scene.Profile.Dashboard.followers
[postDashboardMeterView, followingDashboardMeterView, followersDashboardMeterView].forEach { meterView in
let tapGestureRecognizer = UITapGestureRecognizer.singleTapGestureRecognizer
tapGestureRecognizer.addTarget(self, action: #selector(ProfileStatusDashboardView.tapGestureRecognizerHandler(_:)))
meterView.addGestureRecognizer(tapGestureRecognizer)
}
followingDashboardMeterView.accessibilityHint = L10n.Scene.Profile.Accessibility.doubleTapToOpenTheList
followersDashboardMeterView.accessibilityHint = L10n.Scene.Profile.Accessibility.doubleTapToOpenTheList
2021-04-01 08:39:15 +02:00
}
}
extension ProfileStatusDashboardView {
@objc private func tapGestureRecognizerHandler(_ sender: UITapGestureRecognizer) {
os_log(.debug, "%{public}s[%{public}ld], %{public}s", ((#file as NSString).lastPathComponent), #line, #function)
2021-04-01 08:39:15 +02:00
guard let sourceView = sender.view as? ProfileStatusDashboardMeterView else {
assertionFailure()
return
}
2021-11-01 12:54:07 +01:00
switch sourceView {
case postDashboardMeterView:
delegate?.profileStatusDashboardView(self, dashboardMeterViewDidPressed: sourceView, meter: .post)
case followingDashboardMeterView:
delegate?.profileStatusDashboardView(self, dashboardMeterViewDidPressed: sourceView, meter: .following)
case followersDashboardMeterView:
delegate?.profileStatusDashboardView(self, dashboardMeterViewDidPressed: sourceView, meter: .follower)
default:
assertionFailure()
2021-04-01 08:39:15 +02:00
}
}
}
#if DEBUG
import SwiftUI
struct ProfileBannerStatusView_Previews: PreviewProvider {
static var previews: some View {
UIViewPreview(width: 375) {
ProfileStatusDashboardView()
}
.previewLayout(.fixed(width: 375, height: 100))
}
}
#endif