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

glideapps / glide-data-grid / 7312551980

24 Dec 2023 04:45AM UTC coverage: 90.577% (+4.2%) from 86.42%
7312551980

Pull #810

github

web-flow
Allow control of cell activation behavior (#829)

* Allow control of cell activation behavior

* Add unit tests

* Cleanup

* Fix double click with touch

* Improve comment
Pull Request #810: 6.0.0

2590 of 3242 branches covered (0.0%)

3348 of 3816 new or added lines in 62 files covered. (87.74%)

265 existing lines in 12 files now uncovered.

15745 of 17383 relevant lines covered (90.58%)

3077.86 hits per line

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

38.67
/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,
670✔
5
    callback: () => void,
670✔
6
    targetScroller: React.MutableRefObject<HTMLDivElement | null>
670✔
7
) => {
670✔
8
    const rafId = useRef<number | null>(null);
670✔
9
    const isTouching = useRef<boolean | null>(null);
670✔
10
    const lastScrollPosition = useRef<number | null>(null);
670✔
11
    const sameCount = useRef(0);
670✔
12

670✔
13
    const callbackRef = useRef(callback);
670✔
14
    callbackRef.current = callback;
670✔
15

670✔
16
    const scrollEl = targetScroller.current;
670✔
17

670✔
18
    useEffect(() => {
670✔
19
        const handleScroll = () => {
274✔
NEW
20
            if (isTouching.current === false) {
×
NEW
21
                const currentScrollPosition = scrollEl?.scrollTop ?? 0;
×
NEW
22
                if (lastScrollPosition.current === currentScrollPosition) {
×
NEW
23
                    if (sameCount.current > 3) {
×
NEW
24
                        // Scroll position hasn't changed, stop the animation frame
×
NEW
25
                        lastScrollPosition.current = null;
×
NEW
26
                        isTouching.current = null;
×
NEW
27
                        return;
×
NEW
28
                    } else {
×
NEW
29
                        sameCount.current++;
×
NEW
30
                    }
×
NEW
31
                } else {
×
NEW
32
                    sameCount.current = 0;
×
NEW
33
                }
×
NEW
34

×
NEW
35
                lastScrollPosition.current = currentScrollPosition;
×
NEW
36
                callbackRef.current();
×
NEW
37
                rafId.current = window.setTimeout(handleScroll, 1000 / 120);
×
NEW
38
            }
×
NEW
39
        };
×
40

274✔
41
        const startTouch = () => {
274✔
NEW
42
            isTouching.current = true;
×
NEW
43
            lastScrollPosition.current = null; // Reset last scroll position on touch start
×
NEW
44
            if (rafId.current !== null) {
×
NEW
45
                window.clearTimeout(rafId.current);
×
NEW
46
                rafId.current = null;
×
NEW
47
            }
×
NEW
48
        };
×
49

274✔
50
        const endTouch = (event: TouchEvent) => {
274✔
NEW
51
            if (event.touches.length === 0) {
×
NEW
52
                // All touches have ended
×
NEW
53
                isTouching.current = false;
×
NEW
54
                sameCount.current = 0;
×
NEW
55
                rafId.current = window.setTimeout(handleScroll, 1000 / 120);
×
NEW
56
            }
×
NEW
57
        };
×
58

274✔
59
        if (isEnabled && scrollEl !== null) {
274!
NEW
60
            const element = scrollEl;
×
NEW
61
            element.addEventListener("touchstart", startTouch);
×
NEW
62
            element.addEventListener("touchend", endTouch);
×
NEW
63

×
NEW
64
            return () => {
×
NEW
65
                element.removeEventListener("touchstart", startTouch);
×
NEW
66
                element.removeEventListener("touchend", endTouch);
×
NEW
67
                if (rafId.current !== null) {
×
NEW
68
                    window.clearTimeout(rafId.current);
×
NEW
69
                }
×
NEW
70
            };
×
NEW
71
        }
×
72
    }, [isEnabled, scrollEl]);
670✔
73
};
670✔
74

1✔
75
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