Fix #1345. Android triggers a window resize event when the soft keyboard pops up (i.e. when the text field is focused) which caused us to call hideChaff and close the widget div, unfocusing the text input and auto-closing the keyboard. This PR adds a new method to call from the window resize handler that moves the widget div rather than hiding it. (#1743)

This commit is contained in:
picklesrus 2018-10-23 17:02:12 -04:00 committed by GitHub
parent 6da220d4bc
commit a5ff0e1328
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 44 additions and 2 deletions

View file

@ -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();

View file

@ -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);

View file

@ -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.