From ba76fc51a15d36e1bc72951607cac18baf07d450 Mon Sep 17 00:00:00 2001 From: CMK Date: Thu, 10 Feb 2022 15:03:57 +0800 Subject: [PATCH] fix: add missing margin for timeline with horizontal regular size class --- Mastodon.xcodeproj/project.pbxproj | 4 + .../HomeTimelineViewController.swift | 1 - .../NotificationTableViewCell+ViewModel.swift | 6 +- .../Cell/NotificationTableViewCell.swift | 16 +- .../AdaptiveMarginStatusTableViewCell.swift | 45 ++++ .../StatusTableViewCell+ViewModel.swift | 2 +- .../TableviewCell/StatusTableViewCell.swift | 255 ++---------------- ...tusThreadRootTableViewCell+ViewModel.swift | 2 +- .../StatusThreadRootTableViewCell.swift | 26 +- 9 files changed, 112 insertions(+), 245 deletions(-) create mode 100644 Mastodon/Scene/Share/View/TableviewCell/AdaptiveMarginStatusTableViewCell.swift diff --git a/Mastodon.xcodeproj/project.pbxproj b/Mastodon.xcodeproj/project.pbxproj index b7ede3f2..1bc305a6 100644 --- a/Mastodon.xcodeproj/project.pbxproj +++ b/Mastodon.xcodeproj/project.pbxproj @@ -482,6 +482,7 @@ DBB45B5627B39FC9002DC5A7 /* MediaPreviewVideoViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBB45B5527B39FC9002DC5A7 /* MediaPreviewVideoViewController.swift */; }; DBB45B5927B39FE4002DC5A7 /* MediaPreviewVideoViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBB45B5827B39FE4002DC5A7 /* MediaPreviewVideoViewModel.swift */; }; DBB45B5B27B3A109002DC5A7 /* MediaPreviewTransitionViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBB45B5A27B3A109002DC5A7 /* MediaPreviewTransitionViewController.swift */; }; + DBB45B5E27B4EB22002DC5A7 /* AdaptiveMarginStatusTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBB45B5D27B4EB22002DC5A7 /* AdaptiveMarginStatusTableViewCell.swift */; }; DBB525082611EAC0002F1F29 /* Tabman in Frameworks */ = {isa = PBXBuildFile; productRef = DBB525072611EAC0002F1F29 /* Tabman */; }; DBB5250E2611EBAF002F1F29 /* ProfileSegmentedViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBB5250D2611EBAF002F1F29 /* ProfileSegmentedViewController.swift */; }; DBB525212611EBD6002F1F29 /* ProfilePagingViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBB525202611EBD6002F1F29 /* ProfilePagingViewController.swift */; }; @@ -1225,6 +1226,7 @@ DBB45B5527B39FC9002DC5A7 /* MediaPreviewVideoViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MediaPreviewVideoViewController.swift; sourceTree = ""; }; DBB45B5827B39FE4002DC5A7 /* MediaPreviewVideoViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MediaPreviewVideoViewModel.swift; sourceTree = ""; }; DBB45B5A27B3A109002DC5A7 /* MediaPreviewTransitionViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MediaPreviewTransitionViewController.swift; sourceTree = ""; }; + DBB45B5D27B4EB22002DC5A7 /* AdaptiveMarginStatusTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AdaptiveMarginStatusTableViewCell.swift; sourceTree = ""; }; DBB5250D2611EBAF002F1F29 /* ProfileSegmentedViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileSegmentedViewController.swift; sourceTree = ""; }; DBB525202611EBD6002F1F29 /* ProfilePagingViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfilePagingViewController.swift; sourceTree = ""; }; DBB5252F2611EBF3002F1F29 /* ProfilePagingViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfilePagingViewModel.swift; sourceTree = ""; }; @@ -1736,6 +1738,7 @@ DBE3CDBA261C427900430CC6 /* TimelineHeaderTableViewCell.swift */, DB6B750327300B4000C70B6E /* TimelineFooterTableViewCell.swift */, DB02CDAA26256A9500D0A2AF /* ThreadReplyLoaderTableViewCell.swift */, + DBB45B5D27B4EB22002DC5A7 /* AdaptiveMarginStatusTableViewCell.swift */, ); path = TableviewCell; sourceTree = ""; @@ -3826,6 +3829,7 @@ DBA465952696E387002B41DB /* AppPreference.swift in Sources */, 2D8434F525FF465D00EECE90 /* HomeTimelineNavigationBarTitleViewModel.swift in Sources */, DB938F0F2624119800E5B6C1 /* ThreadViewModel+LoadThreadState.swift in Sources */, + DBB45B5E27B4EB22002DC5A7 /* AdaptiveMarginStatusTableViewCell.swift in Sources */, DB6180F226391CF40018D199 /* MediaPreviewImageViewModel.swift in Sources */, DBA5E7A3263AD0A3004598BB /* PhotoLibraryService.swift in Sources */, 5DDDF1932617442700311060 /* Mastodon+Entity+Account.swift in Sources */, diff --git a/Mastodon/Scene/HomeTimeline/HomeTimelineViewController.swift b/Mastodon/Scene/HomeTimeline/HomeTimelineViewController.swift index 31914970..d37ac8ca 100644 --- a/Mastodon/Scene/HomeTimeline/HomeTimelineViewController.swift +++ b/Mastodon/Scene/HomeTimeline/HomeTimelineViewController.swift @@ -185,7 +185,6 @@ extension HomeTimelineViewController { viewModel.tableView = tableView viewModel.contentOffsetAdjustableTimelineViewControllerDelegate = self tableView.delegate = self -// tableView.prefetchDataSource = self viewModel.setupDiffableDataSource( tableView: tableView, statusTableViewCellDelegate: self, diff --git a/Mastodon/Scene/Notification/Cell/NotificationTableViewCell+ViewModel.swift b/Mastodon/Scene/Notification/Cell/NotificationTableViewCell+ViewModel.swift index 83bd7b82..dc16346c 100644 --- a/Mastodon/Scene/Notification/Cell/NotificationTableViewCell+ViewModel.swift +++ b/Mastodon/Scene/Notification/Cell/NotificationTableViewCell+ViewModel.swift @@ -31,11 +31,11 @@ extension NotificationTableViewCell { ) { if notificationView.frame == .zero { // set status view width - notificationView.frame.size.width = tableView.frame.width + notificationView.frame.size.width = tableView.frame.width - containerViewHorizontalMargin 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 - notificationView.quoteStatusView.frame.size.width = tableView.frame.width - StatusView.containerLayoutMargin.left - StatusView.containerLayoutMargin.right + notificationView.statusView.frame.size.width = tableView.frame.width - containerViewHorizontalMargin + notificationView.quoteStatusView.frame.size.width = tableView.frame.width - StatusView.containerLayoutMargin.left - StatusView.containerLayoutMargin.right - containerViewHorizontalMargin } switch viewModel.value { diff --git a/Mastodon/Scene/Notification/Cell/NotificationTableViewCell.swift b/Mastodon/Scene/Notification/Cell/NotificationTableViewCell.swift index fa49824f..17b1b9a1 100644 --- a/Mastodon/Scene/Notification/Cell/NotificationTableViewCell.swift +++ b/Mastodon/Scene/Notification/Cell/NotificationTableViewCell.swift @@ -20,6 +20,9 @@ final class NotificationTableViewCell: UITableViewCell { let notificationView = NotificationView() let separatorLine = UIView.separatorLine + + var containerViewLeadingLayoutConstraint: NSLayoutConstraint! + var containerViewTrailingLayoutConstraint: NSLayoutConstraint! override func prepareForReuse() { super.prepareForReuse() @@ -45,10 +48,12 @@ extension NotificationTableViewCell { private func _init() { notificationView.translatesAutoresizingMaskIntoConstraints = false contentView.addSubview(notificationView) + setupContainerViewMarginConstraints() + updateContainerViewMarginConstraints() NSLayoutConstraint.activate([ notificationView.topAnchor.constraint(equalTo: contentView.topAnchor, constant: 16), - notificationView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor), - notificationView.trailingAnchor.constraint(equalTo: contentView.trailingAnchor), + containerViewLeadingLayoutConstraint, + containerViewTrailingLayoutConstraint, contentView.bottomAnchor.constraint(equalTo: notificationView.bottomAnchor), ]) @@ -66,6 +71,13 @@ extension NotificationTableViewCell { } +// MARK: - AdaptiveContainerMarginTableViewCell +extension NotificationTableViewCell: AdaptiveContainerMarginTableViewCell { + var containerView: NotificationView { + notificationView + } +} + // MARK: - NotificationViewContainerTableViewCell extension NotificationTableViewCell: NotificationViewContainerTableViewCell { } diff --git a/Mastodon/Scene/Share/View/TableviewCell/AdaptiveMarginStatusTableViewCell.swift b/Mastodon/Scene/Share/View/TableviewCell/AdaptiveMarginStatusTableViewCell.swift new file mode 100644 index 00000000..78363d09 --- /dev/null +++ b/Mastodon/Scene/Share/View/TableviewCell/AdaptiveMarginStatusTableViewCell.swift @@ -0,0 +1,45 @@ +// +// AdaptiveMarginStatusTableViewCell.swift +// Mastodon +// +// Created by MainasuK on 2022-2-10. +// + +import UIKit +import MastodonUI + +protocol AdaptiveContainerMarginTableViewCell: UITableViewCell { + associatedtype ContainerView: UIView + static var containerViewMarginForRegularHorizontalSizeClass: CGFloat { get } + var containerView: ContainerView { get } + var containerViewLeadingLayoutConstraint: NSLayoutConstraint! { get set } + var containerViewTrailingLayoutConstraint: NSLayoutConstraint! { get set } +} + +extension AdaptiveContainerMarginTableViewCell { + + static var containerViewMarginForRegularHorizontalSizeClass: CGFloat { 64 } + + func setupContainerViewMarginConstraints() { + containerViewLeadingLayoutConstraint = containerView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor) + containerViewTrailingLayoutConstraint = contentView.trailingAnchor.constraint(equalTo: containerView.trailingAnchor) + } + + func updateContainerViewMarginConstraints() { + guard traitCollection.userInterfaceIdiom != .phone, + traitCollection.horizontalSizeClass == .regular + else { + containerViewLeadingLayoutConstraint.constant = 0 + containerViewTrailingLayoutConstraint.constant = 0 + return + } + + containerViewLeadingLayoutConstraint.constant = Self.containerViewMarginForRegularHorizontalSizeClass + containerViewTrailingLayoutConstraint.constant = Self.containerViewMarginForRegularHorizontalSizeClass + } + + var containerViewHorizontalMargin: CGFloat { + containerViewLeadingLayoutConstraint.constant + containerViewTrailingLayoutConstraint.constant + } + +} diff --git a/Mastodon/Scene/Share/View/TableviewCell/StatusTableViewCell+ViewModel.swift b/Mastodon/Scene/Share/View/TableviewCell/StatusTableViewCell+ViewModel.swift index 873caff0..84dd4943 100644 --- a/Mastodon/Scene/Share/View/TableviewCell/StatusTableViewCell+ViewModel.swift +++ b/Mastodon/Scene/Share/View/TableviewCell/StatusTableViewCell+ViewModel.swift @@ -32,7 +32,7 @@ extension StatusTableViewCell { ) { if statusView.frame == .zero { // set status view width - statusView.frame.size.width = tableView.frame.width + statusView.frame.size.width = tableView.frame.width - containerViewHorizontalMargin logger.log(level: .debug, "\((#file as NSString).lastPathComponent, privacy: .public)[\(#line, privacy: .public)], \(#function, privacy: .public): did layout for new cell") } diff --git a/Mastodon/Scene/Share/View/TableviewCell/StatusTableViewCell.swift b/Mastodon/Scene/Share/View/TableviewCell/StatusTableViewCell.swift index aa8da714..5a88eeba 100644 --- a/Mastodon/Scene/Share/View/TableviewCell/StatusTableViewCell.swift +++ b/Mastodon/Scene/Share/View/TableviewCell/StatusTableViewCell.swift @@ -14,6 +14,8 @@ import MastodonUI final class StatusTableViewCell: UITableViewCell { + static let marginForRegularHorizontalSizeClass: CGFloat = 64 + let logger = Logger(subsystem: "StatusTableViewCell", category: "View") weak var delegate: StatusTableViewCellDelegate? @@ -21,6 +23,9 @@ final class StatusTableViewCell: UITableViewCell { let statusView = StatusView() let separatorLine = UIView.separatorLine + + var containerViewLeadingLayoutConstraint: NSLayoutConstraint! + var containerViewTrailingLayoutConstraint: NSLayoutConstraint! // var isFiltered: Bool = false { // didSet { @@ -64,10 +69,12 @@ extension StatusTableViewCell { private func _init() { statusView.translatesAutoresizingMaskIntoConstraints = false contentView.addSubview(statusView) + setupContainerViewMarginConstraints() + updateContainerViewMarginConstraints() NSLayoutConstraint.activate([ statusView.topAnchor.constraint(equalTo: contentView.topAnchor, constant: 16), - statusView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor), - statusView.trailingAnchor.constraint(equalTo: contentView.trailingAnchor), + containerViewLeadingLayoutConstraint, + containerViewTrailingLayoutConstraint, statusView.bottomAnchor.constraint(equalTo: contentView.bottomAnchor), ]) statusView.setup(style: .inline) @@ -82,245 +89,25 @@ extension StatusTableViewCell { ]) statusView.delegate = self -// statusView.translatesAutoresizingMaskIntoConstraints = false -// contentView.addSubview(statusView) -// NSLayoutConstraint.activate([ -// statusView.topAnchor.constraint(equalTo: contentView.topAnchor, constant: 20), -// statusView.leadingAnchor.constraint(equalTo: contentView.readableContentGuide.leadingAnchor), -// contentView.readableContentGuide.trailingAnchor.constraint(equalTo: statusView.trailingAnchor), -// ]) -// -// threadMetaStackView.translatesAutoresizingMaskIntoConstraints = false -// contentView.addSubview(threadMetaStackView) -// NSLayoutConstraint.activate([ -// threadMetaStackView.topAnchor.constraint(equalTo: statusView.bottomAnchor), -// threadMetaStackView.leadingAnchor.constraint(equalTo: contentView.readableContentGuide.leadingAnchor), -// threadMetaStackView.trailingAnchor.constraint(equalTo: contentView.readableContentGuide.trailingAnchor), -// threadMetaStackView.bottomAnchor.constraint(equalTo: contentView.bottomAnchor), -// ]) -// threadMetaStackView.addArrangedSubview(threadMetaView) -// -// filteredLabel.translatesAutoresizingMaskIntoConstraints = false -// addSubview(filteredLabel) -// NSLayoutConstraint.activate([ -// filteredLabel.centerXAnchor.constraint(equalTo: centerXAnchor), -// filteredLabel.centerYAnchor.constraint(equalTo: centerYAnchor), -// ]) -// filteredLabel.isHidden = true -// -// statusView.delegate = self -// statusView.pollTableView.delegate = self -// statusView.statusMosaicImageViewContainer.delegate = self -// statusView.actionToolbarContainer.delegate = self -// -// // default hidden -// threadMetaView.isHidden = true } -// override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { -// super.traitCollectionDidChange(previousTraitCollection) -// -// resetSeparatorLineLayout() -// } -// -// private func configure(isFiltered: Bool) { -// statusView.alpha = isFiltered ? 0 : 1 -// threadMetaView.alpha = isFiltered ? 0 : 1 -// filteredLabel.isHidden = !isFiltered -// isUserInteractionEnabled = !isFiltered -// } - + override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { + super.traitCollectionDidChange(previousTraitCollection) + + updateContainerViewMarginConstraints() + } + } -//extension StatusTableViewCell { -// -// private func resetSeparatorLineLayout() { -// separatorLineToEdgeLeadingLayoutConstraint.isActive = false -// separatorLineToEdgeTrailingLayoutConstraint.isActive = false -// separatorLineToMarginLeadingLayoutConstraint.isActive = false -// separatorLineToMarginTrailingLayoutConstraint.isActive = false -// -// if traitCollection.userInterfaceIdiom == .phone { -// // to edge -// NSLayoutConstraint.activate([ -// separatorLineToEdgeLeadingLayoutConstraint, -// separatorLineToEdgeTrailingLayoutConstraint, -// ]) -// } else { -// if traitCollection.horizontalSizeClass == .compact { -// // to edge -// NSLayoutConstraint.activate([ -// separatorLineToEdgeLeadingLayoutConstraint, -// separatorLineToEdgeTrailingLayoutConstraint, -// ]) -// } else { -// // to margin -// NSLayoutConstraint.activate([ -// separatorLineToMarginLeadingLayoutConstraint, -// separatorLineToMarginTrailingLayoutConstraint, -// ]) -// } -// } -// } -// -//} -// -//// MARK: - MosaicImageViewContainerPresentable -//extension StatusTableViewCell: MosaicImageViewContainerPresentable { -// -// var mosaicImageViewContainer: MosaicImageViewContainer { -// return statusView.statusMosaicImageViewContainer -// } -// -// var isRevealing: Bool { -// return statusView.isRevealing -// } -// -//} -// -//// MARK: - UITableViewDelegate -//extension StatusTableViewCell: UITableViewDelegate { -// -// func tableView(_ tableView: UITableView, shouldHighlightRowAt indexPath: IndexPath) -> Bool { -// if tableView === statusView.pollTableView, let diffableDataSource = statusView.pollTableViewDataSource { -// var pollID: String? -// defer { -// os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s: indexPath: %s. PollID: %s", ((#file as NSString).lastPathComponent), #line, #function, indexPath.debugDescription, pollID ?? "") -// } -// guard let item = diffableDataSource.itemIdentifier(for: indexPath), -// case let .option(objectID, _) = item, -// let option = delegate?.managedObjectContext.object(with: objectID) as? PollOption else { -// return false -// } -// pollID = option.poll.id -// return !option.poll.expired -// } else { -// assertionFailure() -// return true -// } -// } -// -// func tableView(_ tableView: UITableView, willSelectRowAt indexPath: IndexPath) -> IndexPath? { -// if tableView === statusView.pollTableView, let diffableDataSource = statusView.pollTableViewDataSource { -// var pollID: String? -// defer { -// os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s: indexPath: %s. PollID: %s", ((#file as NSString).lastPathComponent), #line, #function, indexPath.debugDescription, pollID ?? "") -// } -// -// guard let context = delegate?.context else { return nil } -// guard let activeMastodonAuthenticationBox = context.authenticationService.activeMastodonAuthenticationBox.value else { return nil } -// guard let item = diffableDataSource.itemIdentifier(for: indexPath), -// case let .option(objectID, _) = item, -// let option = delegate?.managedObjectContext.object(with: objectID) as? PollOption else { -// return nil -// } -// let poll = option.poll -// pollID = poll.id -// -// // disallow select when: poll expired OR user voted remote OR user voted local -// let userID = activeMastodonAuthenticationBox.userID -// let didVotedRemote = (option.poll.votedBy ?? Set()).contains(where: { $0.id == userID }) -// let votedOptions = poll.options.filter { option in -// (option.votedBy ?? Set()).map { $0.id }.contains(userID) -// } -// let didVotedLocal = !votedOptions.isEmpty -// -// if poll.multiple { -// guard !option.poll.expired, !didVotedRemote else { -// return nil -// } -// } else { -// guard !option.poll.expired, !didVotedRemote, !didVotedLocal else { -// return nil -// } -// } -// -// return indexPath -// } else { -// assertionFailure() -// return indexPath -// } -// } -// -// -// func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { -// if tableView === statusView.pollTableView { -// os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s: indexPath: %s", ((#file as NSString).lastPathComponent), #line, #function, indexPath.debugDescription) -// delegate?.statusTableViewCell(self, pollTableView: statusView.pollTableView, didSelectRowAt: indexPath) -// } else { -// assertionFailure() -// } -// } -// -//} - +// MARK: - AdaptiveContainerMarginTableViewCell +extension StatusTableViewCell: AdaptiveContainerMarginTableViewCell { + var containerView: StatusView { + statusView + } +} // MARK: - StatusViewContainerTableViewCell extension StatusTableViewCell: StatusViewContainerTableViewCell { } // MARK: - StatusViewDelegate extension StatusTableViewCell: StatusViewDelegate { } - - -//// MARK: - StatusViewDelegate -//extension StatusTableViewCell: StatusViewDelegate { -// -// func statusView(_ statusView: StatusView, headerInfoLabelDidPressed label: UILabel) { -// delegate?.statusTableViewCell(self, statusView: statusView, headerInfoLabelDidPressed: label) -// } -// -// func statusView(_ statusView: StatusView, avatarImageViewDidPressed imageView: UIImageView) { -// delegate?.statusTableViewCell(self, statusView: statusView, avatarImageViewDidPressed: imageView) -// } -// -// func statusView(_ statusView: StatusView, revealContentWarningButtonDidPressed button: UIButton) { -// delegate?.statusTableViewCell(self, statusView: statusView, revealContentWarningButtonDidPressed: button) -// } -// -// func statusView(_ statusView: StatusView, contentWarningOverlayViewDidPressed contentWarningOverlayView: ContentWarningOverlayView) { -// delegate?.statusTableViewCell(self, statusView: statusView, contentWarningOverlayViewDidPressed: contentWarningOverlayView) -// } -// -// func statusView(_ statusView: StatusView, playerContainerView: PlayerContainerView, contentWarningOverlayViewDidPressed contentWarningOverlayView: ContentWarningOverlayView) { -// delegate?.statusTableViewCell(self, playerContainerView: playerContainerView, contentWarningOverlayViewDidPressed: contentWarningOverlayView) -// } -// -// func statusView(_ statusView: StatusView, pollVoteButtonPressed button: UIButton) { -// delegate?.statusTableViewCell(self, statusView: statusView, pollVoteButtonPressed: button) -// } -// -// func statusView(_ statusView: StatusView, metaText: MetaText, didSelectMeta meta: Meta) { -// delegate?.statusTableViewCell(self, statusView: statusView, metaText: metaText, didSelectMeta: meta) -// } -// -//} -// -//// MARK: - MosaicImageViewDelegate -//extension StatusTableViewCell: MosaicImageViewContainerDelegate { -// -// func mosaicImageViewContainer(_ mosaicImageViewContainer: MosaicImageViewContainer, didTapImageView imageView: UIImageView, atIndex index: Int) { -// delegate?.statusTableViewCell(self, mosaicImageViewContainer: mosaicImageViewContainer, didTapImageView: imageView, atIndex: index) -// } -// -// func mosaicImageViewContainer(_ mosaicImageViewContainer: MosaicImageViewContainer, contentWarningOverlayViewDidPressed contentWarningOverlayView: ContentWarningOverlayView) { -// delegate?.statusTableViewCell(self, mosaicImageViewContainer: mosaicImageViewContainer, contentWarningOverlayViewDidPressed: contentWarningOverlayView) -// } -// -//} -// -//// MARK: - ActionToolbarContainerDelegate -//extension StatusTableViewCell: ActionToolbarContainerDelegate { -// -// func actionToolbarContainer(_ actionToolbarContainer: ActionToolbarContainer, replayButtonDidPressed sender: UIButton) { -// delegate?.statusTableViewCell(self, actionToolbarContainer: actionToolbarContainer, replyButtonDidPressed: sender) -// } -// -// func actionToolbarContainer(_ actionToolbarContainer: ActionToolbarContainer, reblogButtonDidPressed sender: UIButton) { -// delegate?.statusTableViewCell(self, actionToolbarContainer: actionToolbarContainer, reblogButtonDidPressed: sender) -// } -// -// func actionToolbarContainer(_ actionToolbarContainer: ActionToolbarContainer, starButtonDidPressed sender: UIButton) { -// delegate?.statusTableViewCell(self, actionToolbarContainer: actionToolbarContainer, likeButtonDidPressed: sender) -// } -// -//} diff --git a/Mastodon/Scene/Share/View/TableviewCell/StatusThreadRootTableViewCell+ViewModel.swift b/Mastodon/Scene/Share/View/TableviewCell/StatusThreadRootTableViewCell+ViewModel.swift index 240736fd..9568aa80 100644 --- a/Mastodon/Scene/Share/View/TableviewCell/StatusThreadRootTableViewCell+ViewModel.swift +++ b/Mastodon/Scene/Share/View/TableviewCell/StatusThreadRootTableViewCell+ViewModel.swift @@ -31,7 +31,7 @@ extension StatusThreadRootTableViewCell { ) { if statusView.frame == .zero { // set status view width - statusView.frame.size.width = tableView.frame.width + statusView.frame.size.width = tableView.frame.width - containerViewHorizontalMargin logger.log(level: .debug, "\((#file as NSString).lastPathComponent, privacy: .public)[\(#line, privacy: .public)], \(#function, privacy: .public): did layout for new cell") } diff --git a/Mastodon/Scene/Share/View/TableviewCell/StatusThreadRootTableViewCell.swift b/Mastodon/Scene/Share/View/TableviewCell/StatusThreadRootTableViewCell.swift index a330161f..e16e4f28 100644 --- a/Mastodon/Scene/Share/View/TableviewCell/StatusThreadRootTableViewCell.swift +++ b/Mastodon/Scene/Share/View/TableviewCell/StatusThreadRootTableViewCell.swift @@ -14,7 +14,9 @@ import MastodonUI final class StatusThreadRootTableViewCell: UITableViewCell { - let logger = Logger(subsystem: "StatusTableViewCell", category: "View") + static let marginForRegularHorizontalSizeClass: CGFloat = 64 + + let logger = Logger(subsystem: "StatusThreadRootTableViewCell", category: "View") weak var delegate: StatusTableViewCellDelegate? var disposeBag = Set() @@ -22,6 +24,9 @@ final class StatusThreadRootTableViewCell: UITableViewCell { let statusView = StatusView() let separatorLine = UIView.separatorLine + var containerViewLeadingLayoutConstraint: NSLayoutConstraint! + var containerViewTrailingLayoutConstraint: NSLayoutConstraint! + override func prepareForReuse() { super.prepareForReuse() @@ -52,10 +57,12 @@ extension StatusThreadRootTableViewCell { statusView.translatesAutoresizingMaskIntoConstraints = false contentView.addSubview(statusView) + setupContainerViewMarginConstraints() + updateContainerViewMarginConstraints() NSLayoutConstraint.activate([ statusView.topAnchor.constraint(equalTo: contentView.topAnchor, constant: 16), - statusView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor), - statusView.trailingAnchor.constraint(equalTo: contentView.trailingAnchor), + containerViewLeadingLayoutConstraint, + containerViewTrailingLayoutConstraint, statusView.bottomAnchor.constraint(equalTo: contentView.bottomAnchor), ]) statusView.setup(style: .plain) @@ -76,8 +83,21 @@ extension StatusThreadRootTableViewCell { statusView.contentMetaText.textView.isAccessibilityElement = false } + override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { + super.traitCollectionDidChange(previousTraitCollection) + + updateContainerViewMarginConstraints() + } + } +extension StatusThreadRootTableViewCell: AdaptiveContainerMarginTableViewCell { + var containerView: StatusView { + statusView + } +} + + // MARK: - StatusViewContainerTableViewCell extension StatusThreadRootTableViewCell: StatusViewContainerTableViewCell { }