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

页面生命周期未调用 #127

Open
LinBowen9656 opened this issue Sep 29, 2020 · 3 comments
Open

页面生命周期未调用 #127

LinBowen9656 opened this issue Sep 29, 2020 · 3 comments
Labels
help wanted Extra attention is needed

Comments

@LinBowen9656
Copy link

当滑动listContainer时,滑动后不立刻松手,并停在scrollview paging的临界点后松手,最后显示界面的viewDidAppear等生命周期方法未被调用,或者当页面较多时非常快速滑动多页后停下来也可以触发此BUG

@rainedAllNight
Copy link

遇到同样的问题,在快速滑动或者paging临界值快速松手会出现生命周期未按预期调用的问题,如tab 页面从左到右顺序为 A 、B,当滑动到B后,尝试向左滑到A,滑动一点距离后快速松手,由于paging的作用会回到B,这时候预期的生命周期应该是 A:WillAppear -> B: WillDisAppear, A: WillDisAppear, B:WillAppear ; 实际上会有很大概率的变成 A:WillAppear -> B: WillDisAppear, 缺少后续的生命周期调用,项目里多处使用JXSegmentedView的地方都能复现,麻烦帮忙确认下

@rainedAllNight
Copy link

大概查到了原因,JXSegmentedListContainerView中有针对滑动取消的兼容逻辑,但是只处理了取消时手放开走减速的情况,当最后取消时,通过手指拉动回来让滑动停止时,scrollViewDidEndDecelerating不会调用,因为这个时候是通过Dragging让其停止的。

public func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
//滑动到一半又取消滑动处理
if willAppearIndex != -1 || willDisappearIndex != -1 {
listWillDisappear(at: willAppearIndex)
listWillAppear(at: willDisappearIndex)
listDidDisappear(at: willAppearIndex)
listDidAppear(at: willDisappearIndex)
willDisappearIndex = -1
willAppearIndex = -1
}
}

修复建议:DidEndDragging方法也添加兼容处理,但是需要评估是否会影响其他正常的滑动逻辑
public func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) {
if decelerate {
return
}
if willAppearIndex != -1 || willDisappearIndex != -1 {
listWillDisappear(at: willAppearIndex)
listWillAppear(at: willDisappearIndex)
listDidDisappear(at: willAppearIndex)
listDidAppear(at: willDisappearIndex)
willDisappearIndex = -1
willAppearIndex = -1
}
}

@rainedAllNight
Copy link

这个只能处理临界点后松手的场景,快速滑动仍然有问题,初步判断原因是在快速滑动时,index会计算错误,导致scrollViewDidEndDecelerating里执行取消逻辑时执行的是错误的index

@pujiaxin33 pujiaxin33 added the help wanted Extra attention is needed label Jul 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants