forked from shadowfacts/Tusker
Fix multi column navigation not animating when scrolling back while replacing multiple columns
This commit is contained in:
parent
dcc5f7f716
commit
412c5ee91d
|
@ -17,7 +17,6 @@ protocol MultiColumnNavigationCustomTargetProviding {
|
||||||
|
|
||||||
class MultiColumnNavigationController: UIViewController {
|
class MultiColumnNavigationController: UIViewController {
|
||||||
|
|
||||||
private var isManuallyUpdating = false
|
|
||||||
private var _viewControllers: [UIViewController] = []
|
private var _viewControllers: [UIViewController] = []
|
||||||
var viewControllers: [UIViewController] {
|
var viewControllers: [UIViewController] {
|
||||||
get {
|
get {
|
||||||
|
@ -25,8 +24,7 @@ class MultiColumnNavigationController: UIViewController {
|
||||||
}
|
}
|
||||||
set {
|
set {
|
||||||
_viewControllers = newValue
|
_viewControllers = newValue
|
||||||
if isViewLoaded,
|
if isViewLoaded {
|
||||||
!isManuallyUpdating {
|
|
||||||
updateViews()
|
updateViews()
|
||||||
scrollToEnd(animated: false)
|
scrollToEnd(animated: false)
|
||||||
}
|
}
|
||||||
|
@ -143,7 +141,14 @@ class MultiColumnNavigationController: UIViewController {
|
||||||
}
|
}
|
||||||
|
|
||||||
private func scrollColumnToEnd(columnIndex: Int, animated: Bool) {
|
private func scrollColumnToEnd(columnIndex: Int, animated: Bool) {
|
||||||
|
// Laying out may change the content offset if we have fewer columns than before,
|
||||||
|
// but we want to keep the original offset so that we can animate smoothly to the final one.
|
||||||
|
let origContentOffset = scrollView.contentOffset
|
||||||
scrollView.layoutIfNeeded()
|
scrollView.layoutIfNeeded()
|
||||||
|
if animated {
|
||||||
|
scrollView.contentOffset = origContentOffset
|
||||||
|
}
|
||||||
|
|
||||||
let column = stackView.arrangedSubviews[columnIndex]
|
let column = stackView.arrangedSubviews[columnIndex]
|
||||||
let columnFrame = column.convert(column.bounds, to: scrollView)
|
let columnFrame = column.convert(column.bounds, to: scrollView)
|
||||||
let offset: CGFloat
|
let offset: CGFloat
|
||||||
|
|
Loading…
Reference in New Issue