fix: make content warning overlay toggle with cell height animation

This commit is contained in:
CMK 2021-06-23 23:34:38 +08:00
parent 4325ca3127
commit a6afe3e6ac
4 changed files with 38 additions and 11 deletions

View File

@ -52,6 +52,7 @@ extension NotificationSection {
let frame = CGRect(x: 0, y: 0, width: tableView.readableContentGuide.layoutFrame.width - NotificationStatusTableViewCell.statusPadding.left - NotificationStatusTableViewCell.statusPadding.right, height: tableView.readableContentGuide.layoutFrame.height) let frame = CGRect(x: 0, y: 0, width: tableView.readableContentGuide.layoutFrame.width - NotificationStatusTableViewCell.statusPadding.left - NotificationStatusTableViewCell.statusPadding.right, height: tableView.readableContentGuide.layoutFrame.height)
StatusSection.configure( StatusSection.configure(
cell: cell, cell: cell,
tableView: tableView,
dependency: dependency, dependency: dependency,
readableLayoutFrame: frame, readableLayoutFrame: frame,
status: status, status: status,

View File

@ -41,6 +41,7 @@ extension ReportSection {
let status = managedObjectContext.object(with: objectID) as! Status let status = managedObjectContext.object(with: objectID) as! Status
StatusSection.configure( StatusSection.configure(
cell: cell, cell: cell,
tableView: tableView,
dependency: dependency, dependency: dependency,
readableLayoutFrame: tableView.readableContentGuide.layoutFrame, readableLayoutFrame: tableView.readableContentGuide.layoutFrame,
status: status, status: status,

View File

@ -88,6 +88,7 @@ extension StatusSection {
// configure cell // configure cell
configureStatusTableViewCell( configureStatusTableViewCell(
cell: cell, cell: cell,
tableView: tableView,
dependency: dependency, dependency: dependency,
readableLayoutFrame: tableView.readableContentGuide.layoutFrame, readableLayoutFrame: tableView.readableContentGuide.layoutFrame,
status: status, status: status,
@ -109,6 +110,7 @@ extension StatusSection {
let status = managedObjectContext.object(with: objectID) as! Status let status = managedObjectContext.object(with: objectID) as! Status
StatusSection.configure( StatusSection.configure(
cell: cell, cell: cell,
tableView: tableView,
dependency: dependency, dependency: dependency,
readableLayoutFrame: tableView.readableContentGuide.layoutFrame, readableLayoutFrame: tableView.readableContentGuide.layoutFrame,
status: status, status: status,
@ -189,6 +191,7 @@ extension StatusSection {
static func configureStatusTableViewCell( static func configureStatusTableViewCell(
cell: StatusTableViewCell, cell: StatusTableViewCell,
tableView: UITableView,
dependency: NeedsDependency, dependency: NeedsDependency,
readableLayoutFrame: CGRect?, readableLayoutFrame: CGRect?,
status: Status, status: Status,
@ -197,6 +200,7 @@ extension StatusSection {
) { ) {
configure( configure(
cell: cell, cell: cell,
tableView: tableView,
dependency: dependency, dependency: dependency,
readableLayoutFrame: readableLayoutFrame, readableLayoutFrame: readableLayoutFrame,
status: status, status: status,
@ -207,6 +211,7 @@ extension StatusSection {
static func configure( static func configure(
cell: StatusCell, cell: StatusCell,
tableView: UITableView,
dependency: NeedsDependency, dependency: NeedsDependency,
readableLayoutFrame: CGRect?, readableLayoutFrame: CGRect?,
status: Status, status: Status,
@ -253,6 +258,7 @@ extension StatusSection {
StatusSection.configureContentWarningOverlay( StatusSection.configureContentWarningOverlay(
statusView: cell.statusView, statusView: cell.statusView,
status: status, status: status,
tableView: tableView,
attribute: statusItemAttribute, attribute: statusItemAttribute,
documentStore: dependency.context.documentStore, documentStore: dependency.context.documentStore,
animated: false animated: false
@ -313,8 +319,9 @@ extension StatusSection {
.receive(on: RunLoop.main) .receive(on: RunLoop.main)
.sink { _ in .sink { _ in
// do nothing // do nothing
} receiveValue: { [weak cell] change in } receiveValue: { [weak cell, weak tableView] change in
guard let cell = cell else { return } guard let cell = cell else { return }
guard let tableView = tableView else { return }
guard case .update(let object) = change.changeType, guard case .update(let object) = change.changeType,
let status = object as? Status, !status.isDeleted else { let status = object as? Status, !status.isDeleted else {
return return
@ -323,6 +330,7 @@ extension StatusSection {
StatusSection.configureContentWarningOverlay( StatusSection.configureContentWarningOverlay(
statusView: cell.statusView, statusView: cell.statusView,
status: status, status: status,
tableView: tableView,
attribute: statusItemAttribute, attribute: statusItemAttribute,
documentStore: dependency.context.documentStore, documentStore: dependency.context.documentStore,
animated: true animated: true
@ -343,6 +351,7 @@ extension StatusSection {
static func configureContentWarningOverlay( static func configureContentWarningOverlay(
statusView: StatusView, statusView: StatusView,
status: Status, status: Status,
tableView: UITableView,
attribute: Item.StatusAttribute, attribute: Item.StatusAttribute,
documentStore: DocumentStore, documentStore: DocumentStore,
animated: Bool animated: Bool
@ -370,13 +379,25 @@ extension StatusSection {
statusView.playerContainerView.contentWarningOverlayView.isHidden = true statusView.playerContainerView.contentWarningOverlayView.isHidden = true
if let revealedAt = status.revealedAt, revealedAt > appStartUpTimestamp { if let revealedAt = status.revealedAt, revealedAt > appStartUpTimestamp {
statusView.updateRevealContentWarningButton(isRevealing: true)
statusView.updateContentWarningDisplay(isHidden: true, animated: animated)
attribute.isRevealing.value = true attribute.isRevealing.value = true
statusView.updateRevealContentWarningButton(isRevealing: true)
statusView.updateContentWarningDisplay(isHidden: true, animated: animated) { [weak tableView] in
guard animated else { return }
DispatchQueue.main.async {
tableView?.beginUpdates()
tableView?.endUpdates()
}
}
} else { } else {
statusView.updateRevealContentWarningButton(isRevealing: false)
statusView.updateContentWarningDisplay(isHidden: false, animated: animated)
attribute.isRevealing.value = false attribute.isRevealing.value = false
statusView.updateRevealContentWarningButton(isRevealing: false)
statusView.updateContentWarningDisplay(isHidden: false, animated: animated) { [weak tableView] in
guard animated else { return }
DispatchQueue.main.async {
tableView?.beginUpdates()
tableView?.endUpdates()
}
}
} }
case .media(let isSensitive): case .media(let isSensitive):
if !isSensitive, documentStore.defaultRevealStatusDict[status.id] == nil { if !isSensitive, documentStore.defaultRevealStatusDict[status.id] == nil {
@ -410,6 +431,7 @@ extension StatusSection {
statusView.playerContainerView.contentWarningOverlayView.update(isRevealing: false, style: .media) statusView.playerContainerView.contentWarningOverlayView.update(isRevealing: false, style: .media)
} }
} }
if animated { if animated {
UIView.animate(withDuration: 0.33, delay: 0, options: .curveEaseInOut) { UIView.animate(withDuration: 0.33, delay: 0, options: .curveEaseInOut) {
updateContentOverlay() updateContentOverlay()

View File

@ -349,7 +349,7 @@ extension StatusView {
contentWarningOverlayView.translatesAutoresizingMaskIntoConstraints = false contentWarningOverlayView.translatesAutoresizingMaskIntoConstraints = false
containerStackView.addSubview(contentWarningOverlayView) containerStackView.addSubview(contentWarningOverlayView)
NSLayoutConstraint.activate([ NSLayoutConstraint.activate([
statusContainerStackView.topAnchor.constraint(equalTo: contentWarningOverlayView.topAnchor).priority(.defaultHigh), statusContainerStackView.topAnchor.constraint(equalTo: contentWarningOverlayView.topAnchor).priority(.defaultHigh + 10),
statusContainerStackView.leftAnchor.constraint(equalTo: contentWarningOverlayView.leftAnchor).priority(.defaultHigh), statusContainerStackView.leftAnchor.constraint(equalTo: contentWarningOverlayView.leftAnchor).priority(.defaultHigh),
contentWarningOverlayView.rightAnchor.constraint(equalTo: statusContainerStackView.rightAnchor).priority(.defaultHigh), contentWarningOverlayView.rightAnchor.constraint(equalTo: statusContainerStackView.rightAnchor).priority(.defaultHigh),
contentWarningOverlayView.bottomAnchor.constraint(equalTo: statusContainerStackView.bottomAnchor).priority(.defaultHigh), contentWarningOverlayView.bottomAnchor.constraint(equalTo: statusContainerStackView.bottomAnchor).priority(.defaultHigh),
@ -412,6 +412,7 @@ extension StatusView {
containerStackView.addArrangedSubview(actionToolbarContainer) containerStackView.addArrangedSubview(actionToolbarContainer)
containerStackView.sendSubviewToBack(actionToolbarContainer) containerStackView.sendSubviewToBack(actionToolbarContainer)
actionToolbarContainer.setContentCompressionResistancePriority(.defaultLow, for: .vertical) actionToolbarContainer.setContentCompressionResistancePriority(.defaultLow, for: .vertical)
actionToolbarContainer.setContentHuggingPriority(.required - 1, for: .vertical)
headerContainerView.isHidden = true headerContainerView.isHidden = true
statusMosaicImageViewContainer.isHidden = true statusMosaicImageViewContainer.isHidden = true
@ -445,22 +446,24 @@ extension StatusView {
extension StatusView { extension StatusView {
func updateContentWarningDisplay(isHidden: Bool, animated: Bool) { func updateContentWarningDisplay(isHidden: Bool, animated: Bool, completion: (() -> Void)? = nil) {
func updateOverlayView() { func updateOverlayView() {
contentWarningOverlayView.contentOverlayView.alpha = isHidden ? 0 : 1 contentWarningOverlayView.contentOverlayView.alpha = isHidden ? 0 : 1
contentWarningOverlayView.isUserInteractionEnabled = !isHidden contentWarningOverlayView.isUserInteractionEnabled = !isHidden
} }
contentWarningOverlayView.blurContentWarningTitleLabel.isHidden = isHidden
if animated { if animated {
let animator = UIViewPropertyAnimator(duration: 0.33, curve: .easeInOut) { UIView.animate(withDuration: 0.33, delay: 0, options: .curveEaseInOut) {
updateOverlayView() updateOverlayView()
} completion: { _ in
completion!()
} }
animator.startAnimation()
} else { } else {
updateOverlayView() updateOverlayView()
completion?()
} }
contentWarningOverlayView.blurContentWarningTitleLabel.isHidden = isHidden
} }
func updateRevealContentWarningButton(isRevealing: Bool) { func updateRevealContentWarningButton(isRevealing: Bool) {