Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit 76fd15c4 authored by Simon Chan's avatar Simon Chan
Browse files

feat(demo): add smart auto scroll to grid

parent 12a991ea
Loading
Loading
Loading
Loading
+18 −1
Original line number Diff line number Diff line
import { makeStyles, mergeClasses, shorthands } from '@griffel/react';
import { ComponentType, CSSProperties, useLayoutEffect, useMemo, useState } from "react";
import { ComponentType, CSSProperties, useEffect, useLayoutEffect, useMemo, useState } from "react";
import { useStableCallback, withDisplayName } from "../utils";
import { ResizeObserver, Size } from './resize-observer';

@@ -167,8 +167,18 @@ export const Grid = withDisplayName('Grid')(({
    const [bodyRef, setBodyRef] = useState<HTMLDivElement | null>(null);
    const [bodySize, setBodySize] = useState<Size>({ width: 0, height: 0 });

    const [autoScroll, setAutoScroll] = useState(true);

    const handleScroll = useStableCallback(() => {
        if (bodyRef) {
            if (autoScroll) {
                if (scrollTop < bodyRef.scrollHeight - bodyRef.clientHeight && bodyRef.scrollTop < scrollTop) {
                    setAutoScroll(false);
                }
            } else if (bodyRef.scrollTop + bodyRef.offsetHeight >= bodyRef.scrollHeight - 50) {
                setAutoScroll(true);
            }

            setScrollLeft(bodyRef.scrollLeft);
            setScrollTop(bodyRef.scrollTop);
        }
@@ -267,6 +277,13 @@ export const Grid = withDisplayName('Grid')(({
        };
    }, [columns, bodySize.width]);

    useEffect(() => {
        if (autoScroll && bodyRef) {
            void bodyRef.offsetLeft;
            bodyRef.scrollTop = bodyRef.scrollHeight;
        }
    });

    const headers = useMemo(() => (
        columnMetadata.columns.map((column, index) => (
            <HeaderComponent
+1 −1
Original line number Diff line number Diff line
@@ -168,7 +168,7 @@ export class Logcat extends AdbCommandBase {
                    ...(options?.pid ? ['--pid', options.pid.toString()] : []),
                    ...(options?.ids ? ['-b', Logcat.joinLogId(options.ids)] : [])
                ], {
                    // PERF: None protocol is 25% faster then Shell protocol
                    // PERF: None protocol is 150% faster then Shell protocol
                    protocols: [AdbSubprocessNoneProtocol],
                });
                bufferedStream = new BufferedStream(stdout);