Skip to content

Commit e83010e

Browse files
committed
fix(IndexList): 修复点击 Sidebar 后滚动页面无法改变选中位置的问题
close #1078
1 parent 1447a72 commit e83010e

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

src/index-list/index.js

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const defaultSidebarData = [
1313
Component({
1414

1515
externalClasses: [
16-
'l-tip-class', 'l-tip-text-class', 'l-sidebar-class', 'l-selected-class', 'l-unselected-class','l-sidebar-item-class'
16+
'l-tip-class', 'l-tip-text-class', 'l-sidebar-class', 'l-selected-class', 'l-unselected-class', 'l-sidebar-item-class'
1717
],
1818

1919
relations: {
@@ -135,7 +135,7 @@ Component({
135135
wx.lin = wx.lin || {};
136136
// 传入scrollTop的值的函数
137137
wx.lin.setScrollTop = (scrollTop) => {
138-
dataUtil.setDiffData(this, {scrollTop});
138+
dataUtil.setDiffData(this, { scrollTop });
139139
};
140140
},
141141

@@ -357,7 +357,7 @@ Component({
357357
countCurrentActiveIndex(scrollTop) {
358358
let result = 0;
359359
// 每个 Anchor 距离页面顶部的 px 值
360-
const {anchorTopLocations} = this.data._anchor;
360+
const { anchorTopLocations } = this.data._anchor;
361361

362362
for (let i = 0; i < anchorTopLocations.length; i++) {
363363
if (scrollTop + this.data._stickOffsetTopPx < anchorTopLocations[i]) {
@@ -378,19 +378,18 @@ Component({
378378
* @param event 事件对象
379379
*/
380380
onTouchMove(event) {
381-
382381
// 显示 Tip
383382
this.switchTipShow(true);
384383
// 标识正在滑动 Sidebar
385384
this.switchIsMovingSidebar(true);
386385

387386
// 取出 Sidebar 位置信息
388-
const {top: sidebarTop, sidebarItemHeight} = this.data._sidebar;
387+
const { top: sidebarTop, sidebarItemHeight } = this.data._sidebar;
389388
// Sidebar 索引个数
390389
const sidebarLength = this.data.sidebarData.length;
391390
// 触摸点 Y 坐标
392391
const touchY = event.touches[0].clientY;
393-
// 计算当前触摸点在第几个索引除
392+
// 计算当前触摸点在第几个索引处
394393
let index = Math.floor((touchY - sidebarTop) / sidebarItemHeight);
395394

396395
// 滑动超过范围时限制索引边界值
@@ -417,15 +416,24 @@ Component({
417416
scrollTop: scrollPageToLocation
418417
});
419418

419+
/**
420+
* fix issue1078
421+
* 当点击 sidebar 时,onTouchend 会先于 onTouchMove 执行
422+
* 导致滑动状态无法正常关闭,固此处添加一个延时状态修改(页面滚动需要一定时间)
423+
*/
424+
event.type === 'tap' && setTimeout(() => {
425+
this.switchIsMovingSidebar(false);
426+
}, 100);
427+
420428
// 触发 linselected 事件
421-
eventUtil.emit(this, 'linselected', {index, tipText});
429+
eventUtil.emit(this, 'linselected', { index, tipText });
422430
},
423431

424432
/**
425433
* 监听 手指触摸动作结束 事件
426434
*/
427435
onTouchend() {
428-
// 300 毫秒后隐藏 Tip
436+
// 500 毫秒后隐藏 Tip
429437
setTimeout(() => {
430438
this.switchTipShow(false);
431439
}, 500);

0 commit comments

Comments
 (0)