fix(ui): TabBar 点击滑块从旧位置滑到新位置
- 点击时不再让滑块在 touchstart 直接跳到手指位置 - 拖动超过 12px 阈值后才跟手,位置统一用百分比,避免 px/calc 混用导致跳变 - 松手按命中 tab 切页,同一 tab 不重复跳转
This commit is contained in:
@@ -1,21 +1,27 @@
|
||||
import test from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
import { clampDragX, getTabBarFrame, tabIndexAtX } from '../src/custom-tab-bar/tabBarGeometry.js'
|
||||
import { clampPercent, getTabBarFrame, hasDragged, tabIndexAtPercent } from '../src/custom-tab-bar/tabBarGeometry.js'
|
||||
|
||||
test('maps a drag x to the tab under the finger', () => {
|
||||
assert.equal(tabIndexAtX(10, 100, 5), 0)
|
||||
assert.equal(tabIndexAtX(30, 100, 5), 1)
|
||||
assert.equal(tabIndexAtX(50, 100, 5), 2)
|
||||
assert.equal(tabIndexAtX(70, 100, 5), 3)
|
||||
assert.equal(tabIndexAtX(90, 100, 5), 4)
|
||||
test('maps a drag percent to the tab under the finger', () => {
|
||||
assert.equal(tabIndexAtPercent(10, 5), 0)
|
||||
assert.equal(tabIndexAtPercent(30, 5), 1)
|
||||
assert.equal(tabIndexAtPercent(50, 5), 2)
|
||||
assert.equal(tabIndexAtPercent(70, 5), 3)
|
||||
assert.equal(tabIndexAtPercent(90, 5), 4)
|
||||
})
|
||||
|
||||
test('clamps drag positions outside the bar', () => {
|
||||
assert.equal(tabIndexAtX(-10, 100, 5), 0)
|
||||
assert.equal(tabIndexAtX(200, 100, 5), 4)
|
||||
assert.equal(clampDragX(-5, 100), 0)
|
||||
assert.equal(clampDragX(120, 100), 100)
|
||||
assert.equal(clampDragX(Number.NaN, 100), 0)
|
||||
test('clamps percent and maps out-of-range to edge tabs', () => {
|
||||
assert.equal(clampPercent(-5), 0)
|
||||
assert.equal(clampPercent(120), 100)
|
||||
assert.equal(clampPercent(Number.NaN), 0)
|
||||
assert.equal(tabIndexAtPercent(-5, 5), 0)
|
||||
assert.equal(tabIndexAtPercent(120, 5), 4)
|
||||
})
|
||||
|
||||
test('only treats a move as a drag beyond the threshold', () => {
|
||||
assert.equal(hasDragged(100, 110, 12), false)
|
||||
assert.equal(hasDragged(100, 112, 12), true)
|
||||
assert.equal(hasDragged(100, 88, 12), true)
|
||||
})
|
||||
|
||||
test('derives the floating bar frame from window width', () => {
|
||||
|
||||
Reference in New Issue
Block a user