@aiquants/virtualscroll 3.9.0 → 3.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/dist/VirtualScroll.d.ts.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +298 -297
- package/package.json +1 -1
- package/src/VirtualScroll.tsx +13 -4
package/package.json
CHANGED
package/src/VirtualScroll.tsx
CHANGED
|
@@ -1428,20 +1428,29 @@ const VirtualScrollInner = <T,>(
|
|
|
1428
1428
|
|
|
1429
1429
|
const [scrollPosition, setScrollPosition] = useState(initialValues.position)
|
|
1430
1430
|
const [contentSize, setContentSize] = useState<number>(initialValues.total)
|
|
1431
|
-
// 初期位置の index とアンカーは上端揃えの scrollToIndex
|
|
1432
|
-
|
|
1431
|
+
// 初期位置の index とアンカーは上端揃えの scrollToIndex と同じ位置なので、その位置の上端揃えとして覚えておく。位置 0 から
|
|
1432
|
+
// 始まる一覧も先頭の行の上端に揃っている (位置 0 の行ラッパーは覚えた揃えによらず上端で揃える) ため、同じく覚える。覚えずに
|
|
1433
|
+
// 始めると、先頭へ戻すだけの最初の scrollToIndex (ホストが開いた直後の打鍵で先頭へ戻すなど) が状態を書き、確定を 1 回足す
|
|
1434
|
+
const [alignedEdge, setAlignedEdge] = useState<AlignedEdge | null>(() => ((initialScrollAnchor && itemCount > 0) || typeof initialScrollIndex === "number" || initialValues.position <= EDGE_POSITION_TOLERANCE ? { edge: "start", panePosition: initialValues.position } : null))
|
|
1433
1435
|
// 状態の同期の写し。手動スクロールのたびに状態へ null を書くと、同じ値でも React が描画を予約し得るため、写しで要否を決める
|
|
1434
1436
|
const alignedEdgeRef = useRef(alignedEdge)
|
|
1435
1437
|
|
|
1436
1438
|
/**
|
|
1437
1439
|
* Remembers the alignment that holds at a pane position, or forgets it with `null`: writes the state the items wrapper
|
|
1438
|
-
* snaps with and its synchronous copy.
|
|
1440
|
+
* snaps with and its synchronous copy, only when the edge or the pane position differs from the remembered one.
|
|
1439
1441
|
*
|
|
1440
|
-
* あるペイン位置で成り立つ揃えを覚える処理 (`null` で忘れる)
|
|
1442
|
+
* あるペイン位置で成り立つ揃えを覚える処理 (`null` で忘れる)。行ラッパーが揃えに使う状態と、その同期の写しへ、覚えた揃えと
|
|
1443
|
+
* 辺かペイン位置が違うときだけ書く。
|
|
1441
1444
|
*
|
|
1442
1445
|
* @param next - The alignment, or `null` / 揃え (無ければ `null`)
|
|
1443
1446
|
*/
|
|
1444
1447
|
const rememberAlignedEdge = useCallback((next: AlignedEdge | null): void => {
|
|
1448
|
+
const current = alignedEdgeRef.current
|
|
1449
|
+
// 同じ揃えでも新しいオブジェクトを書けば React は描画を予約する。同じ位置への scrollToIndex (ホストが打鍵ごとに
|
|
1450
|
+
// 先頭へ戻すなど) のたびに確定が 1 回増えるため、辺と位置が同じなら書かない
|
|
1451
|
+
if (current === next || (current !== null && next !== null && current.edge === next.edge && current.panePosition === next.panePosition)) {
|
|
1452
|
+
return
|
|
1453
|
+
}
|
|
1445
1454
|
alignedEdgeRef.current = next
|
|
1446
1455
|
setAlignedEdge(next)
|
|
1447
1456
|
}, [])
|