Skip to content
Snippets Groups Projects
Commit 127d009d authored by DD Liu's avatar DD Liu
Browse files

Merge branch 'develop' into monitors

parents f385070f 4dd3ed69
No related branches found
No related tags found
No related merge requests found
...@@ -19,6 +19,8 @@ const GUIComponent = props => { ...@@ -19,6 +19,8 @@ const GUIComponent = props => {
basePath, basePath,
children, children,
vm, vm,
onTabSelect,
tabIndex,
...componentProps ...componentProps
} = props; } = props;
if (children) { if (children) {
...@@ -29,13 +31,6 @@ const GUIComponent = props => { ...@@ -29,13 +31,6 @@ const GUIComponent = props => {
); );
} }
// @todo hack to resize blockly manually in case resize happened while hidden
const handleTabSelect = tabIndex => {
if (tabIndex === 0) {
setTimeout(() => window.dispatchEvent(new Event('resize')));
}
};
return ( return (
<Box <Box
className={styles.pageWrapper} className={styles.pageWrapper}
...@@ -48,7 +43,7 @@ const GUIComponent = props => { ...@@ -48,7 +43,7 @@ const GUIComponent = props => {
<Tabs <Tabs
className={styles.tabs} className={styles.tabs}
forceRenderTabPanel={true} // eslint-disable-line react/jsx-boolean-value forceRenderTabPanel={true} // eslint-disable-line react/jsx-boolean-value
onSelect={handleTabSelect} onSelect={onTabSelect}
> >
<TabList className={styles.tabList}> <TabList className={styles.tabList}>
<Tab className={styles.tab}>Scripts</Tab> <Tab className={styles.tab}>Scripts</Tab>
...@@ -59,6 +54,7 @@ const GUIComponent = props => { ...@@ -59,6 +54,7 @@ const GUIComponent = props => {
<Box className={styles.blocksWrapper}> <Box className={styles.blocksWrapper}>
<Blocks <Blocks
grow={1} grow={1}
isVisible={tabIndex === 0} // Scripts tab
options={{ options={{
media: `${basePath}static/blocks-media/` media: `${basePath}static/blocks-media/`
}} }}
...@@ -102,6 +98,8 @@ const GUIComponent = props => { ...@@ -102,6 +98,8 @@ const GUIComponent = props => {
GUIComponent.propTypes = { GUIComponent.propTypes = {
basePath: PropTypes.string, basePath: PropTypes.string,
children: PropTypes.node, children: PropTypes.node,
onTabSelect: PropTypes.func,
tabIndex: PropTypes.number,
vm: PropTypes.instanceOf(VM).isRequired vm: PropTypes.instanceOf(VM).isRequired
}; };
GUIComponent.defaultProps = { GUIComponent.defaultProps = {
......
...@@ -52,7 +52,21 @@ class Blocks extends React.Component { ...@@ -52,7 +52,21 @@ class Blocks extends React.Component {
this.attachVM(); this.attachVM();
} }
shouldComponentUpdate (nextProps, nextState) { shouldComponentUpdate (nextProps, nextState) {
return this.state.prompt !== nextState.prompt; return this.state.prompt !== nextState.prompt || this.props.isVisible !== nextProps.isVisible;
}
componentDidUpdate (prevProps) {
if (this.props.isVisible === prevProps.isVisible) {
return;
}
// @todo hack to resize blockly manually in case resize happened while hidden
if (this.props.isVisible) { // Scripts tab
window.dispatchEvent(new Event('resize'));
this.workspace.setVisible(true);
this.workspace.toolbox_.refreshSelection();
} else {
this.workspace.setVisible(false);
}
} }
componentWillUnmount () { componentWillUnmount () {
this.detachVM(); this.detachVM();
...@@ -147,6 +161,7 @@ class Blocks extends React.Component { ...@@ -147,6 +161,7 @@ class Blocks extends React.Component {
const { const {
options, // eslint-disable-line no-unused-vars options, // eslint-disable-line no-unused-vars
vm, // eslint-disable-line no-unused-vars vm, // eslint-disable-line no-unused-vars
isVisible, // eslint-disable-line no-unused-vars
...props ...props
} = this.props; } = this.props;
return ( return (
...@@ -170,11 +185,12 @@ class Blocks extends React.Component { ...@@ -170,11 +185,12 @@ class Blocks extends React.Component {
} }
Blocks.propTypes = { Blocks.propTypes = {
isVisible: PropTypes.bool.isRequired,
options: PropTypes.shape({ options: PropTypes.shape({
media: PropTypes.string, media: PropTypes.string,
zoom: PropTypes.shape({ zoom: PropTypes.shape({
controls: PropTypes.boolean, controls: PropTypes.bool,
wheel: PropTypes.boolean, wheel: PropTypes.bool,
startScale: PropTypes.number startScale: PropTypes.number
}), }),
colours: PropTypes.shape({ colours: PropTypes.shape({
......
const PropTypes = require('prop-types'); const PropTypes = require('prop-types');
const React = require('react'); const React = require('react');
const VM = require('scratch-vm'); const VM = require('scratch-vm');
const bindAll = require('lodash.bindall');
const vmListenerHOC = require('../lib/vm-listener-hoc.jsx'); const vmListenerHOC = require('../lib/vm-listener-hoc.jsx');
const GUIComponent = require('../components/gui/gui.jsx'); const GUIComponent = require('../components/gui/gui.jsx');
class GUI extends React.Component { class GUI extends React.Component {
constructor (props) {
super(props);
bindAll(this, [
'handleTabSelect'
]);
this.state = {tabIndex: 0};
}
componentDidMount () { componentDidMount () {
this.props.vm.loadProject(this.props.projectData); this.props.vm.loadProject(this.props.projectData);
this.props.vm.setCompatibilityMode(true); this.props.vm.setCompatibilityMode(true);
...@@ -20,6 +28,9 @@ class GUI extends React.Component { ...@@ -20,6 +28,9 @@ class GUI extends React.Component {
componentWillUnmount () { componentWillUnmount () {
this.props.vm.stopAll(); this.props.vm.stopAll();
} }
handleTabSelect (tabIndex) {
this.setState({tabIndex});
}
render () { render () {
const { const {
projectData, // eslint-disable-line no-unused-vars projectData, // eslint-disable-line no-unused-vars
...@@ -28,7 +39,9 @@ class GUI extends React.Component { ...@@ -28,7 +39,9 @@ class GUI extends React.Component {
} = this.props; } = this.props;
return ( return (
<GUIComponent <GUIComponent
tabIndex={this.state.tabIndex}
vm={vm} vm={vm}
onTabSelect={this.handleTabSelect}
{...componentProps} {...componentProps}
/> />
); );
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment