scroll to row index logic added
This commit is contained in:
parent
773410168c
commit
7f5b2cc78b
@ -18,6 +18,7 @@ import Foundation
|
||||
}
|
||||
public var molecules: [ListItemModelProtocol & MoleculeModelProtocol]?
|
||||
public var line: LineModel?
|
||||
public var scrollToRowIndex: Int?
|
||||
|
||||
/// This template requires content.
|
||||
func validateModelHasContent() throws {
|
||||
@ -45,6 +46,7 @@ import Foundation
|
||||
private enum CodingKeys: String, CodingKey {
|
||||
case molecules
|
||||
case line
|
||||
case scrollToRowIndex
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
@ -55,6 +57,7 @@ import Foundation
|
||||
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
|
||||
molecules = try typeContainer.decodeModelsIfPresent(codingKey: .molecules)
|
||||
line = try typeContainer.decodeIfPresent(LineModel.self, forKey: .line)
|
||||
scrollToRowIndex = try typeContainer.decodeIfPresent(Int.self, forKey: .scrollToRowIndex)
|
||||
try super.init(from: decoder)
|
||||
try validateModelHasContent()
|
||||
}
|
||||
@ -64,6 +67,7 @@ import Foundation
|
||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||
try container.encodeModelsIfPresent(molecules, forKey: .molecules)
|
||||
try container.encode(line, forKey: .line)
|
||||
try container.encode(scrollToRowIndex, forKey: .scrollToRowIndex)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -81,6 +81,27 @@ open class MoleculeListTemplate: ThreeLayerTableViewController, TemplateProtocol
|
||||
super.handleNewData()
|
||||
}
|
||||
|
||||
open override func viewDidAppear(_ animated: Bool) {
|
||||
super.viewDidAppear(animated)
|
||||
//Handle scroll
|
||||
handleScrollToSpecificRow()
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Handle scroll to spefic row
|
||||
//--------------------------------------------------
|
||||
func handleScrollToSpecificRow() {
|
||||
guard let index = templateModel?.scrollToRowIndex,
|
||||
loadObject?.pageDataFromCache == false,
|
||||
let table = tableView,
|
||||
index < tableView(table, numberOfRowsInSection:0) else { return }
|
||||
let indexPath = IndexPath(row: index, section: 0)
|
||||
tableView?.scrollToRow(at: indexPath, at: .middle, animated: false)
|
||||
//Reset for without refresh page not needed
|
||||
templateModel?.scrollToRowIndex = nil
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Table View
|
||||
//--------------------------------------------------
|
||||
|
||||
Loading…
Reference in New Issue
Block a user