Merge pull request #3816 from NoelDeMartin/MOBILE-4362

MOBILE-4362: Fix Drag & Drop race condition
main
Dani Palou 2023-10-11 15:07:49 +02:00 committed by GitHub
commit edf1aea478
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 4 deletions

View File

@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
import { CoreUtils } from '@services/utils/utils';
import { CoreDom } from '@singletons/dom'; import { CoreDom } from '@singletons/dom';
import { CoreEventObserver } from '@singletons/events'; import { CoreEventObserver } from '@singletons/events';
import { CoreLogger } from '@singletons/logger'; import { CoreLogger } from '@singletons/logger';
@ -148,7 +147,10 @@ export class AddonQtypeDdImageOrTextQuestion {
} }
} }
await CoreUtils.nextTick(); await CoreDom.waitToBeVisible(
this.container.querySelector<HTMLElement>('.ddarea') ??
this.container,
);
// All drag items have been created, position them. // All drag items have been created, position them.
this.repositionDragsForQuestion(); this.repositionDragsForQuestion();

View File

@ -123,9 +123,13 @@ export class CoreDom {
* @returns True if element is visible inside the DOM. * @returns True if element is visible inside the DOM.
*/ */
static isElementVisible(element: HTMLElement, checkSize = true): boolean { static isElementVisible(element: HTMLElement, checkSize = true): boolean {
if (checkSize && (element.clientWidth === 0 || element.clientHeight === 0)) { if (checkSize) {
const dimensions = element.getBoundingClientRect();
if (dimensions.width === 0 || dimensions.height === 0) {
return false; return false;
} }
}
const style = getComputedStyle(element); const style = getComputedStyle(element);
if (style.opacity === '0' || style.display === 'none' || style.visibility === 'hidden') { if (style.opacity === '0' || style.display === 'none' || style.visibility === 'hidden') {