Attempt to fix initial positioning when content is smaller than screen size

This commit is contained in:
Peter 2019-05-01 17:17:38 +04:00
parent 6d3d242c1a
commit febf3d3f0e

View File

@ -828,9 +828,13 @@ open class ListView: ASDisplayNode, UIScrollViewAccessibilityDelegate, UIGesture
case let .Spring(duration): case let .Spring(duration):
transition = .animated(duration: duration, curve: .spring) transition = .animated(duration: duration, curve: .spring)
case let .Default(duration): case let .Default(duration):
if let duration = duration, duration.isZero {
transition = .immediate
} else {
transition = .animated(duration: duration ?? 0.3, curve: .easeInOut) transition = .animated(duration: duration ?? 0.3, curve: .easeInOut)
} }
} }
}
var offset: CGFloat = 0.0 var offset: CGFloat = 0.0
if topItemFound && bottomItemFound { if topItemFound && bottomItemFound {
@ -854,7 +858,11 @@ open class ListView: ASDisplayNode, UIScrollViewAccessibilityDelegate, UIGesture
} else { } else {
let areaHeight = min(completeHeight, visibleAreaHeight) let areaHeight = min(completeHeight, visibleAreaHeight)
if bottomItemEdge < effectiveInsets.top + areaHeight - overscroll { if bottomItemEdge < effectiveInsets.top + areaHeight - overscroll {
if snapTopItem && topItemEdge < effectiveInsets.top {
offset = (effectiveInsets.top - overscroll) - topItemEdge
} else {
offset = effectiveInsets.top + areaHeight - overscroll - bottomItemEdge offset = effectiveInsets.top + areaHeight - overscroll - bottomItemEdge
}
} else if topItemEdge > effectiveInsets.top - overscroll && /*snapTopItem*/ true { } else if topItemEdge > effectiveInsets.top - overscroll && /*snapTopItem*/ true {
offset = (effectiveInsets.top - overscroll) - topItemEdge offset = (effectiveInsets.top - overscroll) - topItemEdge
} }
@ -3235,7 +3243,12 @@ open class ListView: ASDisplayNode, UIScrollViewAccessibilityDelegate, UIGesture
let minIndicatorHeight: CGFloat = 6.0 let minIndicatorHeight: CGFloat = 6.0
let visibleHeightWithoutIndicatorInsets = self.visibleSize.height - self.scrollIndicatorInsets.top - self.scrollIndicatorInsets.bottom - indicatorTopInset - indicatorBottomInset let visibleHeightWithoutIndicatorInsets = self.visibleSize.height - self.scrollIndicatorInsets.top - self.scrollIndicatorInsets.bottom - indicatorTopInset - indicatorBottomInset
let indicatorHeight: CGFloat = max(minIndicatorContentHeight, floor(visibleHeightWithoutIndicatorInsets * (self.visibleSize.height - self.insets.top - self.insets.bottom) / approximateContentHeight)) let indicatorHeight: CGFloat
if approximateContentHeight <= 0 {
indicatorHeight = 0.0
} else {
indicatorHeight = max(minIndicatorContentHeight, floor(visibleHeightWithoutIndicatorInsets * (self.visibleSize.height - self.insets.top - self.insets.bottom) / approximateContentHeight))
}
let upperBound = self.scrollIndicatorInsets.top + indicatorTopInset let upperBound = self.scrollIndicatorInsets.top + indicatorTopInset
let lowerBound = self.visibleSize.height - self.scrollIndicatorInsets.bottom - indicatorTopInset - indicatorBottomInset - indicatorHeight let lowerBound = self.visibleSize.height - self.scrollIndicatorInsets.bottom - indicatorTopInset - indicatorBottomInset - indicatorHeight