Skip to content

Fix #1345. Android triggers a window resize event when the soft keyb… #1743

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion core/blockly.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,29 @@ Blockly.onContextMenu_ = function(e) {
* @param {boolean=} opt_allowToolbox If true, don't close the toolbox.
*/
Blockly.hideChaff = function(opt_allowToolbox) {
Blockly.Tooltip.hide();
Blockly.hideChaffInternal_(opt_allowToolbox);
Blockly.WidgetDiv.hide(true);
};

/**
* Close tooltips, context menus, dropdown selections, etc.
* For some elements (e.g. field text inputs), rather than hiding, it will
* move them.
* @param {boolean=} opt_allowToolbox If true, don't close the toolbox.
*/
Blockly.hideChaffOnResize = function(opt_allowToolbox) {
Blockly.hideChaffInternal_(opt_allowToolbox);
Blockly.WidgetDiv.repositionForWindowResize();
};

/**
* Does a majority of the work for hideChaff including tooltips, dropdowns,
* toolbox, etc. It does not deal with the WidgetDiv.
* @param {boolean=} opt_allowToolbox If true, don't close the toolbox.
* @private
*/
Blockly.hideChaffInternal_ = function(opt_allowToolbox) {
Blockly.Tooltip.hide();
Blockly.DropDownDiv.hideWithoutAnimation();
if (!opt_allowToolbox) {
var workspace = Blockly.getMainWorkspace();
Expand Down
2 changes: 1 addition & 1 deletion core/inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ Blockly.init_ = function(mainWorkspace) {
var workspaceResizeHandler = Blockly.bindEventWithChecks_(window, 'resize',
null,
function() {
Blockly.hideChaff(true);
Blockly.hideChaffOnResize(true);
Blockly.svgResize(mainWorkspace);
});
mainWorkspace.setResizeHandlerWrapper(workspaceResizeHandler);
Expand Down
21 changes: 21 additions & 0 deletions core/widgetdiv.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,27 @@ Blockly.WidgetDiv.show = function(newOwner, rtl, opt_dispose,
Blockly.WidgetDiv.DIV.style.display = 'block';
};

/**
* Repositions the widgetDiv on window resize. If it doesn't know how to
* calculate the new position, it wll just hide it instead.
*/
Blockly.WidgetDiv.repositionForWindowResize = function() {
// This condition mainly catches the widget div when it is being used as a
// text input. It is important not to close it in this case because on Android,
// when a field is focused, the soft keyboard opens triggering a window resize
// event and we want the widget div to stick around so users can type into it.
if (Blockly.WidgetDiv.owner_
&& Blockly.WidgetDiv.owner_.getScaledBBox_
&& Blockly.WidgetDiv.owner_.getSize) {
var widgetScaledBBox = Blockly.WidgetDiv.owner_.getScaledBBox_();
var widgetSize = Blockly.WidgetDiv.owner_.getSize();
Blockly.WidgetDiv.positionInternal_(widgetScaledBBox.left, widgetScaledBBox.top,
widgetSize.height);
} else {
Blockly.WidgetDiv.hide();
}
};

/**
* Destroy the widget and hide the div.
* @param {boolean=} opt_noAnimate If set, animation will not be run for the hide.
Expand Down