Skip to content

Commit 1ed97ab

Browse files
rish-hubdannyrb
authored andcommitted
feat: Conditionally-render-ViewportOverlay-w/-prop-#43 (#44)
* Proptype defined * Changes: comment removed and proptype is made optional, removed prop passed in the example, destructured isOverlayVisible with frameRate and isPlaying
1 parent c55c94c commit 1ed97ab

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

src/CornerstoneViewport/CornerstoneViewport.js

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ class CornerstoneViewport extends Component {
8383
//
8484
style: PropTypes.object,
8585
className: PropTypes.string,
86+
isOverlayVisible: PropTypes.bool,
8687
};
8788

8889
constructor(props) {
@@ -103,6 +104,7 @@ class CornerstoneViewport extends Component {
103104
scale: undefined,
104105
windowWidth: undefined,
105106
windowCenter: undefined,
107+
isOverlayVisible: true,
106108
// Orientation Markers
107109
rotationDegrees: undefined,
108110
isFlippedVertically: undefined,
@@ -247,8 +249,12 @@ class CornerstoneViewport extends Component {
247249
}
248250

249251
// ~~ CINE
250-
const { frameRate, isPlaying } = this.props;
251-
const { frameRate: prevFrameRate, isPlaying: prevIsPlaying } = prevProps;
252+
const { frameRate, isPlaying, isOverlayVisible } = this.props;
253+
const {
254+
frameRate: prevFrameRate,
255+
isPlaying: prevIsPlaying,
256+
isOverlayVisible: prevIsOverlayVisible,
257+
} = prevProps;
252258
const validFrameRate = Math.max(frameRate, 1);
253259
const shouldStart = isPlaying !== prevIsPlaying && isPlaying;
254260
const shouldPause = isPlaying !== prevIsPlaying && !isPlaying;
@@ -264,6 +270,9 @@ class CornerstoneViewport extends Component {
264270
if (Object.keys(updatedState).length > 0) {
265271
this.setState(updatedState);
266272
}
273+
274+
if (isOverlayVisible !== prevIsOverlayVisible)
275+
this.setState({ isOverlayVisible });
267276
}
268277

269278
/**
@@ -298,12 +307,18 @@ class CornerstoneViewport extends Component {
298307
*/
299308
getOverlay() {
300309
const { viewportOverlayComponent: Component, imageIds } = this.props;
301-
const { imageIdIndex, scale, windowWidth, windowCenter } = this.state;
310+
const {
311+
imageIdIndex,
312+
scale,
313+
windowWidth,
314+
windowCenter,
315+
isOverlayVisible,
316+
} = this.state;
302317
const imageId = imageIds[imageIdIndex];
303-
304318
return (
305319
imageId &&
306-
windowWidth && (
320+
windowWidth &&
321+
isOverlayVisible && (
307322
<Component
308323
imageIndex={imageIdIndex + 1}
309324
stackSize={imageIds.length}

0 commit comments

Comments
 (0)