Skip to content

Commit

Permalink
Fix to lazy rendering + maintaining annotation mode across page change
Browse files Browse the repository at this point in the history
  • Loading branch information
rsimon committed Nov 12, 2021
1 parent a76a170 commit 42ba405
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
1 change: 1 addition & 0 deletions src/pdf/PDFViewer.css
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ header label {
.page-container {
position:relative;
margin:10px 0;
min-height:50vh;
}

.page-container .r6o-content-wrapper {
Expand Down
39 changes: 25 additions & 14 deletions src/pdf/endless/AnnotatablePage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ const AnnotatablePage = props => {

const containerEl = useRef();

const [ pageVisible, setPageVisible ] = useState(false);

const [ pageVisible, setPageVisible ] = useState(false)
const [ isRendered, setRendered ] = useState(false);

const [ anno, setAnno ] = useState();
Expand Down Expand Up @@ -70,6 +69,27 @@ const AnnotatablePage = props => {
props.onDeleteAnnotation(extended)
}

const setMode = recogito => {
if (isRendered) {
const imageLayer = containerEl.current.querySelector('svg.a9s-annotationlayer');

if (props.annotationMode === 'IMAGE') {
if (imageLayer)
imageLayer.style.pointerEvents = 'auto';
} else if (props.annotationMode === 'ANNOTATION') {
if (imageLayer)
imageLayer.style.pointerEvents = null;

recogito.setMode('ANNOTATION');
} else if (props.annotationMode === 'RELATIONS') {
if (imageLayer)
imageLayer.style.pointerEvents = null;

recogito.setMode('RELATIONS');
}
}
}

const initAnnotationLayer = () => {
console.log('Creating annotation layer on page ' + props.page);

Expand Down Expand Up @@ -105,6 +125,8 @@ const AnnotatablePage = props => {
// wait time until Recogito/Annotorious inits are complete.
r.setAnnotations(text);
anno.setAnnotations(image);

setMode(r);
}

const destroyAnnotationLayer = () => {
Expand Down Expand Up @@ -153,18 +175,7 @@ const AnnotatablePage = props => {
}, [ isRendered, pageVisible ]);

useEffect(() => {
if (containerEl.current) {
const imageLayer = containerEl.current.querySelector('svg.a9s-annotationlayer');

if (imageLayer) {
if (props.annotationMode === 'IMAGE') {
imageLayer.style.pointerEvents = 'auto';
} else {
imageLayer.style.pointerEvents = null;
recogito.setMode(props.annotationMode);
}
}
}
setMode(recogito);
}, [ props.annotationMode ])

return (
Expand Down

0 comments on commit 42ba405

Please sign in to comment.