Merge branch 'bugfix/table_refresh_crash' into 'develop'

Move dispatch to always happen for refresh

See merge request BPHV_MIPS/mvm_core_ui!747
This commit is contained in:
Pfeil, Scott Robert 2021-08-03 13:18:54 +00:00
commit 50d30b08e5
4 changed files with 21 additions and 30 deletions

View File

@ -173,11 +173,6 @@ open class MoleculeListTemplate: ThreeLayerTableViewController, TemplateProtocol
cell.didDeselectCell(at: indexPath, delegateObject: delegateObject() as? MVMCoreUIDelegateObject, additionalData: nil)
}
func performTableViewUpdates() {
tableView.beginUpdates()
tableView.endUpdates()
}
//--------------------------------------------------
// MARK: - MoleculeDelegateProtocol
//--------------------------------------------------
@ -187,7 +182,7 @@ open class MoleculeListTemplate: ThreeLayerTableViewController, TemplateProtocol
let point = molecule.convert(molecule.bounds.origin, to: tableView)
if let indexPath = tableView.indexPathForRow(at: point), tableView.indexPathsForVisibleRows?.contains(indexPath) ?? false {
performTableViewUpdates()
refreshTable()
}
}
@ -305,25 +300,22 @@ extension MoleculeListTemplate: MoleculeListProtocol {
}
open func addMolecules(_ molecules: [ListItemModelProtocol & MoleculeModelProtocol], indexPath: IndexPath, animation: UITableView.RowAnimation?) {
// This dispatch is needed to fix a race condition that can occur if this function is called during the table setup.
DispatchQueue.main.async {
var indexPaths: [IndexPath] = []
var indexPaths: [IndexPath] = []
for molecule in molecules {
if let info = self.createMoleculeInfo(with: molecule) {
self.tableView?.register(info.class, forCellReuseIdentifier: info.identifier)
let index = indexPath.row + indexPaths.count
self.moleculesInfo?.insert(info, at: index)
indexPaths.append(IndexPath(row: index, section: 0))
}
for molecule in molecules {
if let info = self.createMoleculeInfo(with: molecule) {
self.tableView?.register(info.class, forCellReuseIdentifier: info.identifier)
let index = indexPath.row + indexPaths.count
self.moleculesInfo?.insert(info, at: index)
indexPaths.append(IndexPath(row: index, section: 0))
}
guard let animation = animation,
indexPaths.count > 0 else { return }
self.tableView?.insertRows(at: indexPaths, with: animation)
self.updateViewConstraints()
self.view.layoutIfNeeded()
}
guard let animation = animation,
indexPaths.count > 0 else { return }
self.tableView?.insertRows(at: indexPaths, with: animation)
self.updateViewConstraints()
self.view.layoutIfNeeded()
}
open func getIndexPath(for molecule: ListItemModelProtocol & MoleculeModelProtocol) -> IndexPath? {

View File

@ -83,8 +83,11 @@ open class ProgrammaticTableViewController: ProgrammaticScrollViewController, UI
}
open func refreshTable() {
tableView.beginUpdates()
tableView.endUpdates()
// Perform asyncronously to ensure it can never run in the same process as table data updates.
DispatchQueue.main.async { [self] in
tableView.beginUpdates()
tableView.endUpdates()
}
}
/// For subclassing, returns the number of sections for table. This function calls numberOfSectionsForTableview aftre ensuring the table is setup properly.

View File

@ -132,9 +132,7 @@ open class ThreeLayerTableViewController: ProgrammaticTableViewController {
bottomViewTopConstraint?.constant = newSpace
showFooter(width)
}
DispatchQueue.main.async {
self.refreshTable()
}
refreshTable()
}
super.updateViewConstraints()
}

View File

@ -270,9 +270,7 @@ import UIKit
bottomBar?.frame = CGRect(x: 0, y: bounds.height - size, width: bounds.width, height: size)
if updateMoleculeLayout || heightChanged {
DispatchQueue.main.async { [self] in
delegateObject?.moleculeDelegate?.moleculeLayoutUpdated(self)
}
delegateObject?.moleculeDelegate?.moleculeLayoutUpdated(self)
}
setNeedsDisplay()