Skip to content

Commit 57fd95f

Browse files
authored
Merge pull request #107 from Kitware/detect-external-style
fix(useInteractorStyle): no presets with external styles
2 parents 0cc3878 + 674b232 commit 57fd95f

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

src/core/internal/ParentedView.tsx

+6-2
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,18 @@ const ParentedView = forwardRef(function ParentedView(
6363
[renderWindowAPI]
6464
);
6565

66-
const [getInteractorStyle, setInteractorStyle] =
66+
const [getInteractorStyle, setInteractorStyle, isExternalStyle] =
6767
useInteractorStyle(getInteractor);
6868

6969
const {
7070
interactorSettings = DefaultProps.interactorSettings,
7171
autoCenterOfRotation = DefaultProps.autoCenterOfRotation,
7272
} = props;
73-
useInteractorStyleManipulatorSettings(getInteractorStyle, interactorSettings);
73+
useInteractorStyleManipulatorSettings(
74+
getInteractorStyle,
75+
isExternalStyle,
76+
interactorSettings
77+
);
7478

7579
useApplyCenterOfRotation(
7680
rendererRef,

src/core/internal/SingleView.tsx

+6-2
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ const SingleView = forwardRef(function SingleView(props: ViewProps, fwdRef) {
5454
[]
5555
);
5656

57-
const [getInteractorStyle, setInteractorStyle] =
57+
const [getInteractorStyle, setInteractorStyle, isExternalStyle] =
5858
useInteractorStyle(getInteractor);
5959

6060
useMount(() => {
@@ -65,7 +65,11 @@ const SingleView = forwardRef(function SingleView(props: ViewProps, fwdRef) {
6565
interactorSettings = DefaultProps.interactorSettings,
6666
autoCenterOfRotation = DefaultProps.autoCenterOfRotation,
6767
} = props;
68-
useInteractorStyleManipulatorSettings(getInteractorStyle, interactorSettings);
68+
useInteractorStyleManipulatorSettings(
69+
getInteractorStyle,
70+
isExternalStyle,
71+
interactorSettings
72+
);
6973

7074
useApplyCenterOfRotation(
7175
rendererRef,

src/core/modules/useInteractorStyle.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,15 @@ const settingToManipulator = (setting: ManipulatorSettings) => {
9292

9393
export function useInteractorStyleManipulatorSettings(
9494
getStyle: () => vtkInteractorStyle,
95+
isExternalStyle: boolean,
9596
settings: ManipulatorSettings[]
9697
) {
9798
useComparableEffect(
9899
() => {
100+
// Assumes external styles are externally controlled
101+
if (isExternalStyle) return;
99102
if (!getStyle().isA('vtkInteractorStyleManipulator')) return;
103+
100104
const style = getStyle() as vtkInteractorStyleManipulator;
101105
style.removeAllManipulators();
102106
// always add gestures
@@ -139,6 +143,7 @@ export function useInteractorStyle(
139143
);
140144

141145
const externalStyleRef = useRef<vtkInteractorStyle | null>(null);
146+
const isExternalStyle = !!externalStyleRef.current;
142147

143148
const getStyle = useCallback(() => {
144149
return externalStyleRef.current ?? getInternalStyle();
@@ -177,5 +182,5 @@ export function useInteractorStyle(
177182
};
178183
}, [getInteractor, getStyle, internalStyleRef]);
179184

180-
return [getStyle, setStyle] as const;
185+
return [getStyle, setStyle, isExternalStyle] as const;
181186
}

0 commit comments

Comments
 (0)