From e31d8036b006283bbf7921c24254cb375e1b32f9 Mon Sep 17 00:00:00 2001 From: Forrest Date: Wed, 28 Feb 2024 13:06:33 -0500 Subject: [PATCH] fix(ParentedView): switch interactor on capture --- src/core/internal/ParentedView.tsx | 36 +++++++++++++++--------------- src/global.d.ts | 1 + 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/core/internal/ParentedView.tsx b/src/core/internal/ParentedView.tsx index b427cd5..f9d7559 100644 --- a/src/core/internal/ParentedView.tsx +++ b/src/core/internal/ParentedView.tsx @@ -91,11 +91,9 @@ const ParentedView = forwardRef(function ParentedView( const rendererAPI = rendererRef.current; if (!rendererAPI) return false; - const interactor = getInteractor(); + const interactor = getInteractor() as FixedVTKRenderWindowInteractor; - (interactor as FixedVTKRenderWindowInteractor).setCurrentRenderer( - rendererAPI.get() - ); + interactor.setCurrentRenderer(rendererAPI.get()); interactor.setInteractorStyle(getInteractorStyle()); const oldContainer = interactor.getContainer(); @@ -108,21 +106,23 @@ const ParentedView = forwardRef(function ParentedView( // Use wheel events to cover the posibility of interacting // with an out-of-focus browser window. - useEventListener(containerRef, 'wheel', (ev: WheelEvent) => { - if (switchTarget()) { - // forward wheel-event to interactor - const interactor = getInteractor(); - interactor.handleWheel(ev); - } - }); + useEventListener( + containerRef, + 'wheel', + () => { + switchTarget(); + }, + { capture: true } + ); - useEventListener(containerRef, 'pointerenter', (ev: PointerEvent) => { - if (switchTarget()) { - // forward pointer-event to interactor - const interactor = getInteractor(); - interactor.handlePointerEnter(ev); - } - }); + useEventListener( + containerRef, + 'pointerenter', + () => { + switchTarget(); + }, + { capture: true } + ); // --- resize handling --- // diff --git a/src/global.d.ts b/src/global.d.ts index 56aed86..b54bceb 100644 --- a/src/global.d.ts +++ b/src/global.d.ts @@ -6,6 +6,7 @@ declare module '@kitware/vtk.js/type-patches' { export interface FixedVTKRenderWindowInteractor extends vtkRenderWindowInteractor { setCurrentRenderer(ren: vtkRenderer): void; + setContainer(el: HTMLElement | null): boolean; } export interface VtkRendererEvent {