Skip to content

Commit

Permalink
fix: fix bug that prevented modal dialogs from appearing on mobile (#183
Browse files Browse the repository at this point in the history
)
  • Loading branch information
gonfunko authored Oct 2, 2024
1 parent 6d14530 commit 37e0f10
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
11 changes: 10 additions & 1 deletion src/data_category.js
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,16 @@ function addCreateButton(xmlList, workspace, type) {
}
button.setAttribute("text", msg);
button.setAttribute("callbackKey", callbackKey);
workspace.registerButtonCallback(callbackKey, callback);
workspace.registerButtonCallback(callbackKey, (b) => {
// Run the callback after a delay to avoid it getting captured by the React
// modal in scratch-gui and being registered as a click on the scrim that
// dismisses the dialog.
requestAnimationFrame(() => {
setTimeout(() => {
callback(b);
});
});
});
xmlList.push(button);
}

Expand Down
9 changes: 8 additions & 1 deletion src/procedures.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,14 @@ function addCreateButton_(workspace, xmlList) {
var msg = Blockly.Msg.NEW_PROCEDURE;
var callbackKey = "CREATE_PROCEDURE";
var callback = function () {
createProcedureDefCallback(workspace);
// Run the callback after a delay to avoid it getting captured by the React
// modal in scratch-gui and being registered as a click on the scrim that
// dismisses the dialog.
requestAnimationFrame(() => {
setTimeout(() => {
createProcedureDefCallback(workspace);
});
});
};
button.setAttribute("text", msg);
button.setAttribute("callbackKey", callbackKey);
Expand Down

0 comments on commit 37e0f10

Please # to comment.