fix(ui): 拖动松手从手指位置平滑契合到目标 tab
- 拖动状态与位置状态分离 - 松手先恢复过渡但保留手指位置,下一帧再吸附到目标 tab,避免从旧位置跳变
This commit is contained in:
@@ -1,7 +1,12 @@
|
||||
import test from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
import { readFileSync } from 'node:fs'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
import path from 'node:path'
|
||||
import { clampPercent, getTabBarFrame, hasDragged, tabIndexAtPercent } from '../src/custom-tab-bar/tabBarGeometry.js'
|
||||
|
||||
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..')
|
||||
|
||||
test('maps a drag percent to the tab under the finger', () => {
|
||||
assert.equal(tabIndexAtPercent(10, 5), 0)
|
||||
assert.equal(tabIndexAtPercent(30, 5), 1)
|
||||
@@ -28,3 +33,11 @@ test('derives the floating bar frame from window width', () => {
|
||||
assert.deepEqual(getTabBarFrame(375), { left: 18, width: 339 })
|
||||
assert.deepEqual(getTabBarFrame(750), { left: 36, width: 678 })
|
||||
})
|
||||
|
||||
test('enables the slide transition before snapping the indicator to the target', () => {
|
||||
const source = readFileSync(path.join(root, 'src/custom-tab-bar/index.tsx'), 'utf8')
|
||||
assert.match(
|
||||
source,
|
||||
/isDraggingRef\.current = false\s+setIsDragging\(false\)\s+Taro\.nextTick\(\(\) => \{[\s\S]*?setDragPercent\(null\)/
|
||||
)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user