Skip to content

Commit

Permalink
优化列表容器生命周期方法触发
Browse files Browse the repository at this point in the history
  • Loading branch information
pujiaxin33 committed Jul 27, 2020
1 parent ddd6fb5 commit f2523cd
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions Sources/Common/JXSegmentedListContainerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,6 @@ open class JXSegmentedListContainerView: UIView, JXSegmentedViewListContainer, J
list.listView().frame = cell?.contentView.bounds ?? CGRect.zero
cell?.contentView.addSubview(list.listView())
}
listWillAppear(at: index)
}

private func listWillAppear(at index: Int) {
Expand Down Expand Up @@ -404,6 +403,9 @@ extension JXSegmentedListContainerView: UICollectionViewDataSource, UICollection
}

public func scrollViewDidScroll(_ scrollView: UIScrollView) {
guard scrollView.isTracking || scrollView.isDragging else {
return
}
let percent = scrollView.contentOffset.x/scrollView.bounds.size.width
let maxCount = Int(round(scrollView.contentSize.width/scrollView.bounds.size.width))
var leftIndex = Int(floor(Double(percent)))
Expand All @@ -415,27 +417,26 @@ extension JXSegmentedListContainerView: UICollectionViewDataSource, UICollection
let remainderRatio = percent - CGFloat(leftIndex)
if rightIndex == currentIndex {
//当前选中的在右边,用户正在从右边往左边滑动
if remainderRatio < (1 - initListPercent) {
if validListDict[leftIndex] == nil && remainderRatio < (1 - initListPercent) {
initListIfNeeded(at: leftIndex)
}
if willAppearIndex == -1 {
willAppearIndex = leftIndex;
if validListDict[leftIndex] != nil {
}else if validListDict[leftIndex] != nil {
if willAppearIndex == -1 {
willAppearIndex = leftIndex;
listWillAppear(at: willAppearIndex)
}
}

if willDisappearIndex == -1 {
willDisappearIndex = rightIndex
listWillDisappear(at: willDisappearIndex)
}
}else {
//当前选中的在左边,用户正在从左边往右边滑动
if remainderRatio > initListPercent {
if validListDict[rightIndex] == nil && remainderRatio > initListPercent {
initListIfNeeded(at: rightIndex)
}
if willAppearIndex == -1 {
willAppearIndex = rightIndex
if validListDict[rightIndex] != nil {
}else if validListDict[rightIndex] != nil {
if willAppearIndex == -1 {
willAppearIndex = rightIndex
listWillAppear(at: willAppearIndex)
}
}
Expand Down

0 comments on commit f2523cd

Please sign in to comment.