Skip to content
This repository has been archived by the owner on Mar 19, 2021. It is now read-only.

Make login screen not jump on small devices #7

Open
wants to merge 1 commit into
base: mobile_support
Choose a base branch
from
Open
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
33 changes: 6 additions & 27 deletions front/src/Phaser/Components/TextInput.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@

const IGNORED_KEYS = new Set([
'Esc',
'Escape',
'Alt',
'Meta',
'Control',
'Ctrl',
'Space',
'Backspace'
])

export class TextInput extends Phaser.GameObjects.BitmapText {
private minUnderLineLength = 4;
private underLine: Phaser.GameObjects.Text;
Expand All @@ -26,26 +14,17 @@ export class TextInput extends Phaser.GameObjects.BitmapText {
this.underLine.setOrigin(0.5);

this.domInput.maxLength = maxLength;
this.domInput.style.opacity = "0";
// Make sure that now scolling is needed and that the input field is
// not visible
this.domInput.setAttribute('style', 'opacity:0;position:absolute;top:0');
if (text) {
this.domInput.value = text;
}

this.domInput.addEventListener('keydown', event => {
if (IGNORED_KEYS.has(event.key)) {
return;
}

if (!/[a-zA-Z0-9:.!&?()+-]/.exec(event.key)) {
event.preventDefault();
}
});

this.domInput.addEventListener('input', (event) => {
if (event.defaultPrevented) {
return;
}
this.text = this.domInput.value;
// Truncate the text to the maximum length, this is needed for mobile
// browsers that don't support the input field `maxLength` attribute
this.text = this.domInput.value.substr(0, maxLength);
this.underLine.text = this.getUnderLineBody(this.text.length);
onChange(this.text);
});
Expand Down