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

fix(IndexBar): allow active bottom anchor #10404

Merged
merged 3 commits into from Mar 18, 2022

Conversation

nemo-shen
Copy link
Contributor

#10342

原因分析

原先的逻辑是通过滚动后触发 onScroll,再根据 rect.top 距离来判断匹配的 Anchor

而实际上,最大的滚动的距离是 整个文档滚动高度 - 当前屏幕窗口高度,因此当文档滚动高度超过屏幕窗口高度时,点击最底部的 Anchor 无法触发 onScroll 事件,也就无法点亮对应的 Anchor

另外一种情况是,初始位置在 A 直接点击 Z,此时的确会触发 onScroll 事件,但如果 Z 对应的内容不足一屏,则会导致 Z 的下标无法滚动到顶部,也就无法被正确匹配到,最终可能是选中 Y

处理思路

针对这两种情况分别做处理:
情况一: 判断是否 当前滚动距离 === 当前文档最大滚动距离,如果满足则表示无法继续滚动触发 onScroll,则通过手动触发。

情况二: 在触发点击或触摸滑动选择 Anchor 时,记录当前正确的 selectActiveIndex,触发 onScroll 事件时,通过 selectActiveIndex 获取到正确的下标。

调整后效果

CleanShot-20220317234348 png@2x
CleanShot-20220317234407 png@2x

@chenjiahan chenjiahan merged commit 7c00cea into youzan:dev Mar 18, 2022
@chenjiahan
Copy link
Member

🐂🐂

@chenjiahan
Copy link
Member

image

试了下这块高亮效果挺奇怪的,anchor 和 cell 融合在了一起,看起来像是 UI bug

@nemo-shen
Copy link
Contributor Author

对的,我当时也觉得挺奇怪的😂

@nemo-shen nemo-shen deleted the hotfix/index-bar_0317 branch March 18, 2022 01:51
@chenjiahan
Copy link
Member

对的,我当时也觉得挺奇怪的😂

因为正常来说 active 的 anchor 只会出现在顶部,像这种在页面中间的 anchor 我们是不希望 active 显示的,最好能去掉

@M69W
Copy link

M69W commented Jul 29, 2022

对的,我当时也觉得挺奇怪的😂

因为正常来说 active 的 anchor 只会出现在顶部,像这种在页面中间的 anchor 我们是不希望 active 显示的,最好能去掉

点击右边的索引列表,能高亮当前点击的 anchor
V3V4
同样的效果是否可以同步到 V2?

@chenjiahan
Copy link
Member

image

@M69W
Copy link

M69W commented Jul 29, 2022

理解
可以这么理解第三点:是否以个人的形式把这部分代码提交到 V2分支?

@chenjiahan
Copy link
Member

可以的,我们会进行 review 和 merge

@LeoWangJ
Copy link

在該情况一: 判断是否 当前滚动距离 === 当前文档最大滚动距离,如果满足则表示无法继续滚动触发 onScroll,则通过手动触发。

截圖 2022-08-10 上午10 47 29
情况一的修改中 return 使下方 code 無法繼續執行,這導致了滑到最底部時, 即 当前滚动距离 === 当前文档最大滚动距离 無法觸發 match.$el.scrollIntoView(),使得點擊上方字母時無法正確定位。
如下方影片所示,使用官方文檔 IndexBar 滑到最底部時,再點擊H字母,此時高亮 H 字母,但並未正常定位到 H 區塊

2022-08-10.10.58.00.mov

想請問的是這個 return 是否必須存在?

@chenjiahan
Copy link
Member

@LeoWangJ 可以单独开个 issue 哈

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants