Skip to content

Commit 597cb9b

Browse files
committed
✨ strech preview canvas to full-width on demand
1 parent 0e66756 commit 597cb9b

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

client/modules/IDE/components/PreviewFrame.jsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,12 @@ class PreviewFrame extends React.Component {
201201
this.addLoopProtect(sketchDoc);
202202
sketchDoc.head.insertBefore(consoleErrorsScript, sketchDoc.head.firstElement);
203203

204+
if (this.props.forceFullWidth) {
205+
const resizeScript = sketchDoc.createElement('style');
206+
resizeScript.innerHTML = '.p5Canvas { width: 100% !important; height: auto !important }';
207+
sketchDoc.head.appendChild(resizeScript);
208+
}
209+
204210
return `<!DOCTYPE HTML>\n${sketchDoc.documentElement.outerHTML}`;
205211
}
206212

@@ -331,6 +337,7 @@ class PreviewFrame extends React.Component {
331337
if (this.props.endSketchRefresh) {
332338
this.props.endSketchRefresh();
333339
}
340+
// debugger; // eslint-disable-line
334341
} else {
335342
doc.srcdoc = '';
336343
srcDoc.set(doc, ' ');
@@ -384,11 +391,13 @@ PreviewFrame.propTypes = {
384391
clearConsole: PropTypes.func.isRequired,
385392
cmController: PropTypes.shape({
386393
getContent: PropTypes.func
387-
})
394+
}),
395+
forceFullWidth: PropTypes.bool
388396
};
389397

390398
PreviewFrame.defaultProps = {
391399
fullView: false,
400+
forceFullWidth: false,
392401
cmController: {}
393402
};
394403

client/modules/Mobile/MobileSketchView.jsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable */
2-
import React from 'react';
2+
import React, { useEffect } from 'react';
33
import PropTypes from 'prop-types';
44
import { Link } from 'react-router';
55
import { bindActionCreators } from 'redux';
@@ -53,10 +53,10 @@ const MobileSketchView = (props) => {
5353

5454
const { preferences, ide } = props;
5555

56-
// useEffect(() => {
56+
useEffect(() => {
5757
// console.log(params);
5858
// getProject(params.project_id, params.username);
59-
// }, []);
59+
});
6060

6161
return (
6262
<Screen>
@@ -78,6 +78,7 @@ const MobileSketchView = (props) => {
7878
content={selectedFile.content}
7979

8080
isPlaying
81+
forceFullWidth
8182
isAccessibleOutputPlaying={ide.isAccessibleOutputPlaying}
8283
previewIsRefreshing={ide.previewIsRefreshing}
8384

0 commit comments

Comments
 (0)