From a86ea5131cdcb3c0f889a489f00b13935e9f2e2a Mon Sep 17 00:00:00 2001 From: Benjamin Elo Date: Wed, 24 Jul 2019 02:48:30 -0700 Subject: [PATCH] Added onHideSheet method to Sheet props Summary: This component was added back in January, but it hasn't been used, and thus no one has tested it in the real world. It needs a onHideSheet method to unmount this component when the plugin sheet becomes hidden. This allows the sheet to appear and dissapear on button clicks, instead of only appearing when the container component loads. For the old behavior see the test plan in this diff: D13597251 Reviewed By: jknoxville Differential Revision: D16443836 fbshipit-source-id: 68feec23338287dbafc846689ea2a1b35be4b2b0 --- src/ui/components/Sheet.js | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/ui/components/Sheet.js b/src/ui/components/Sheet.js index 331a15e35..7858aae17 100644 --- a/src/ui/components/Sheet.js +++ b/src/ui/components/Sheet.js @@ -8,7 +8,10 @@ import {Component} from 'react'; import {createPortal} from 'react-dom'; import {connect} from 'react-redux'; -import {setActiveSheet} from '../../reducers/application.js'; +import { + ACTIVE_SHEET_PLUGIN_SHEET, + setActiveSheet, +} from '../../reducers/application.js'; import type {ActiveSheet} from '../../reducers/application'; @@ -21,6 +24,10 @@ type Props = { * the sheet. */ children: (onHide: () => void) => ?React.Node, + /** + * Function that is called when the sheet becomes hidden. + */ + onHideSheet: () => void, setActiveSheet: (sheet: ActiveSheet) => any, activeSheet: ActiveSheet, }; @@ -58,8 +65,20 @@ class Sheet extends Component { if (prevState.content !== this.state.content) { this.showSheetIfContentsAvailable(); } + if ( + prevProps.activeSheet === ACTIVE_SHEET_PLUGIN_SHEET && + this.props.activeSheet !== ACTIVE_SHEET_PLUGIN_SHEET + ) { + this.onHideSheet(); + } } + onHideSheet = () => { + if (this.props.onHideSheet != null) { + this.props.onHideSheet(); + } + }; + showSheetIfContentsAvailable = () => { if (this.state.content) { this.props.setActiveSheet('PLUGIN_SHEET');