Skip to content

Commit

Permalink
Improves performance of annotation layer when hidden
Browse files Browse the repository at this point in the history
  • Loading branch information
Titou325 committed Jul 23, 2024
1 parent fcb6611 commit c82ea11
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/lib/pdf/layers/annotation.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { AnnotationLayer } from "pdfjs-dist";
import { useEffect, useRef } from "react";

import { useVisibility } from "@/lib/viewport";

import { usePDFLinkService } from "../links";
import { usePDFPage } from "../page";
import { cancellable } from "../utils";
Expand All @@ -20,9 +22,24 @@ export const useAnnotationLayer = (params: AnnotationLayerParams) => {
const annotationLayerRef = useRef<HTMLDivElement>(null);
const annotationLayerObjectRef = useRef<AnnotationLayer | null>(null);
const linkService = usePDFLinkService();
const { visible } = useVisibility({
elementRef: annotationLayerRef,
});

const { pdfPageProxy } = usePDFPage();

useEffect(() => {
if (!annotationLayerRef.current) {
return;
}

if (visible) {
annotationLayerRef.current.style.contentVisibility = "visible";
} else {
annotationLayerRef.current.style.contentVisibility = "hidden";
}
}, [visible]);

useEffect(() => {
if (!annotationLayerRef.current) {
return;
Expand Down

0 comments on commit c82ea11

Please sign in to comment.