Skip to content

Commit

Permalink
fix(keyboard): detach resize from keyboard events (#112)
Browse files Browse the repository at this point in the history
  • Loading branch information
roman-rr committed Nov 15, 2021
1 parent bf34a24 commit 5d574d7
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 23 deletions.
20 changes: 14 additions & 6 deletions dist/cupertino-pane.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*
* Released under the MIT License
*
* Released on: November 12, 2021
* Released on: November 15, 2021
*/

/*! *****************************************************************************
Expand Down Expand Up @@ -580,6 +580,7 @@ class Events {
}
}
onKeyboardShow(e) {
this.keyboardVisible = true;
// focud element not inside pane
if (!this.isPaneDescendant(document.activeElement)) {
return;
Expand Down Expand Up @@ -625,11 +626,16 @@ class Events {
}
onWindowResize(e) {
return __awaiter(this, void 0, void 0, function* () {
// If form element active - recognize here as Keyboard event
// TODO: if window screen not changed condition also (desktop input focus + resize)
// We should separate keyboard and resize events
// If form element active - recognize here as KeyboardWillShow
if (this.isFormElement(document.activeElement)) {
return;
}
if (!this.isFormElement(document.activeElement)
&& this.keyboardVisible) {
this.keyboardVisible = false;
return;
}
yield new Promise((resolve) => setTimeout(() => resolve(true), 150));
this.instance.updateScreenHeights();
this.breakpoints.buildBreakpoints(JSON.parse(this.breakpoints.lockedBreakpoints));
Expand Down Expand Up @@ -949,9 +955,11 @@ class Breakpoints {
}
// Move to any if removed
if (!((_e = this.settings.breaks[this.prevBreakpoint]) === null || _e === void 0 ? void 0 : _e.enabled)) {
let nextY = this.instance.swipeNextPoint(1, 1, this.getClosestBreakY());
const nextBreak = Object.entries(this.breaks).find(val => val[1] === nextY);
this.instance.moveToBreak(nextBreak[0]);
if (!this.instance.isHidden()) {
let nextY = this.instance.swipeNextPoint(1, 1, this.getClosestBreakY());
const nextBreak = Object.entries(this.breaks).find(val => val[1] === nextY);
this.instance.moveToBreak(nextBreak[0]);
}
}
// Re-calc height and top
this.instance.paneEl.style.top = this.settings.inverse
Expand Down
4 changes: 2 additions & 2 deletions dist/cupertino-pane.esm.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/cupertino-pane.esm.min.js.map

Large diffs are not rendered by default.

20 changes: 14 additions & 6 deletions dist/cupertino-pane.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/cupertino-pane.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions dist/cupertino-pane.min.js

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions src/breakpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,11 @@ export class Breakpoints {

// Move to any if removed
if (!this.settings.breaks[this.prevBreakpoint]?.enabled) {
let nextY = this.instance.swipeNextPoint(1, 1, this.getClosestBreakY());
const nextBreak = Object.entries(this.breaks).find(val => val[1] === nextY);
this.instance.moveToBreak(nextBreak[0]);
if (!this.instance.isHidden()) {
let nextY = this.instance.swipeNextPoint(1, 1, this.getClosestBreakY());
const nextBreak = Object.entries(this.breaks).find(val => val[1] === nextY);
this.instance.moveToBreak(nextBreak[0]);
}
}

// Re-calc height and top
Expand Down
11 changes: 9 additions & 2 deletions src/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,8 @@ export class Events {
*/
public onKeyboardShowCb = (e) => this.onKeyboardShow(e);
private onKeyboardShow(e) {
this.keyboardVisible = true;

// focud element not inside pane
if (!this.isPaneDescendant(document.activeElement)) {
return;
Expand Down Expand Up @@ -524,11 +526,16 @@ export class Events {
*/
public onWindowResizeCb = (e) => this.onWindowResize(e);
private async onWindowResize(e) {
// If form element active - recognize here as Keyboard event
// TODO: if window screen not changed condition also (desktop input focus + resize)
// We should separate keyboard and resize events
// If form element active - recognize here as KeyboardWillShow
if (this.isFormElement(document.activeElement)) {
return;
}
if (!this.isFormElement(document.activeElement)
&& this.keyboardVisible) {
this.keyboardVisible = false;
return;
}

await new Promise((resolve) => setTimeout(() => resolve(true), 150));
this.instance.updateScreenHeights();
Expand Down

0 comments on commit 5d574d7

Please sign in to comment.