@@ -21,6 +21,8 @@ function useAndroidX() {
21
21
return global . androidx && global . androidx . core . view ;
22
22
}
23
23
24
+ const HIDE_RETRY_MS = 100 ;
25
+
24
26
export class LoadingIndicator {
25
27
private _popOver : android . widget . PopupWindow ;
26
28
private _currentProgressColor : Color ;
@@ -71,10 +73,16 @@ export class LoadingIndicator {
71
73
this . _updatePopOver ( context , options ) ;
72
74
}
73
75
}
76
+
77
+ hide ( attemptTimeout : number = 1000 ) : void {
78
+ if ( this . _isCreatingPopOver ) {
79
+ this . _waitForCreatePopOver ( attemptTimeout ) ;
80
+ return ;
74
81
}
82
+ this . _tryHide ( ) ;
75
83
}
76
84
77
- hide ( ) {
85
+ private _tryHide ( ) : void {
78
86
try {
79
87
for ( let i = 0 ; i < this . _loadersInstances . length ; i ++ ) {
80
88
const loader = this . _loadersInstances [ i ] ;
@@ -93,6 +101,23 @@ export class LoadingIndicator {
93
101
}
94
102
}
95
103
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
+
96
121
private _isShowing ( loader : android . widget . PopupWindow ) {
97
122
return loader . isShowing ( ) ;
98
123
}
0 commit comments