Fix tablel view cells being re-selected on aborted nav swipe back

This commit is contained in:
Shadowfacts 2019-12-14 11:59:31 -05:00
parent c26657bafa
commit eb6cfba9aa
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
13 changed files with 93 additions and 95 deletions

View File

@ -76,6 +76,7 @@
D61AC1D5232E9FA600C54D2D /* InstanceSelectorTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D61AC1D4232E9FA600C54D2D /* InstanceSelectorTableViewController.swift */; };
D61AC1D8232EA42D00C54D2D /* InstanceTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D61AC1D6232EA42D00C54D2D /* InstanceTableViewCell.swift */; };
D61AC1D9232EA42D00C54D2D /* InstanceTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = D61AC1D7232EA42D00C54D2D /* InstanceTableViewCell.xib */; };
D627943223A5466600D38C68 /* SelectableTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D627943123A5466600D38C68 /* SelectableTableViewCell.swift */; };
D627FF76217E923E00CC0648 /* DraftsManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = D627FF75217E923E00CC0648 /* DraftsManager.swift */; };
D627FF79217E950100CC0648 /* DraftsTableViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = D627FF78217E950100CC0648 /* DraftsTableViewController.xib */; };
D627FF7B217E951500CC0648 /* DraftsTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D627FF7A217E951500CC0648 /* DraftsTableViewController.swift */; };
@ -339,6 +340,7 @@
D61AC1D4232E9FA600C54D2D /* InstanceSelectorTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceSelectorTableViewController.swift; sourceTree = "<group>"; };
D61AC1D6232EA42D00C54D2D /* InstanceTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceTableViewCell.swift; sourceTree = "<group>"; };
D61AC1D7232EA42D00C54D2D /* InstanceTableViewCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = InstanceTableViewCell.xib; sourceTree = "<group>"; };
D627943123A5466600D38C68 /* SelectableTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SelectableTableViewCell.swift; sourceTree = "<group>"; };
D627FF75217E923E00CC0648 /* DraftsManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DraftsManager.swift; sourceTree = "<group>"; };
D627FF78217E950100CC0648 /* DraftsTableViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = DraftsTableViewController.xib; sourceTree = "<group>"; };
D627FF7A217E951500CC0648 /* DraftsTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DraftsTableViewController.swift; sourceTree = "<group>"; };
@ -1074,6 +1076,7 @@
D6C693F82162E4DB007D6A6D /* StatusContentLabel.swift */,
D641C77E213DC78A004B4513 /* InlineTextAttachment.swift */,
04ED00B021481ED800567C53 /* SteppedProgressView.swift */,
D627943123A5466600D38C68 /* SelectableTableViewCell.swift */,
D67C57A721E2649B00C3118B /* Account Detail */,
D67C57B021E28F9400C3118B /* Compose Status Reply */,
D60C07E221E817560057FAA8 /* Compose Media */,
@ -1603,6 +1606,7 @@
D6AEBB4A23216F0400E5038B /* UnfollowAccountActivity.swift in Sources */,
D663626421360D2300C9CBA2 /* AvatarStyle.swift in Sources */,
D679C09F215850EF00DA27FE /* XCBActions.swift in Sources */,
D627943223A5466600D38C68 /* SelectableTableViewCell.swift in Sources */,
D6DD353F22F502EC00A9563A /* Preferences+Notification.swift in Sources */,
D63661C02381C144004B9E16 /* PreferencesNavigationController.swift in Sources */,
D6AEBB4523216AF800E5038B /* FollowAccountActivity.swift in Sources */,

View File

@ -113,10 +113,7 @@ class ConversationTableViewController: EnhancedTableViewController {
}
}
override func tableView(_ tableView: UITableView, willSelectRowAt indexPath: IndexPath) -> IndexPath? {
let statusID = statuses[indexPath.row].id
return statusID == mainStatusID ? nil : indexPath
}
// MARK: - Table view delegate
override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
return true

View File

@ -109,6 +109,7 @@ class NotificationsTableViewController: EnhancedTableViewController {
}
}
// MARK: - Table view delegate
override func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
if indexPath.row == groups.count - 1 {

View File

@ -51,12 +51,10 @@ class InstanceSelectorTableViewController: UITableViewController {
case let .selected(instance):
let cell = tableView.dequeueReusableCell(withIdentifier: instanceCell, for: indexPath) as! InstanceTableViewCell
cell.updateUI(instance: instance)
cell.delegate = self
return cell
case let .recommended(instance):
let cell = tableView.dequeueReusableCell(withIdentifier: instanceCell, for: indexPath) as! InstanceTableViewCell
cell.updateUI(instance: instance)
cell.delegate = self
return cell
}
})
@ -135,6 +133,23 @@ class InstanceSelectorTableViewController: UITableViewController {
self.dataSource.apply(snapshot)
}
}
// MARK: - Table view delegate
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
guard let delegate = delegate, let item = dataSource.itemIdentifier(for: indexPath) else {
return
}
switch item {
case let .selected(instance):
delegate.didSelectInstance(url: URL(string: instance.uri)!)
case let .recommended(instance):
var components = URLComponents()
components.scheme = "https"
components.host = instance.domain
components.path = "/"
delegate.didSelectInstance(url: components.url!)
}
}
}
extension InstanceSelectorTableViewController {
@ -179,16 +194,3 @@ extension InstanceSelectorTableViewController: UISearchResultsUpdating {
urlCheckerSubject.send(currentQuery)
}
}
extension InstanceSelectorTableViewController: InstanceTableViewCellDelegate {
func didSelectInstance(_ instance: Instance) {
delegate?.didSelectInstance(url: URL(string: instance.uri)!)
}
func didSelectInstance(_ instance: InstanceSelector.Instance) {
var components = URLComponents()
components.scheme = "https"
components.host = instance.domain
components.path = "/"
delegate?.didSelectInstance(url: components.url!)
}
}

View File

@ -180,6 +180,8 @@ class ProfileTableViewController: EnhancedTableViewController {
}
}
// MARK: - Table view delegate
override func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
if timelineSegments.count > 0 && indexPath.section - 1 == timelineSegments.count && indexPath.row == timelineSegments[indexPath.section - 2].count - 1 {
guard let older = older else { return }

View File

@ -35,6 +35,13 @@ class EnhancedTableViewController: UITableViewController {
override func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
prevScrollToTopOffset = nil
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if let cell = tableView.cellForRow(at: indexPath) as? SelectableTableViewCell {
cell.didSelectCell()
}
}
}

View File

@ -56,14 +56,12 @@ class AccountTableViewCell: UITableViewCell {
updateUIForPrefrences()
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
}
if selected {
delegate?.selected(account: accountID)
}
extension AccountTableViewCell: SelectableTableViewCell {
func didSelectCell() {
delegate?.selected(account: accountID)
}
}
extension AccountTableViewCell: MenuPreviewProvider {

View File

@ -23,12 +23,10 @@ class HashtagTableViewCell: UITableViewCell {
hashtagLabel.text = "#\(hashtag.name)"
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
if selected {
delegate?.selected(tag: hashtag)
}
}
}
extension HashtagTableViewCell: SelectableTableViewCell {
func didSelectCell() {
delegate?.selected(tag: hashtag)
}
}

View File

@ -9,15 +9,8 @@
import UIKit
import Pachyderm
protocol InstanceTableViewCellDelegate {
func didSelectInstance(_ instance: Instance)
func didSelectInstance(_ instance: InstanceSelector.Instance)
}
class InstanceTableViewCell: UITableViewCell {
var delegate: InstanceTableViewCellDelegate?
@IBOutlet weak var thumbnailImageView: UIImageView!
@IBOutlet weak var domainLabel: UILabel!
@IBOutlet weak var adultLabel: UILabel!
@ -74,16 +67,4 @@ class InstanceTableViewCell: UITableViewCell {
}
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
if selected, let delegate = delegate {
if let instance = instance {
delegate.didSelectInstance(instance)
} else if let instance = selectorInstance {
delegate.didSelectInstance(instance)
}
}
}
}

View File

@ -149,29 +149,28 @@ class ActionNotificationGroupTableViewCell: UITableViewCell {
updateTimestampWorkItem?.cancel()
updateTimestampWorkItem = nil
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
if selected, let delegate = delegate {
let notifications = group.notificationIDs.compactMap(MastodonCache.notification(for:))
let accountIDs = notifications.map { $0.account.id }
let action: StatusActionAccountListTableViewController.ActionType
switch notifications.first!.kind {
case .favourite:
action = .favorite
case .reblog:
action = .reblog
default:
fatalError()
}
let vc = delegate.statusActionAccountList(action: action, statusID: statusID, statusState: .unknown, accountIDs: accountIDs)
delegate.show(vc)
}
}
}
extension ActionNotificationGroupTableViewCell: SelectableTableViewCell {
func didSelectCell() {
guard let delegate = delegate else { return }
let notifications = group.notificationIDs.compactMap(MastodonCache.notification(for:))
let accountIDs = notifications.map { $0.account.id }
let action: StatusActionAccountListTableViewController.ActionType
switch notifications.first!.kind {
case .favourite:
action = .favorite
case .reblog:
action = .reblog
default:
fatalError()
}
let vc = delegate.statusActionAccountList(action: action, statusID: statusID, statusState: .unknown, accountIDs: accountIDs)
delegate.show(vc)
}
}
extension ActionNotificationGroupTableViewCell: MenuPreviewProvider {
func getPreviewProviders(for location: CGPoint, sourceViewController: UIViewController) -> PreviewProviders? {

View File

@ -112,23 +112,21 @@ class FollowNotificationGroupTableViewCell: UITableViewCell {
updateTimestampWorkItem?.cancel()
updateTimestampWorkItem = nil
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
if selected {
let people = group.notificationIDs.compactMap(MastodonCache.notification(for:)).map { $0.account.id }
switch people.count {
case 0:
return
case 1:
delegate?.selected(account: people.first!)
default:
delegate?.showFollowedByList(accountIDs: people)
}
}
extension FollowNotificationGroupTableViewCell: SelectableTableViewCell {
func didSelectCell() {
let people = group.notificationIDs.compactMap(MastodonCache.notification(for:)).map { $0.account.id }
switch people.count {
case 0:
return
case 1:
delegate?.selected(account: people.first!)
default:
delegate?.showFollowedByList(accountIDs: people)
}
}
}
extension FollowNotificationGroupTableViewCell: MenuPreviewProvider {

View File

@ -0,0 +1,13 @@
//
// SelectableTableViewCell.swift
// Tusker
//
// Created by Shadowfacts on 12/14/19.
// Copyright © 2019 Shadowfacts. All rights reserved.
//
import UIKit
protocol SelectableTableViewCell {
func didSelectCell()
}

View File

@ -119,14 +119,6 @@ class TimelineStatusTableViewCell: BaseStatusTableViewCell {
showPinned = false
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
if selected {
delegate?.selected(status: statusID, state: statusState.copy())
}
}
@objc func reblogLabelPressed() {
guard let rebloggerID = rebloggerID else { return }
delegate?.selected(account: rebloggerID)
@ -141,6 +133,12 @@ class TimelineStatusTableViewCell: BaseStatusTableViewCell {
}
extension TimelineStatusTableViewCell: SelectableTableViewCell {
func didSelectCell() {
delegate?.selected(status: statusID, state: statusState.copy())
}
}
extension TimelineStatusTableViewCell: TableViewSwipeActionProvider {
func leadingSwipeActionsConfiguration() -> UISwipeActionsConfiguration? {