Merge pull request #514 from yueyuzhao/issue/474

iOS: scroll up a little bit if the textbox is on the bottom half of the screen
This commit is contained in:
chrisgarrity 2021-09-08 13:36:18 -04:00 committed by GitHub
commit 009bcb5be7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -28,7 +28,7 @@ import {newHTML, newDiv, newP, gn,
setCanvasSizeScaledToWindowDocumentHeight, setCanvasSizeScaledToWindowDocumentHeight,
DEGTOR, getIdFor, setProps, isTablet, isiOS, DEGTOR, getIdFor, setProps, isTablet, isiOS,
isAndroid, fitInRect, scaleMultiplier, setCanvasSize, isAndroid, fitInRect, scaleMultiplier, setCanvasSize,
globaly, globalx, rgbToHex} from '../../utils/lib'; globaly, globalx, rgbToHex, WINDOW_INNER_HEIGHT} from '../../utils/lib';
export default class Sprite { export default class Sprite {
constructor (attr, whenDone) { constructor (attr, whenDone) {
@ -913,6 +913,15 @@ export default class Sprite {
me.unfocusText(); me.unfocusText();
}); });
} else { } else {
// On iOS if the bottom of the textbox is lower than half of the screen
// the color and font size menu may be covered by the keyboard
// 0.45 is a magic number and we should compare the bottom Y of the textbox VS
// WINDOW_INNER_HEIGHT substract the keyboard height.
if (gn('textbox').offsetTop + gn('textbox').offsetHeight > WINDOW_INNER_HEIGHT * 0.45) {
// scroll up a little more than the textbox height
// to show the color menu and font size menu.
window.scroll(0, gn('textbox').offsetHeight * 1.2);
}
if (isTablet) { if (isTablet) {
ti.focus(); ti.focus();
} else { } else {