Skip to content
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

fix(ui5-dialog): Texts are no longer blurred in Chromium-based browsers #2417

Merged
merged 5 commits into from
Nov 5, 2020
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
78 changes: 48 additions & 30 deletions packages/main/src/Dialog.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { isPhone, isDesktop } from "@ui5/webcomponents-base/dist/Device.js";
import ResizeHandler from "@ui5/webcomponents-base/dist/delegate/ResizeHandler.js";
import Popup from "./Popup.js";
import "@ui5/webcomponents-icons/dist/icons/resize-corner.js";
import Icon from "./Icon.js";
Expand Down Expand Up @@ -152,6 +153,18 @@ const metadata = {
* @public
*/
class Dialog extends Popup {
constructor() {
super();

this._screenResizeHandler = this._center.bind(this);

this._dragMouseMoveHandler = this._onDragMouseMove.bind(this);
this._dragMouseUpHandler = this._onDragMouseUp.bind(this);

this._resizeMouseMoveHandler = this._onResizeMouseMove.bind(this);
this._resizeMouseUpHandler = this._onResizeMouseUp.bind(this);
}

static get metadata() {
return metadata;
}
Expand Down Expand Up @@ -193,6 +206,11 @@ class Dialog extends Popup {
};
}

show() {
super.show();
this._center();
}

_clamp(val, min, max) {
return Math.min(Math.max(val, min), max);
}
Expand All @@ -204,16 +222,33 @@ class Dialog extends Popup {
}

onEnterDOM() {
this._dragMouseMoveHandler = this._onDragMouseMove.bind(this);
this._dragMouseUpHandler = this._onDragMouseUp.bind(this);

this._resizeMouseMoveHandler = this._onResizeMouseMove.bind(this);
this._resizeMouseUpHandler = this._onResizeMouseUp.bind(this);
ResizeHandler.register(this, this._screenResizeHandler);
ResizeHandler.register(document.body, this._screenResizeHandler);
}

onExitDOM() {
this._dragMouseMoveHandler = null;
this._dragMouseUpHandler = null;
ResizeHandler.deregister(this, this._screenResizeHandler);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This and the next line are repeated several times in the code - not a big deal but maybe move them to a separate function?

ResizeHandler.deregister(document.body, this._screenResizeHandler);
}

_center() {
const height = window.innerHeight - this.offsetHeight,
width = window.innerWidth - this.offsetWidth;

Object.assign(this.style, {
top: `${Math.round(height / 2)}px`,
left: `${Math.round(width / 2)}px`,
});
}

_revertSize() {
Object.assign(this.style, {
top: "",
left: "",
width: "",
height: "",
});
this.removeEventListener("ui5-before-close", this._revertSize);
}

/**
Expand Down Expand Up @@ -242,7 +277,6 @@ class Dialog extends Popup {
} = window.getComputedStyle(this);

Object.assign(this.style, {
transform: "none",
top: `${top}px`,
left: `${left}px`,
width: `${Math.round(Number.parseFloat(width) * 100) / 100}px`,
Expand Down Expand Up @@ -282,25 +316,18 @@ class Dialog extends Popup {
}

_attachDragHandlers() {
ResizeHandler.deregister(this, this._screenResizeHandler);
ResizeHandler.deregister(document.body, this._screenResizeHandler);

window.addEventListener("mousemove", this._dragMouseMoveHandler);
window.addEventListener("mouseup", this._dragMouseUpHandler);
this.addEventListener("ui5-before-close", this._recenter);
}

_detachDragHandlers() {
window.removeEventListener("mousemove", this._dragMouseMoveHandler);
window.removeEventListener("mouseup", this._dragMouseUpHandler);
}

_recenter() {
Object.assign(this.style, {
top: "",
left: "",
transform: "",
});
this.removeEventListener("ui5-before-close", this._recenter);
}

_onResizeMouseDown(event) {
if (!(this.resizable && this.onDesktop)) {
return;
Expand Down Expand Up @@ -329,7 +356,6 @@ class Dialog extends Popup {
this._minHeight = Number.parseFloat(minHeight);

Object.assign(this.style, {
transform: "none",
top: `${top}px`,
left: `${left}px`,
});
Expand Down Expand Up @@ -390,6 +416,9 @@ class Dialog extends Popup {
}

_attachResizeHandlers() {
ResizeHandler.deregister(this, this._screenResizeHandler);
ResizeHandler.deregister(document.body, this._screenResizeHandler);

georgimkv marked this conversation as resolved.
Show resolved Hide resolved
window.addEventListener("mousemove", this._resizeMouseMoveHandler);
window.addEventListener("mouseup", this._resizeMouseUpHandler);
this.addEventListener("ui5-before-close", this._revertSize);
Expand All @@ -399,17 +428,6 @@ class Dialog extends Popup {
window.removeEventListener("mousemove", this._resizeMouseMoveHandler);
window.removeEventListener("mouseup", this._resizeMouseUpHandler);
}

_revertSize() {
Object.assign(this.style, {
top: "",
left: "",
width: "",
height: "",
transform: "",
});
this.removeEventListener("ui5-before-close", this._revertSize);
}
}

Dialog.define();
Expand Down
3 changes: 0 additions & 3 deletions packages/main/src/themes/Dialog.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
:host {
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
min-width: 20rem;
min-height: 6rem;
box-shadow: var(--sapContent_Shadow3);
Expand Down
2 changes: 1 addition & 1 deletion packages/main/test/pages/DialogLifecycle.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

<template id="dt">
<ui5-dialog id="hello-dialog" header-text="Dialogs are easy!">
<div stype="padding: 2rem; display:flex; justify-content: center;">
<div style="padding: 2rem; display:flex; justify-content: center;">
Hello World!
<ui5-button id="closeDialogButton">Dismiss</ui5-button>
</div>
Expand Down