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

Commit 040001a

Browse files
committed
fix(android-loading-indicator): Add internal wait and retry based on popOver creation status.
This works by using a simple recursive promise chain. There is a default timeout of retry attempts of 1000ms.
1 parent 4a03e17 commit 040001a

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/loading-indicator.android.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ function useAndroidX() {
2121
return global.androidx && global.androidx.core.view;
2222
}
2323

24+
const HIDE_RETRY_MS = 100;
25+
2426
export class LoadingIndicator {
2527
private _popOver: android.widget.PopupWindow;
2628
private _currentProgressColor: Color;
@@ -71,10 +73,16 @@ export class LoadingIndicator {
7173
this._updatePopOver(context, options);
7274
}
7375
}
76+
77+
hide(attemptTimeout: number = 1000): void {
78+
if (this._isCreatingPopOver) {
79+
this._waitForCreatePopOver(attemptTimeout);
80+
return;
7481
}
82+
this._tryHide();
7583
}
7684

77-
hide() {
85+
private _tryHide(): void {
7886
try {
7987
for (let i = 0; i < this._loadersInstances.length; i++) {
8088
const loader = this._loadersInstances[i];
@@ -93,6 +101,23 @@ export class LoadingIndicator {
93101
}
94102
}
95103

104+
private _waitForCreatePopOver(attemptTimeout: number) {
105+
const startTime = Date.now();
106+
107+
const awaitCreation = async () => {
108+
if (!this._isCreatingPopOver) {
109+
return this._tryHide();
110+
}
111+
if (Date.now() > startTime + attemptTimeout) {
112+
console.warn('Hide attempt timeout exceeded');
113+
return;
114+
}
115+
await new Promise((resolve) => setTimeout(resolve, HIDE_RETRY_MS));
116+
return awaitCreation();
117+
};
118+
return awaitCreation();
119+
}
120+
96121
private _isShowing(loader: android.widget.PopupWindow) {
97122
return loader.isShowing();
98123
}
Binary file not shown.

0 commit comments

Comments
 (0)