Skip to content

Commit

Permalink
Merge pull request #128 from Kitware/fix-event-ordering
Browse files Browse the repository at this point in the history
fix(ParentedView): switch interactor on capture
  • Loading branch information
floryst authored Mar 1, 2024
2 parents 418802a + e31d803 commit 5bd0ec1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
36 changes: 18 additions & 18 deletions src/core/internal/ParentedView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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 --- //

Expand Down
1 change: 1 addition & 0 deletions src/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 5bd0ec1

Please sign in to comment.