Merge pull request #943 from nossipova/594-post-visibility

Show post visibility indicator
This commit is contained in:
Nathan Mattes 2023-08-28 12:29:10 +02:00 committed by GitHub
commit 2957408c0a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 136 additions and 30 deletions

View File

@ -0,0 +1,15 @@
{
"images" : [
{
"filename" : "questionmark.circle.pdf",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"preserves-vector-representation" : true
}
}

View File

@ -154,6 +154,7 @@ public enum Asset {
public static let peopleAdd = ImageAsset(name: "Scene/Compose/people.add")
public static let pollFill = ImageAsset(name: "Scene/Compose/poll.fill")
public static let poll = ImageAsset(name: "Scene/Compose/poll")
public static let questionmarkCircle = ImageAsset(name: "Scene/Compose/questionmark.circle")
public static let reorderDot = ImageAsset(name: "Scene/Compose/reorder.dot")
}
public enum Discovery {

View File

@ -0,0 +1,20 @@
// Copyright © 2023 Mastodon gGmbH. All rights reserved.
import UIKit
import CoreDataStack
import MastodonAsset
extension MastodonVisibility {
public var image: UIImage {
let asset: ImageAsset
switch self {
case .public: asset = Asset.Scene.Compose.earth
case .unlisted: asset = Asset.Scene.Compose.people
case .private: asset = Asset.Scene.Compose.peopleAdd
case .direct: asset = Asset.Scene.Compose.mention
case ._other: asset = Asset.Scene.Compose.questionmarkCircle
}
return asset.image.withRenderingMode(.alwaysTemplate)
}
}

View File

@ -126,7 +126,6 @@ extension ComposeContentViewController {
toolbarHostingView.view.heightAnchor.constraint(equalToConstant: ComposeContentToolbarView.toolbarHeight),
])
toolbarHostingView.view.preservesSuperviewLayoutMargins = true
//composeToolbarView.delegate = self
composeContentToolbarBackgroundView.translatesAutoresizingMaskIntoConstraints = false
view.insertSubview(composeContentToolbarBackgroundView, belowSubview: toolbarHostingView.view)

View File

@ -43,6 +43,8 @@ extension NotificationView {
@Published public var timestamp: Date?
@Published public var visibility: MastodonVisibility = .public
@Published public var followRequestState = MastodonFollowRequestState(state: .none)
@Published public var transientFollowRequestState = MastodonFollowRequestState(state: .none)
@ -122,6 +124,12 @@ extension NotificationView.ViewModel {
}
.store(in: &disposeBag)
$visibility
.sink { visibility in
notificationView.visibilityIconImageView.image = visibility.image
}
.store(in: &disposeBag)
// notification type indicator
$notificationIndicatorText
.sink { text in

View File

@ -91,6 +91,20 @@ public final class NotificationView: UIView {
// timestamp
public let dateLabel = MetaLabel(style: .statusUsername)
public let dateTrailingDotLabel: MetaLabel = {
let label = MetaLabel(style: .statusUsername)
label.configure(content: PlaintextMetaContent(string: "·"))
return label
}()
let visibilityIconImageView: UIImageView = {
let imageView = UIImageView()
imageView.tintColor = Asset.Colors.Label.secondary.color
imageView.contentMode = .scaleAspectFit
imageView.image = Asset.Scene.Compose.earth.image.withRenderingMode(.alwaysTemplate)
return imageView
}()
public let menuButton: UIButton = {
let button = HitTestExpandedButton(type: .system)
button.tintColor = Asset.Colors.Label.secondary.color
@ -272,16 +286,32 @@ extension NotificationView {
authrMetaContainer.setCustomSpacing(4, after: authorSecondaryMetaContainer)
authorSecondaryMetaContainer.addArrangedSubview(authorUsernameLabel)
authorUsernameLabel.setContentHuggingPriority(.required - 8, for: .horizontal)
authorUsernameLabel.setContentCompressionResistancePriority(.required - 8, for: .horizontal)
authorUsernameLabel.setContentHuggingPriority(.required - 1, for: .vertical)
authorUsernameLabel.setContentCompressionResistancePriority(.defaultLow, for: .horizontal)
authorSecondaryMetaContainer.addArrangedSubview(usernameTrialingDotLabel)
usernameTrialingDotLabel.setContentHuggingPriority(.required - 2, for: .horizontal)
usernameTrialingDotLabel.setContentCompressionResistancePriority(.required - 2, for: .horizontal)
usernameTrialingDotLabel.setContentCompressionResistancePriority(.required, for: .horizontal)
authorSecondaryMetaContainer.addArrangedSubview(dateLabel)
dateLabel.setContentHuggingPriority(.required - 1, for: .horizontal)
dateLabel.setContentCompressionResistancePriority(.required - 1, for: .horizontal)
authorSecondaryMetaContainer.addArrangedSubview(dateTrailingDotLabel)
dateTrailingDotLabel.setContentCompressionResistancePriority(.required, for: .horizontal)
authorSecondaryMetaContainer.addArrangedSubview(dateTrailingDotLabel)
dateTrailingDotLabel.setContentCompressionResistancePriority(.required, for: .horizontal)
authorSecondaryMetaContainer.addArrangedSubview(visibilityIconImageView)
NSLayoutConstraint.activate([
visibilityIconImageView.heightAnchor.constraint(equalTo: authorUsernameLabel.heightAnchor),
visibilityIconImageView.widthAnchor.constraint(equalTo: visibilityIconImageView.heightAnchor),
])
authorSecondaryMetaContainer.addArrangedSubview(UIView())
authorSecondaryMetaContainer.setCustomSpacing(0, after: visibilityIconImageView)
// authorContainerViewBottomPaddingView
authorContainerViewBottomPaddingView.translatesAutoresizingMaskIntoConstraints = false
containerStackView.addArrangedSubview(authorContainerViewBottomPaddingView)

View File

@ -41,9 +41,23 @@ public class StatusAuthorView: UIStackView {
// timestamp
public let dateLabel = MetaLabel(style: .statusUsername)
public let dateTrailingDotLabel: MetaLabel = {
let label = MetaLabel(style: .statusUsername)
label.configure(content: PlaintextMetaContent(string: "·"))
return label
}()
let visibilityIconImageView: UIImageView = {
let imageView = UIImageView()
imageView.tintColor = Asset.Colors.Label.secondary.color
imageView.contentMode = .scaleAspectFit
imageView.image = Asset.Scene.Compose.earth.image.withRenderingMode(.alwaysTemplate)
return imageView
}()
public let menuButton: UIButton = {
let button = HitTestExpandedButton(type: .system)
button.expandEdgeInsets = UIEdgeInsets(top: -20, left: -10, bottom: -5, right: -10)
button.expandEdgeInsets = UIEdgeInsets(top: -20, left: -10, bottom: -10, right: -10)
button.tintColor = Asset.Colors.Label.secondary.color
let image = UIImage(systemName: "ellipsis", withConfiguration: UIImage.SymbolConfiguration(font: .systemFont(ofSize: 15)))
button.setImage(image, for: .normal)
@ -53,11 +67,10 @@ public class StatusAuthorView: UIStackView {
public let contentSensitiveeToggleButton: UIButton = {
let button = HitTestExpandedButton(type: .system)
button.expandEdgeInsets = UIEdgeInsets(top: -5, left: -10, bottom: -20, right: -10)
button.expandEdgeInsets = UIEdgeInsets(top: -20, left: -10, bottom: -10, right: -10)
button.tintColor = Asset.Colors.Label.secondary.color
button.imageView?.contentMode = .scaleAspectFill
button.imageView?.clipsToBounds = false
let image = UIImage(systemName: "eye.slash.fill", withConfiguration: UIImage.SymbolConfiguration(font: .systemFont(ofSize: 15)))
button.imageView?.contentMode = .scaleAspectFit
let image = UIImage(systemName: "eye.slash.fill")
button.setImage(image, for: .normal)
return button
}()
@ -138,6 +151,8 @@ extension StatusAuthorView {
// dateLabel
dateLabel.isUserInteractionEnabled = false
visibilityIconImageView.isUserInteractionEnabled = false
}
}
@ -259,47 +274,59 @@ extension StatusAuthorView {
// authorPrimaryMetaContainer: H - [ authorNameLabel | (padding) | menuButton ]
let authorPrimaryMetaContainer = UIStackView()
authorPrimaryMetaContainer.axis = .horizontal
authorPrimaryMetaContainer.spacing = 10
authorPrimaryMetaContainer.alignment = .center
authorPrimaryMetaContainer.spacing = 8
authorMetaContainer.addArrangedSubview(authorPrimaryMetaContainer)
// authorNameLabel
authorPrimaryMetaContainer.addArrangedSubview(authorNameLabel)
authorNameLabel.setContentHuggingPriority(.required - 10, for: .horizontal)
authorNameLabel.setContentCompressionResistancePriority(.required - 10, for: .horizontal)
authorNameLabel.setContentHuggingPriority(.required - 1, for: .vertical)
authorNameLabel.setContentCompressionResistancePriority(.defaultLow, for: .horizontal)
authorPrimaryMetaContainer.addArrangedSubview(UIView())
authorPrimaryMetaContainer.addArrangedSubview(contentSensitiveeToggleButton)
NSLayoutConstraint.activate([
contentSensitiveeToggleButton.heightAnchor.constraint(equalToConstant: 18),
])
authorPrimaryMetaContainer.setCustomSpacing(16, after: contentSensitiveeToggleButton)
// menuButton
authorPrimaryMetaContainer.addArrangedSubview(menuButton)
menuButton.setContentHuggingPriority(.required - 2, for: .horizontal)
menuButton.setContentCompressionResistancePriority(.required - 2, for: .horizontal)
menuButton.setContentHuggingPriority(.required - 1, for: .horizontal)
menuButton.setContentCompressionResistancePriority(.required - 1, for: .horizontal)
// authorSecondaryMetaContainer: H - [ authorUsername | usernameTrialingDotLabel | dateLabel | (padding) | contentSensitiveeToggleButton ]
let authorSecondaryMetaContainer = UIStackView()
authorSecondaryMetaContainer.axis = .horizontal
authorSecondaryMetaContainer.alignment = .center
authorSecondaryMetaContainer.spacing = 4
authorMetaContainer.addArrangedSubview(authorSecondaryMetaContainer)
authorSecondaryMetaContainer.addArrangedSubview(authorUsernameLabel)
authorUsernameLabel.setContentHuggingPriority(.required - 8, for: .horizontal)
authorUsernameLabel.setContentCompressionResistancePriority(.required - 8, for: .horizontal)
authorUsernameLabel.setContentHuggingPriority(.required - 1, for: .vertical)
authorUsernameLabel.setContentCompressionResistancePriority(.defaultLow, for: .horizontal)
authorSecondaryMetaContainer.addArrangedSubview(usernameTrialingDotLabel)
usernameTrialingDotLabel.setContentHuggingPriority(.required - 2, for: .horizontal)
usernameTrialingDotLabel.setContentCompressionResistancePriority(.required - 2, for: .horizontal)
usernameTrialingDotLabel.setContentCompressionResistancePriority(.required, for: .horizontal)
authorSecondaryMetaContainer.addArrangedSubview(dateLabel)
dateLabel.setContentHuggingPriority(.required - 1, for: .horizontal)
dateLabel.setContentCompressionResistancePriority(.required - 1, for: .horizontal)
authorSecondaryMetaContainer.addArrangedSubview(UIView())
contentSensitiveeToggleButton.translatesAutoresizingMaskIntoConstraints = false
authorSecondaryMetaContainer.addArrangedSubview(contentSensitiveeToggleButton)
authorSecondaryMetaContainer.addArrangedSubview(dateTrailingDotLabel)
dateTrailingDotLabel.setContentCompressionResistancePriority(.required, for: .horizontal)
authorSecondaryMetaContainer.addArrangedSubview(visibilityIconImageView)
NSLayoutConstraint.activate([
contentSensitiveeToggleButton.heightAnchor.constraint(equalTo: authorUsernameLabel.heightAnchor, multiplier: 1.0).priority(.required - 1),
contentSensitiveeToggleButton.widthAnchor.constraint(equalTo: contentSensitiveeToggleButton.heightAnchor, multiplier: 1.0).priority(.required - 1),
visibilityIconImageView.heightAnchor.constraint(equalTo: authorUsernameLabel.heightAnchor),
visibilityIconImageView.widthAnchor.constraint(equalTo: visibilityIconImageView.heightAnchor),
])
authorUsernameLabel.setContentHuggingPriority(.required - 1, for: .vertical)
authorUsernameLabel.setContentCompressionResistancePriority(.required - 1, for: .vertical)
contentSensitiveeToggleButton.setContentHuggingPriority(.defaultLow, for: .vertical)
contentSensitiveeToggleButton.setContentHuggingPriority(.defaultLow, for: .horizontal)
contentSensitiveeToggleButton.setContentCompressionResistancePriority(.defaultLow, for: .horizontal)
contentSensitiveeToggleButton.setContentCompressionResistancePriority(.defaultLow, for: .vertical)
authorSecondaryMetaContainer.setCustomSpacing(0, after: visibilityIconImageView)
authorSecondaryMetaContainer.addArrangedSubview(UIView())
}
func layoutReport() {

View File

@ -292,6 +292,12 @@ extension StatusView.ViewModel {
authorView.dateLabel.configure(content: PlaintextMetaContent(string: text))
}
.store(in: &disposeBag)
$visibility
.sink { visibility in
authorView.visibilityIconImageView.image = visibility.image
}
.store(in: &disposeBag)
}
private func bindContent(statusView: StatusView) {