Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Helps to navigate to top or bottom of the inline row #1166

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions Source/Core/BaseRow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,21 @@ open class BaseRow: BaseRowType {
self.tag = tag
}


/**
Scrolls to a wanted part of the view
Usage :
override this method somewhere in new class.

//isScrollToTop
open override func isScrollToTop() -> Bool {
return true
}
*/
open func isScrollToTop() -> Bool {
return false
}

/**
Method that reloads the cell
*/
Expand Down
4 changes: 2 additions & 2 deletions Source/Core/Core.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1043,10 +1043,10 @@ extension FormViewControllerProtocol {

// MARK: Helpers

func makeRowVisible(_ row: BaseRow) {
func makeRowVisible(_ row: BaseRow, _ isScrollToTop:Bool){
guard let cell = row.baseCell, let indexPath = row.indexPath, let tableView = tableView else { return }
if cell.window == nil || (tableView.contentOffset.y + tableView.frame.size.height <= cell.frame.origin.y + cell.frame.size.height) {
tableView.scrollToRow(at: indexPath, at: .bottom, animated: true)
tableView.scrollToRow(at: indexPath, at: isScrollToTop ? .top :.bottom, animated: true)
}
}
}
3 changes: 2 additions & 1 deletion Source/Core/InlineRowType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ extension InlineRowType where Self: BaseRow, Self.Cell.Value == Self.InlineRow.
if let indexPath = indexPath {
_inlineRow = inline
section.insert(inline, at: indexPath.row + 1)
cell.formViewController()?.makeRowVisible(inline)
let stt = isScrollToTop()
cell.formViewController()?.makeRowVisible(inline,stt)
}
}
}
Expand Down