Skip to content

Commit 37e0f10

Browse files
authored
fix: fix bug that prevented modal dialogs from appearing on mobile (#183)
1 parent 6d14530 commit 37e0f10

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/data_category.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,16 @@ function addCreateButton(xmlList, workspace, type) {
426426
}
427427
button.setAttribute("text", msg);
428428
button.setAttribute("callbackKey", callbackKey);
429-
workspace.registerButtonCallback(callbackKey, callback);
429+
workspace.registerButtonCallback(callbackKey, (b) => {
430+
// Run the callback after a delay to avoid it getting captured by the React
431+
// modal in scratch-gui and being registered as a click on the scrim that
432+
// dismisses the dialog.
433+
requestAnimationFrame(() => {
434+
setTimeout(() => {
435+
callback(b);
436+
});
437+
});
438+
});
430439
xmlList.push(button);
431440
}
432441

src/procedures.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,14 @@ function addCreateButton_(workspace, xmlList) {
105105
var msg = Blockly.Msg.NEW_PROCEDURE;
106106
var callbackKey = "CREATE_PROCEDURE";
107107
var callback = function () {
108-
createProcedureDefCallback(workspace);
108+
// Run the callback after a delay to avoid it getting captured by the React
109+
// modal in scratch-gui and being registered as a click on the scrim that
110+
// dismisses the dialog.
111+
requestAnimationFrame(() => {
112+
setTimeout(() => {
113+
createProcedureDefCallback(workspace);
114+
});
115+
});
109116
};
110117
button.setAttribute("text", msg);
111118
button.setAttribute("callbackKey", callbackKey);

0 commit comments

Comments
 (0)