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,8 +300,6 @@ 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] = []
for molecule in molecules {
@ -324,7 +317,6 @@ extension MoleculeListTemplate: MoleculeListProtocol {
self.updateViewConstraints()
self.view.layoutIfNeeded()
}
}
open func getIndexPath(for molecule: ListItemModelProtocol & MoleculeModelProtocol) -> IndexPath? {
guard let index = moleculesInfo?.firstIndex(where: { (moleculeInfo) -> Bool in

View File

@ -83,9 +83,12 @@ open class ProgrammaticTableViewController: ProgrammaticScrollViewController, UI
}
open func refreshTable() {
// 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.
open func getNumberOfSections() -> Int { 1 }

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,10 +270,8 @@ 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)
}
}
setNeedsDisplay()
layoutIfNeeded()