From 78fc34c08d89e20003d69987057f2b0328aba238 Mon Sep 17 00:00:00 2001 From: CMK Date: Fri, 18 Feb 2022 18:25:26 +0800 Subject: [PATCH] chore: update notification timeline margin --- .../Cell/NotificationTableViewCell+ViewModel.swift | 2 +- .../Container/AdaptiveMarginContainerView.swift | 14 ++++++++++---- .../MastodonUI/View/Content/NotificationView.swift | 9 ++------- .../MastodonUI/View/Content/StatusView.swift | 3 ++- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/Mastodon/Scene/Notification/Cell/NotificationTableViewCell+ViewModel.swift b/Mastodon/Scene/Notification/Cell/NotificationTableViewCell+ViewModel.swift index 2a4eb8a98..7b994076a 100644 --- a/Mastodon/Scene/Notification/Cell/NotificationTableViewCell+ViewModel.swift +++ b/Mastodon/Scene/Notification/Cell/NotificationTableViewCell+ViewModel.swift @@ -36,7 +36,7 @@ extension NotificationTableViewCell { logger.log(level: .debug, "\((#file as NSString).lastPathComponent, privacy: .public)[\(#line, privacy: .public)], \(#function, privacy: .public): did layout for new cell") notificationView.statusView.frame.size.width = tableView.frame.width - containerViewHorizontalMargin - notificationView.quoteStatusView.frame.size.width = tableView.frame.width - 2 * StatusView.containerLayoutMargin - containerViewHorizontalMargin + notificationView.quoteStatusView.frame.size.width = tableView.frame.width - containerViewHorizontalMargin // the as same width as statusView } switch viewModel.value { diff --git a/MastodonSDK/Sources/MastodonUI/View/Container/AdaptiveMarginContainerView.swift b/MastodonSDK/Sources/MastodonUI/View/Container/AdaptiveMarginContainerView.swift index 467715d72..3bc6c781a 100644 --- a/MastodonSDK/Sources/MastodonUI/View/Container/AdaptiveMarginContainerView.swift +++ b/MastodonSDK/Sources/MastodonUI/View/Container/AdaptiveMarginContainerView.swift @@ -21,25 +21,31 @@ public final class AdaptiveMarginContainerView: UIView { contentView.translatesAutoresizingMaskIntoConstraints = false addSubview(contentView) + let _topLayoutConstraint = contentView.topAnchor.constraint(equalTo: topAnchor) let _leadingLayoutConstraint = contentView.leadingAnchor.constraint(equalTo: leadingAnchor) let _trailingLayoutConstraint = trailingAnchor.constraint(equalTo: contentView.trailingAnchor) + let _bottomLayoutConstraint = bottomAnchor.constraint(equalTo: contentView.bottomAnchor) NSLayoutConstraint.activate([ - contentView.topAnchor.constraint(equalTo: topAnchor), + _topLayoutConstraint, _leadingLayoutConstraint, _trailingLayoutConstraint, - contentView.bottomAnchor.constraint(equalTo: bottomAnchor), + _bottomLayoutConstraint ]) + topLayoutConstraint = _topLayoutConstraint leadingLayoutConstraint = _leadingLayoutConstraint trailingLayoutConstraint = _trailingLayoutConstraint + bottomLayoutConstraint = _bottomLayoutConstraint updateConstraints() } } - var leadingLayoutConstraint: NSLayoutConstraint? - var trailingLayoutConstraint: NSLayoutConstraint? + private(set) var topLayoutConstraint: NSLayoutConstraint? + private(set) var leadingLayoutConstraint: NSLayoutConstraint? + private(set) var trailingLayoutConstraint: NSLayoutConstraint? + private(set) var bottomLayoutConstraint: NSLayoutConstraint? } diff --git a/MastodonSDK/Sources/MastodonUI/View/Content/NotificationView.swift b/MastodonSDK/Sources/MastodonUI/View/Content/NotificationView.swift index a8b7f469f..265a46aa5 100644 --- a/MastodonSDK/Sources/MastodonUI/View/Content/NotificationView.swift +++ b/MastodonSDK/Sources/MastodonUI/View/Content/NotificationView.swift @@ -226,15 +226,9 @@ extension NotificationView { // quoteStatusView containerStackView.addArrangedSubview(quoteStatusViewContainerView) - quoteStatusViewContainerView.layoutMargins = UIEdgeInsets( - top: 0, - left: StatusView.containerLayoutMargin, - bottom: 16, - right: StatusView.containerLayoutMargin - ) + quoteStatusViewContainerView.layoutMargins.bottom = 16 quoteBackgroundView.layoutMargins = UIEdgeInsets(top: 16, left: 0, bottom: 0, right: 0) - quoteBackgroundView.translatesAutoresizingMaskIntoConstraints = false quoteStatusViewContainerView.addSubview(quoteBackgroundView) NSLayoutConstraint.activate([ @@ -301,6 +295,7 @@ extension NotificationView { extension NotificationView: AdaptiveContainerView { public func updateContainerViewComponentsLayoutMarginsRelativeArrangementBehavior(isEnabled: Bool) { statusView.updateContainerViewComponentsLayoutMarginsRelativeArrangementBehavior(isEnabled: isEnabled) + quoteStatusView.updateContainerViewComponentsLayoutMarginsRelativeArrangementBehavior(isEnabled: true) // always set margins } } diff --git a/MastodonSDK/Sources/MastodonUI/View/Content/StatusView.swift b/MastodonSDK/Sources/MastodonUI/View/Content/StatusView.swift index e77e33b24..b938f2b97 100644 --- a/MastodonSDK/Sources/MastodonUI/View/Content/StatusView.swift +++ b/MastodonSDK/Sources/MastodonUI/View/Content/StatusView.swift @@ -611,7 +611,8 @@ extension StatusView.Style { func notificationQuote(statusView: StatusView) { base(statusView: statusView) // override the base style - statusView.contentContainer.layoutMargins.bottom = 16 // fix contentText align to edge issue + statusView.contentAdaptiveMarginContainerView.bottomLayoutConstraint?.constant = 16 // fix bottom margin missing issue + statusView.pollAdaptiveMarginContainerView.bottomLayoutConstraint?.constant = 16 // fix bottom margin missing issue statusView.contentSensitiveeToggleButton.removeFromSuperview() statusView.menuButton.removeFromSuperview() statusView.actionToolbarAdaptiveMarginContainerView.removeFromSuperview()