Skip to content

Commit 25dfcd0

Browse files
authored
Bug fixes - tablet experience (#675)
* Display controls on iPad * Remember where you are
1 parent 7672e3a commit 25dfcd0

3 files changed

Lines changed: 13 additions & 7 deletions

File tree

main/view.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as Blockly from 'blockly';
22
import { workspace } from './blocklyinit.js';
33
import { flock } from '../flock.js';
4+
import { scrollToBlockTopParentLeft } from '../ui/blocklyutil.js';
45

56
export const isNarrowScreen = () => {
67
return window.innerWidth <= 1024;
@@ -10,6 +11,8 @@ const isMobile = () => {
1011
return /Mobi|Android|iPad/i.test(navigator.userAgent);
1112
};
1213

14+
let pendingScrollBlockId = null;
15+
1316
export function onResize(mode) {
1417
// First handle canvas and engine
1518
resizeCanvas();
@@ -29,6 +32,10 @@ export function onResize(mode) {
2932
if (workspace) {
3033
Blockly.svgResize(workspace);
3134
if (mode === 'reset') workspace.scroll(scrollX, scrollY);
35+
if (mode === 'reset' && pendingScrollBlockId) {
36+
scrollToBlockTopParentLeft(workspace, pendingScrollBlockId);
37+
pendingScrollBlockId = null;
38+
}
3239
}
3340
});
3441
}
@@ -320,12 +327,6 @@ function showCodeView() {
320327
if (canvasToggleBtn) canvasToggleBtn.setAttribute('aria-pressed', 'false');
321328
if (codeToggleBtn) codeToggleBtn.setAttribute('aria-pressed', 'true');
322329

323-
// Blockly resize after DOM changes
324-
requestAnimationFrame(() => {
325-
if (workspace) {
326-
Blockly.svgResize(workspace);
327-
}
328-
});
329330
}
330331

331332
onResize('reset');
@@ -343,6 +344,9 @@ export function showCanvasView() {
343344
currentView = 'canvas';
344345

345346
if (isNarrowScreen()) {
347+
// Save the current block before hiding the panel — currentBlock may be cleared on hide.
348+
pendingScrollBlockId = window.currentBlock?.id || null;
349+
346350
// Instead of CSS transform, change the layout directly
347351
const canvasArea = document.getElementById('canvasArea');
348352
const blocklyArea = document.getElementById('codePanel');

ui/blocklyutil.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ function ensureAddMenuSelectionCleanup(workspace) {
9696
workspace.__addMenuSelectionCleanupAttached = true;
9797
}
9898

99-
function scrollToBlockTopParentLeft(workspace, blockId) {
99+
export function scrollToBlockTopParentLeft(workspace, blockId) {
100100
if (!workspace.isMovable()) {
101101
console.warn("Tried to move a non-movable workspace.");
102102
return;

ui/gizmos.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ function createAdaptiveInput({ onMove, onConfirm, onCancel, stepNormal, stepFast
117117
canvas.addEventListener("pointerdown", onCanvasPointer);
118118
const rawKeyObserver = flock.inputManager.onRawKeyDownObservable.add(onRawKey);
119119

120+
if (navigator.maxTouchPoints > 0) switchToTouch();
121+
120122
return function stop() {
121123
canvas.removeEventListener("pointerdown", onCanvasPointer);
122124
flock.inputManager.onRawKeyDownObservable.remove(rawKeyObserver);

0 commit comments

Comments
 (0)