Skip to content

Commit 1d1bf11

Browse files
Duncan UszkayDuncan Uszkay
authored andcommitted
Adjust centering parameters
1 parent 76f1418 commit 1d1bf11

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

components/backdrop/backdrop-loading.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { styleMap } from 'lit/directives/style-map.js';
99

1010
const FADE_DURATION_MS = 500;
1111

12-
const LOADING_SPINNER_MINIMUM_BUFFER = 100;
1312
const LOADING_SPINNER_SIZE = 50;
1413

1514
const reduceMotion = matchMedia('(prefers-reduced-motion: reduce)').matches;
@@ -111,8 +110,8 @@ class LoadingBackdrop extends LocalizeCoreElement(LitElement) {
111110
super();
112111
this.dataState = 'clean';
113112
this._state = 'hidden';
114-
this._spinnerTop = LOADING_SPINNER_MINIMUM_BUFFER;
115-
this._dirtyDialogTop = LOADING_SPINNER_MINIMUM_BUFFER;
113+
this._spinnerTop = 0;
114+
this._dirtyDialogTop = 0;
116115
}
117116

118117
render() {
@@ -161,7 +160,7 @@ class LoadingBackdrop extends LocalizeCoreElement(LitElement) {
161160
}
162161
}
163162

164-
#centerLoadingSpinner() {
163+
async #centerLoadingSpinner() {
165164
if (this._state === 'hidden') { return; }
166165

167166
const loadingSpinner = this.shadowRoot.querySelector('d2l-loading-spinner');
@@ -173,7 +172,7 @@ class LoadingBackdrop extends LocalizeCoreElement(LitElement) {
173172
const upperVisibleBound = Math.max(0, boundingRect.top);
174173
const lowerVisibleBound = Math.min(window.innerHeight, boundingRect.bottom);
175174
const visibleHeight = lowerVisibleBound - upperVisibleBound;
176-
const centeringOffset = visibleHeight / 2;
175+
const centeringOffset = (visibleHeight / 4);
177176

178177
// Calculate if an offset is required to move to the top of the viewport before centering
179178
const topOffset = Math.max(0, -boundingRect.top); // measures the distance below the top of the viewport, which is negative if the element starts above the viewport
@@ -182,10 +181,12 @@ class LoadingBackdrop extends LocalizeCoreElement(LitElement) {
182181
const spinnerSizeOffset = LOADING_SPINNER_SIZE / 2;
183182

184183
// Adjust for the size of the dirty dialog
184+
await this.shadowRoot.querySelector('d2l-empty-state-simple').getUpdateComplete();
185+
await this.shadowRoot.querySelector('d2l-empty-state-action-button').getUpdateComplete();
185186
const dirtyDialogSizeOffset = this.shadowRoot.querySelector('d2l-empty-state-simple').getBoundingClientRect().height / 2;
186187

187-
this._spinnerTop = Math.max(LOADING_SPINNER_MINIMUM_BUFFER, centeringOffset + topOffset - spinnerSizeOffset);
188-
this._dirtyDialogTop = Math.max(LOADING_SPINNER_MINIMUM_BUFFER, centeringOffset + topOffset - dirtyDialogSizeOffset);
188+
this._spinnerTop = centeringOffset + topOffset - spinnerSizeOffset;
189+
this._dirtyDialogTop = centeringOffset + topOffset - dirtyDialogSizeOffset;
189190
}
190191

191192
#fade() {

0 commit comments

Comments
 (0)