• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

glideapps / glide-data-grid / 7213760293

14 Dec 2023 07:41PM UTC coverage: 90.701% (+4.3%) from 86.42%
7213760293

Pull #810

github

jassmith
5.99.9-beta5
Pull Request #810: 6.0.0

2548 of 3185 branches covered (0.0%)

2933 of 3342 new or added lines in 61 files covered. (87.76%)

264 existing lines in 12 files now uncovered.

15547 of 17141 relevant lines covered (90.7%)

2973.79 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

36.51
/packages/core/src/internal/scrolling-data-grid/use-kinetic-scroll.ts
1
import { useEffect, useRef } from "react";
1✔
2

1✔
3
const useKineticScroll = (
1✔
4
    isEnabled: boolean,
644✔
5
    callback: () => void,
644✔
6
    targetScroller: React.MutableRefObject<HTMLDivElement | null>
644✔
7
) => {
644✔
8
    const rafId = useRef<number | null>(null);
644✔
9
    const isTouching = useRef(false);
644✔
10
    const lastScrollPosition = useRef<number | null>(null);
644✔
11

644✔
12
    useEffect(() => {
644✔
13
        const handleScroll = () => {
261✔
NEW
14
            if (!isTouching.current) {
×
NEW
15
                const currentScrollPosition = targetScroller.current?.scrollTop ?? 0;
×
NEW
16
                if (lastScrollPosition.current === currentScrollPosition) {
×
NEW
17
                    // Scroll position hasn't changed, stop the animation frame
×
NEW
18
                    lastScrollPosition.current = null;
×
NEW
19
                    return;
×
NEW
20
                }
×
NEW
21

×
NEW
22
                lastScrollPosition.current = currentScrollPosition;
×
NEW
23
                callback();
×
NEW
24
                rafId.current = requestAnimationFrame(handleScroll);
×
NEW
25
            }
×
NEW
26
        };
×
27

261✔
28
        const startTouch = () => {
261✔
NEW
29
            isTouching.current = true;
×
NEW
30
            lastScrollPosition.current = null; // Reset last scroll position on touch start
×
NEW
31
            if (rafId.current !== null) {
×
NEW
32
                cancelAnimationFrame(rafId.current);
×
NEW
33
                rafId.current = null;
×
NEW
34
            }
×
NEW
35
        };
×
36

261✔
37
        const endTouch = (event: TouchEvent) => {
261✔
NEW
38
            if (event.touches.length === 0) {
×
NEW
39
                // All touches have ended
×
NEW
40
                isTouching.current = false;
×
NEW
41
                rafId.current = requestAnimationFrame(handleScroll);
×
NEW
42
            }
×
NEW
43
        };
×
44

261✔
45
        if (isEnabled && targetScroller.current !== null) {
261!
NEW
46
            const element = targetScroller.current;
×
NEW
47
            element.addEventListener("touchstart", startTouch);
×
NEW
48
            element.addEventListener("touchend", endTouch);
×
NEW
49
            element.addEventListener("scroll", handleScroll, { passive: true });
×
NEW
50

×
NEW
51
            return () => {
×
NEW
52
                element.removeEventListener("touchstart", startTouch);
×
NEW
53
                element.removeEventListener("touchend", endTouch);
×
NEW
54
                element.removeEventListener("scroll", handleScroll);
×
NEW
55
                if (rafId.current !== null) {
×
NEW
56
                    cancelAnimationFrame(rafId.current);
×
NEW
57
                }
×
NEW
58
            };
×
NEW
59
        }
×
60
    }, [isEnabled, targetScroller, callback]);
644✔
61
};
644✔
62

1✔
63
export default useKineticScroll;
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc