@nstudio/nativescript-loading-indicator 3.0.3 → 4.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +0 -0
- package/README.md +18 -34
- package/common.d.ts +83 -0
- package/{loading-indicator.common.js → common.js} +3 -5
- package/common.js.map +1 -0
- package/{loading-indicator.android.d.ts → index.android.d.ts} +2 -2
- package/{loading-indicator.android.js → index.android.js} +188 -190
- package/index.android.js.map +1 -0
- package/index.d.ts +103 -102
- package/{loading-indicator.ios.d.ts → index.ios.d.ts} +2 -2
- package/{loading-indicator.ios.js → index.ios.js} +33 -33
- package/index.ios.js.map +1 -0
- package/package.json +16 -62
- package/platforms/android/AndroidManifest.xml +2 -0
- package/platforms/android/nativescript_loading_indicator.aar +0 -0
- package/platforms/android/res/drawable/circle_shape.xml +6 -0
- package/platforms/android/res/drawable/circular_progress_bar.xml +18 -0
- package/platforms/android/res/drawable/circular_progress_bar_thick.xml +18 -0
- package/loading-indicator.common.d.ts +0 -38
- package/references.d.ts +0 -3
- package/typings/objc!MBProgressHUD.d.ts +0 -240
@@ -1,28 +1,18 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
var color_1 = require("@nativescript/core/color");
|
8
|
-
var image_source_1 = require("@nativescript/core/image-source");
|
9
|
-
var platform_1 = require("@nativescript/core/platform");
|
10
|
-
var frame_1 = require("@nativescript/core/ui/frame");
|
11
|
-
var utils_1 = require("@nativescript/core/utils/utils");
|
12
|
-
var loading_indicator_common_1 = require("./loading-indicator.common");
|
13
|
-
__export(require("./loading-indicator.common"));
|
14
|
-
var R_ATTR_PROGRESS_BAR_STYLE_HORIZONTAL = 0x01010078;
|
15
|
-
var PACKAGE = 'com.github.triniwiz.ns.loading.indicator';
|
16
|
-
var ViewCompatNamespace = useAndroidX()
|
1
|
+
import { Application, Color, Frame, ImageSource, Screen, } from '@nativescript/core';
|
2
|
+
import { Mode } from './common';
|
3
|
+
export * from './common';
|
4
|
+
const R_ATTR_PROGRESS_BAR_STYLE_HORIZONTAL = 0x01010078;
|
5
|
+
const PACKAGE = 'com.github.triniwiz.ns.loading.indicator';
|
6
|
+
const ViewCompatNamespace = useAndroidX()
|
17
7
|
? androidx.core.view
|
18
8
|
: android.support.v4.view;
|
19
9
|
function useAndroidX() {
|
20
10
|
return global.androidx && global.androidx.core.view;
|
21
11
|
}
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
this._defaultProgressColor = new
|
12
|
+
const HIDE_RETRY_MS = 100;
|
13
|
+
export class LoadingIndicator {
|
14
|
+
constructor() {
|
15
|
+
this._defaultProgressColor = new Color('#007DD6');
|
26
16
|
this._progressId = android.view.View.generateViewId();
|
27
17
|
this._messageId = android.view.View.generateViewId();
|
28
18
|
this._detailsId = android.view.View.generateViewId();
|
@@ -30,43 +20,45 @@ var LoadingIndicator = (function () {
|
|
30
20
|
this._loadersInstances = [];
|
31
21
|
this._isCreatingPopOver = false;
|
32
22
|
}
|
33
|
-
|
34
|
-
|
35
|
-
var context = utils_1.ad.getApplicationContext();
|
23
|
+
show(options) {
|
24
|
+
const context = Application.android.foregroundActivity || Application.android.startActivity;
|
36
25
|
if (context) {
|
37
26
|
options = options || {};
|
38
27
|
options.android = options.android || {};
|
39
|
-
options.userInteractionEnabled =
|
28
|
+
options.userInteractionEnabled =
|
29
|
+
options.userInteractionEnabled !== undefined;
|
40
30
|
if (!this._popOver) {
|
41
31
|
this._isCreatingPopOver = true;
|
42
|
-
new Promise(
|
43
|
-
|
44
|
-
|
32
|
+
new Promise((resolve) => {
|
33
|
+
this._createPopOver(context, options);
|
34
|
+
this._loadersInstances.push(this._popOver);
|
45
35
|
resolve();
|
46
|
-
})
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
36
|
+
})
|
37
|
+
.then(() => {
|
38
|
+
this._isCreatingPopOver = false;
|
39
|
+
})
|
40
|
+
.catch((error) => {
|
41
|
+
// Ensure this is left in a clean state.
|
42
|
+
this._isCreatingPopOver = false;
|
43
|
+
const message = error && error.message ? `: ${error.message}` : '';
|
44
|
+
console.error(`Error creating Loading Indicator Pop Over${message}`);
|
52
45
|
});
|
53
46
|
return;
|
54
47
|
}
|
55
48
|
this._updatePopOver(context, options);
|
56
49
|
}
|
57
|
-
}
|
58
|
-
|
59
|
-
if (attemptTimeout === void 0) { attemptTimeout = 1000; }
|
50
|
+
}
|
51
|
+
hide(targetView, attemptTimeout = 1000) {
|
60
52
|
if (this._isCreatingPopOver) {
|
61
53
|
this._waitForCreatePopOver(attemptTimeout);
|
62
54
|
return;
|
63
55
|
}
|
64
56
|
this._tryHide();
|
65
|
-
}
|
66
|
-
|
57
|
+
}
|
58
|
+
_tryHide() {
|
67
59
|
try {
|
68
|
-
for (
|
69
|
-
|
60
|
+
for (let i = 0; i < this._loadersInstances.length; i++) {
|
61
|
+
const loader = this._loadersInstances[i];
|
70
62
|
if (loader) {
|
71
63
|
if (this._isShowing(loader)) {
|
72
64
|
loader.dismiss();
|
@@ -80,48 +72,40 @@ var LoadingIndicator = (function () {
|
|
80
72
|
catch (e) {
|
81
73
|
console.log(e);
|
82
74
|
}
|
83
|
-
}
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
}
|
98
|
-
return [4, new Promise(function (resolve) { return setTimeout(resolve, HIDE_RETRY_MS); })];
|
99
|
-
case 1:
|
100
|
-
_a.sent();
|
101
|
-
return [2, awaitCreation()];
|
102
|
-
}
|
103
|
-
});
|
104
|
-
}); };
|
75
|
+
}
|
76
|
+
_waitForCreatePopOver(attemptTimeout) {
|
77
|
+
const startTime = Date.now();
|
78
|
+
const awaitCreation = async () => {
|
79
|
+
if (!this._isCreatingPopOver) {
|
80
|
+
return this._tryHide();
|
81
|
+
}
|
82
|
+
if (Date.now() > startTime + attemptTimeout) {
|
83
|
+
console.warn('Hide attempt timeout exceeded');
|
84
|
+
return;
|
85
|
+
}
|
86
|
+
await new Promise((resolve) => setTimeout(resolve, HIDE_RETRY_MS));
|
87
|
+
return awaitCreation();
|
88
|
+
};
|
105
89
|
return awaitCreation();
|
106
|
-
}
|
107
|
-
|
90
|
+
}
|
91
|
+
_isShowing(loader) {
|
108
92
|
return loader.isShowing();
|
109
|
-
}
|
110
|
-
|
93
|
+
}
|
94
|
+
_createPopOver(context, options) {
|
111
95
|
this._popOver = new android.widget.PopupWindow();
|
112
|
-
|
96
|
+
const ref = new WeakRef(this);
|
113
97
|
this._popOver.setTouchable(options.userInteractionEnabled);
|
114
|
-
|
115
|
-
|
116
|
-
|
98
|
+
const contentView = new android.widget.LinearLayout(context);
|
99
|
+
const defaultTextColor = new Color(options.color || '#000');
|
100
|
+
const defaultTextNativeColor = defaultTextColor.android
|
117
101
|
? defaultTextColor.android
|
118
102
|
: android.graphics.Color.BLACK;
|
119
|
-
|
103
|
+
const defaultDetailsNativeColor = new Color(255 * 0.8, defaultTextColor.r, defaultTextColor.g, defaultTextColor.b).android;
|
120
104
|
contentView.setOnTouchListener(new android.view.View.OnTouchListener({
|
121
|
-
onTouch
|
122
|
-
|
123
|
-
|
124
|
-
|
105
|
+
onTouch(view, event) {
|
106
|
+
const cancelListener = options.android.cancelListener;
|
107
|
+
const cancelable = options.android.cancelable;
|
108
|
+
const owner = ref.get();
|
125
109
|
if (cancelListener && typeof cancelListener === 'function') {
|
126
110
|
if (owner && cancelable) {
|
127
111
|
owner._popOver.dismiss();
|
@@ -130,43 +114,47 @@ var LoadingIndicator = (function () {
|
|
130
114
|
}
|
131
115
|
}
|
132
116
|
return true;
|
133
|
-
}
|
117
|
+
},
|
134
118
|
}));
|
135
|
-
|
119
|
+
const defaultBackgroundColor = android.graphics.Color.WHITE;
|
120
|
+
// handle dimming background option
|
136
121
|
contentView.setBackgroundColor(options.dimBackground
|
137
|
-
? new
|
122
|
+
? new Color(255 * 0.6, 0, 0, 0).android
|
138
123
|
: android.graphics.Color.TRANSPARENT);
|
139
124
|
contentView.setGravity(android.view.Gravity.CENTER);
|
140
125
|
contentView.setLayoutParams(new android.view.ViewGroup.LayoutParams(android.view.ViewGroup.LayoutParams.FILL_PARENT, android.view.ViewGroup.LayoutParams.FILL_PARENT));
|
141
|
-
|
126
|
+
const parentView = new android.widget.LinearLayout(context);
|
142
127
|
parentView.setOnTouchListener(new android.view.View.OnTouchListener({
|
143
|
-
onTouch
|
128
|
+
onTouch(view, event) {
|
144
129
|
return true;
|
145
|
-
}
|
130
|
+
},
|
146
131
|
}));
|
132
|
+
// Use the ViewCompatNamespace to properly map to `ViewCompat` for AndroidX and support lib versions to avoid breaking change
|
147
133
|
ViewCompatNamespace.ViewCompat.setElevation(parentView, 9.0);
|
148
|
-
|
149
|
-
|
134
|
+
const params = parentView.getLayoutParams();
|
135
|
+
const parentViewParams = params
|
150
136
|
? params
|
151
137
|
: new android.widget.LinearLayout.LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
|
152
|
-
|
138
|
+
const defaultPadding = 10 * Screen.mainScreen.scale;
|
153
139
|
parentView.setPadding(defaultPadding, defaultPadding, defaultPadding, defaultPadding);
|
140
|
+
// handle margin option
|
154
141
|
if (options.margin !== undefined) {
|
155
|
-
|
142
|
+
const margin = options.margin * Screen.mainScreen.scale;
|
156
143
|
parentViewParams.setMargins(margin, margin, margin, margin);
|
157
144
|
}
|
158
145
|
parentView.setLayoutParams(parentViewParams);
|
159
|
-
|
160
|
-
? new
|
146
|
+
const backgroundColor = options.backgroundColor
|
147
|
+
? new Color(options.backgroundColor).android
|
161
148
|
: defaultBackgroundColor;
|
149
|
+
// handle hideBezel option
|
162
150
|
if (options.hideBezel) {
|
163
151
|
parentView.setBackgroundColor(android.graphics.Color.TRANSPARENT);
|
164
152
|
}
|
165
153
|
else {
|
166
|
-
|
154
|
+
const border = new android.graphics.drawable.ShapeDrawable();
|
167
155
|
border.getPaint().setColor(backgroundColor);
|
168
|
-
|
169
|
-
|
156
|
+
const cornerRadiusValue = 8;
|
157
|
+
const cornerRadius = Array.create('float', 8);
|
170
158
|
cornerRadius[0] = cornerRadiusValue;
|
171
159
|
cornerRadius[1] = cornerRadiusValue;
|
172
160
|
cornerRadius[2] = cornerRadiusValue;
|
@@ -175,19 +163,19 @@ var LoadingIndicator = (function () {
|
|
175
163
|
cornerRadius[5] = cornerRadiusValue;
|
176
164
|
cornerRadius[6] = cornerRadiusValue;
|
177
165
|
cornerRadius[7] = cornerRadiusValue;
|
178
|
-
|
166
|
+
const shape = new android.graphics.drawable.shapes.RoundRectShape(cornerRadius, null, null);
|
179
167
|
border.setShape(shape);
|
180
168
|
parentView.setBackgroundDrawable(border);
|
181
169
|
}
|
182
170
|
parentView.setGravity(android.view.Gravity.CENTER);
|
183
171
|
parentView.setOrientation(android.widget.LinearLayout.VERTICAL);
|
184
|
-
|
185
|
-
|
172
|
+
let progressView;
|
173
|
+
const customOrText = options.mode === Mode.CustomView || options.mode === Mode.Text;
|
186
174
|
if (!customOrText) {
|
187
|
-
|
188
|
-
options.mode ===
|
189
|
-
options.mode ===
|
190
|
-
options.mode ===
|
175
|
+
const determinate = options.progress !== undefined ||
|
176
|
+
options.mode === Mode.Determinate ||
|
177
|
+
options.mode === Mode.DeterminateHorizontalBar ||
|
178
|
+
options.mode === Mode.AnnularDeterminate;
|
191
179
|
if (determinate) {
|
192
180
|
progressView = new android.widget.ProgressBar(context, null, R_ATTR_PROGRESS_BAR_STYLE_HORIZONTAL);
|
193
181
|
}
|
@@ -197,16 +185,17 @@ var LoadingIndicator = (function () {
|
|
197
185
|
progressView.setId(this._progressId);
|
198
186
|
parentView.addView(progressView);
|
199
187
|
}
|
200
|
-
|
188
|
+
// handle customView option
|
189
|
+
if (options.mode === Mode.CustomView) {
|
201
190
|
if (options.customView) {
|
202
|
-
|
191
|
+
const customView = this._createCustomView(context, options);
|
203
192
|
if (customView) {
|
204
193
|
parentView.addView(customView);
|
205
194
|
}
|
206
195
|
}
|
207
196
|
}
|
208
197
|
if (options.message) {
|
209
|
-
|
198
|
+
const messageView = new android.widget.TextView(context);
|
210
199
|
messageView.setText(options.message);
|
211
200
|
messageView.setId(this._messageId);
|
212
201
|
if (options.color) {
|
@@ -215,8 +204,9 @@ var LoadingIndicator = (function () {
|
|
215
204
|
messageView.setLayoutParams(new android.widget.LinearLayout.LayoutParams(android.widget.LinearLayout.LayoutParams.WRAP_CONTENT, android.widget.LinearLayout.LayoutParams.WRAP_CONTENT));
|
216
205
|
parentView.addView(messageView);
|
217
206
|
}
|
207
|
+
// handle details message text
|
218
208
|
if (options.details) {
|
219
|
-
|
209
|
+
const detailsView = new android.widget.TextView(context);
|
220
210
|
detailsView.setText(options.details);
|
221
211
|
detailsView.setId(this._detailsId);
|
222
212
|
detailsView.setTextColor(defaultDetailsNativeColor);
|
@@ -224,32 +214,32 @@ var LoadingIndicator = (function () {
|
|
224
214
|
parentView.addView(detailsView);
|
225
215
|
}
|
226
216
|
switch (options.mode) {
|
227
|
-
case
|
217
|
+
case Mode.CustomView:
|
228
218
|
break;
|
229
|
-
case
|
219
|
+
case Mode.AnnularDeterminate:
|
230
220
|
progressView.setIndeterminate(false);
|
231
221
|
progressView.setMax(100);
|
232
222
|
progressView.setProgress(0);
|
233
223
|
progressView.setProgressDrawable(this._getProgressDrawable());
|
234
224
|
progressView.setBackgroundDrawable(this._getBackgroundDrawable());
|
235
|
-
progressView.setLayoutParams(new android.widget.LinearLayout.LayoutParams(60 *
|
225
|
+
progressView.setLayoutParams(new android.widget.LinearLayout.LayoutParams(60 * Screen.mainScreen.scale, 60 * Screen.mainScreen.scale));
|
236
226
|
break;
|
237
|
-
case
|
227
|
+
case Mode.Determinate:
|
238
228
|
progressView.setIndeterminate(false);
|
239
229
|
progressView.setMax(100);
|
240
230
|
progressView.setProgress(0);
|
241
231
|
progressView.setProgressDrawable(this._getProgressDrawableThick());
|
242
232
|
progressView.setBackgroundDrawable(this._getBackgroundDrawable());
|
243
|
-
progressView.setLayoutParams(new android.widget.LinearLayout.LayoutParams(60 *
|
233
|
+
progressView.setLayoutParams(new android.widget.LinearLayout.LayoutParams(60 * Screen.mainScreen.scale, 60 * Screen.mainScreen.scale));
|
244
234
|
break;
|
245
|
-
case
|
235
|
+
case Mode.DeterminateHorizontalBar:
|
246
236
|
progressView.setIndeterminate(false);
|
247
237
|
progressView.setMax(100);
|
248
238
|
progressView.setProgress(0);
|
249
239
|
break;
|
250
|
-
case
|
240
|
+
case Mode.Text:
|
251
241
|
break;
|
252
|
-
case
|
242
|
+
case Mode.Indeterminate:
|
253
243
|
progressView.setIndeterminate(true);
|
254
244
|
break;
|
255
245
|
default:
|
@@ -257,70 +247,72 @@ var LoadingIndicator = (function () {
|
|
257
247
|
break;
|
258
248
|
}
|
259
249
|
if (options.progress !== undefined ||
|
260
|
-
options.mode ===
|
261
|
-
options.mode ===
|
262
|
-
options.mode ===
|
263
|
-
options.mode ===
|
250
|
+
options.mode === Mode.Determinate ||
|
251
|
+
options.mode === Mode.AnnularDeterminate ||
|
252
|
+
options.mode === Mode.DeterminateHorizontalBar ||
|
253
|
+
options.mode === Mode.Indeterminate ||
|
264
254
|
!options.mode) {
|
265
255
|
if (options.color) {
|
266
256
|
this._setColor(options.color, progressView);
|
267
|
-
this._currentProgressColor = new
|
257
|
+
this._currentProgressColor = new Color(options.color);
|
268
258
|
}
|
259
|
+
// handle background color
|
269
260
|
if (options.backgroundColor) {
|
270
261
|
this._setBackgroundColor(options.backgroundColor, progressView);
|
271
262
|
}
|
272
263
|
}
|
273
264
|
contentView.addView(parentView);
|
274
265
|
this._popOver.setContentView(contentView);
|
275
|
-
|
276
|
-
frame_1.Frame.topmost().currentPage.android;
|
266
|
+
// handle anchoring target view
|
277
267
|
if (options.android && options.android.view) {
|
278
|
-
|
268
|
+
const nativeView = options.android.view;
|
279
269
|
this._popOver.setWidth(nativeView.getWidth());
|
280
270
|
this._popOver.setHeight(nativeView.getHeight());
|
281
271
|
this._popOver.showAtLocation(nativeView, android.view.Gravity.CENTER, 0, 0);
|
282
272
|
}
|
283
|
-
else {
|
284
|
-
|
285
|
-
|
273
|
+
else if (Frame.topmost() && (Frame.topmost().android || (Frame.topmost().currentPage && Frame.topmost().currentPage.android))) {
|
274
|
+
const view = Frame.topmost().android.rootViewGroup ||
|
275
|
+
Frame.topmost().currentPage.android;
|
276
|
+
this._popOver.setWidth(Screen.mainScreen.widthPixels);
|
277
|
+
this._popOver.setHeight(Screen.mainScreen.heightPixels);
|
286
278
|
this._popOver.showAtLocation(view, android.view.Gravity.CENTER, 0, 0);
|
287
279
|
}
|
288
|
-
}
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
280
|
+
}
|
281
|
+
_updatePopOver(context, options) {
|
282
|
+
const contentView = this._popOver.getContentView();
|
283
|
+
const parentView = contentView.getChildAt(0);
|
284
|
+
let count = parentView.getChildCount();
|
285
|
+
const defaultTextColor = new Color(options.color || 'black');
|
286
|
+
const defaultTextNativeColor = defaultTextColor.android
|
295
287
|
? defaultTextColor.android
|
296
288
|
: android.graphics.Color.BLACK;
|
297
|
-
|
298
|
-
if (options.mode ===
|
299
|
-
|
289
|
+
const defaultDetailsNativeColor = new Color(255 * 0.8, defaultTextColor.r, defaultTextColor.g, defaultTextColor.b).android;
|
290
|
+
if (options.mode === Mode.Text) {
|
291
|
+
const progressView = parentView.getChildAt(0);
|
300
292
|
if (progressView) {
|
301
|
-
|
293
|
+
const progressViewId = progressView.getId();
|
302
294
|
if (progressViewId === this._progressId) {
|
303
295
|
parentView.removeView(progressView);
|
304
296
|
count = parentView.getChildCount();
|
305
297
|
}
|
306
298
|
}
|
307
299
|
}
|
308
|
-
if (options.mode ===
|
309
|
-
for (
|
310
|
-
|
300
|
+
if (options.mode === Mode.CustomView) {
|
301
|
+
for (let i = 0; i < count; i++) {
|
302
|
+
const view = parentView.getChildAt(i);
|
311
303
|
parentView.removeView(view);
|
312
304
|
}
|
313
|
-
|
305
|
+
const customView = this._createCustomView(context, options);
|
314
306
|
if (customView) {
|
315
307
|
parentView.addView(customView);
|
316
308
|
}
|
317
309
|
count = parentView.getChildCount();
|
318
310
|
}
|
319
311
|
if (options.progress &&
|
320
|
-
options.mode !==
|
321
|
-
options.mode !==
|
322
|
-
|
323
|
-
|
312
|
+
options.mode !== Mode.Text &&
|
313
|
+
options.mode !== Mode.CustomView) {
|
314
|
+
let progressView = parentView.getChildAt(0);
|
315
|
+
const progressViewId = progressView.getId();
|
324
316
|
if (progressView instanceof android.widget.ProgressBar &&
|
325
317
|
progressViewId === this._progressId &&
|
326
318
|
progressView.isIndeterminate()) {
|
@@ -335,34 +327,41 @@ var LoadingIndicator = (function () {
|
|
335
327
|
count = parentView.getChildCount();
|
336
328
|
if (options.color) {
|
337
329
|
this._setColor(options.color, progressView);
|
338
|
-
this._currentProgressColor = new
|
330
|
+
this._currentProgressColor = new Color(options.color);
|
339
331
|
}
|
332
|
+
// handle background color
|
340
333
|
if (options.backgroundColor) {
|
341
334
|
this._setBackgroundColor(options.backgroundColor, progressView);
|
342
335
|
}
|
343
336
|
progressView.setProgress(options.progress * 100);
|
344
337
|
}
|
345
338
|
if (!options.progress &&
|
346
|
-
options.mode !==
|
347
|
-
options.mode !==
|
348
|
-
options.mode ===
|
349
|
-
|
350
|
-
|
339
|
+
options.mode !== Mode.Text &&
|
340
|
+
options.mode !== Mode.CustomView &&
|
341
|
+
options.mode === Mode.Indeterminate) {
|
342
|
+
/**
|
343
|
+
* Get the existing indicator if it exists, assess whether or not the
|
344
|
+
* acquired child is the correct class.
|
345
|
+
*/
|
346
|
+
let progressView = parentView.getChildAt(0);
|
347
|
+
if (progressView instanceof android.widget.ProgressBar === false ||
|
348
|
+
progressView === undefined) {
|
351
349
|
progressView = new android.widget.ProgressBar(context);
|
352
350
|
}
|
353
351
|
if (options.color) {
|
354
352
|
this._setColor(options.color, progressView);
|
355
|
-
this._currentProgressColor = new
|
353
|
+
this._currentProgressColor = new Color(options.color);
|
356
354
|
}
|
355
|
+
// handle background color
|
357
356
|
if (options.backgroundColor) {
|
358
357
|
this._setBackgroundColor(options.backgroundColor, progressView);
|
359
358
|
}
|
360
359
|
count = parentView.getChildCount();
|
361
360
|
}
|
362
361
|
if (options.message) {
|
363
|
-
|
364
|
-
|
365
|
-
|
362
|
+
let messageView;
|
363
|
+
let view;
|
364
|
+
const firstView = parentView.getChildAt(0);
|
366
365
|
switch (count) {
|
367
366
|
case 1:
|
368
367
|
if (firstView.getId() === this._messageId) {
|
@@ -380,7 +379,7 @@ var LoadingIndicator = (function () {
|
|
380
379
|
break;
|
381
380
|
case 2:
|
382
381
|
view = parentView.getChildAt(1);
|
383
|
-
|
382
|
+
const viewId = view.getId();
|
384
383
|
if (viewId === this._messageId) {
|
385
384
|
view.setText(options.message);
|
386
385
|
view.setTextColor(defaultTextNativeColor);
|
@@ -404,11 +403,12 @@ var LoadingIndicator = (function () {
|
|
404
403
|
}
|
405
404
|
count = parentView.getChildCount();
|
406
405
|
}
|
406
|
+
// handle details message text
|
407
407
|
if (options.details) {
|
408
|
-
|
408
|
+
let detailsView;
|
409
409
|
switch (count) {
|
410
410
|
case 1:
|
411
|
-
|
411
|
+
const firstView = parentView.getChildAt(0);
|
412
412
|
if (firstView === this._detailsId) {
|
413
413
|
firstView.setTextColor(defaultDetailsNativeColor);
|
414
414
|
firstView.setText(options.details);
|
@@ -424,7 +424,7 @@ var LoadingIndicator = (function () {
|
|
424
424
|
break;
|
425
425
|
case 2:
|
426
426
|
detailsView = parentView.getChildAt(1);
|
427
|
-
|
427
|
+
const detailsViewId = detailsView.getId();
|
428
428
|
if (detailsViewId === this._detailsId) {
|
429
429
|
detailsView.setTextColor(defaultDetailsNativeColor);
|
430
430
|
detailsView.setText(options.details);
|
@@ -448,9 +448,9 @@ var LoadingIndicator = (function () {
|
|
448
448
|
}
|
449
449
|
}
|
450
450
|
this._popOver.update();
|
451
|
-
}
|
452
|
-
|
453
|
-
|
451
|
+
}
|
452
|
+
_createCustomView(context, options) {
|
453
|
+
let customView;
|
454
454
|
if (options.customView instanceof android.graphics.Bitmap) {
|
455
455
|
customView = new android.widget.ImageView(context);
|
456
456
|
customView.setImageBitmap(options.customView);
|
@@ -460,72 +460,70 @@ var LoadingIndicator = (function () {
|
|
460
460
|
}
|
461
461
|
else if (typeof options.customView === 'string') {
|
462
462
|
customView = new android.widget.ImageView(context);
|
463
|
-
|
463
|
+
const fileName = options.customView
|
464
464
|
.replace('.jpg', '')
|
465
465
|
.replace('.png', '')
|
466
466
|
.replace('.jpeg', '');
|
467
|
-
|
467
|
+
const image = ImageSource.fromFileOrResourceSync('res://' + fileName);
|
468
468
|
if (image && image.android) {
|
469
469
|
customView.setImageBitmap(image.android);
|
470
470
|
}
|
471
471
|
}
|
472
472
|
customView.setId(this._customViewId);
|
473
473
|
return customView;
|
474
|
-
}
|
475
|
-
|
476
|
-
|
474
|
+
}
|
475
|
+
_createDeterminateProgressView(context) {
|
476
|
+
const progressView = new android.widget.ProgressBar(context, null, R_ATTR_PROGRESS_BAR_STYLE_HORIZONTAL);
|
477
477
|
progressView.setId(this._progressId);
|
478
478
|
progressView.setMax(100);
|
479
479
|
progressView.setProgress(0);
|
480
480
|
progressView.setProgressDrawable(this._getProgressDrawable());
|
481
481
|
progressView.setBackgroundDrawable(this._getBackgroundDrawable());
|
482
|
-
progressView.setLayoutParams(new android.widget.LinearLayout.LayoutParams(60 *
|
482
|
+
progressView.setLayoutParams(new android.widget.LinearLayout.LayoutParams(60 * Screen.mainScreen.scale, 60 * Screen.mainScreen.scale));
|
483
483
|
return progressView;
|
484
|
-
}
|
485
|
-
|
486
|
-
|
487
|
-
|
484
|
+
}
|
485
|
+
_setBackgroundColor(color, view) {
|
486
|
+
const progressDrawable = view.getProgressDrawable();
|
487
|
+
const indeterminateDrawable = view.getIndeterminateDrawable();
|
488
488
|
if (progressDrawable instanceof android.graphics.drawable.LayerDrawable &&
|
489
489
|
progressDrawable.getNumberOfLayers() > 0) {
|
490
|
-
|
490
|
+
const backgroundDrawable = progressDrawable.getDrawable(0);
|
491
491
|
if (backgroundDrawable) {
|
492
|
-
backgroundDrawable.setColorFilter(new
|
492
|
+
backgroundDrawable.setColorFilter(new Color(color).android, android.graphics.PorterDuff.Mode.SRC_IN);
|
493
493
|
}
|
494
494
|
}
|
495
495
|
if (indeterminateDrawable instanceof
|
496
496
|
android.graphics.drawable.LayerDrawable &&
|
497
497
|
indeterminateDrawable.getNumberOfLayers() > 0) {
|
498
|
-
|
498
|
+
const backgroundDrawable = indeterminateDrawable.getDrawable(0);
|
499
499
|
if (backgroundDrawable) {
|
500
|
-
backgroundDrawable.setColorFilter(new
|
500
|
+
backgroundDrawable.setColorFilter(new Color(color).android, android.graphics.PorterDuff.Mode.SRC_IN);
|
501
501
|
}
|
502
502
|
}
|
503
|
-
}
|
504
|
-
|
505
|
-
|
506
|
-
|
503
|
+
}
|
504
|
+
_setColor(color, view) {
|
505
|
+
const progressDrawable = view.getProgressDrawable();
|
506
|
+
const indeterminateDrawable = view.getIndeterminateDrawable();
|
507
507
|
if (progressDrawable) {
|
508
|
-
progressDrawable.setColorFilter(new
|
508
|
+
progressDrawable.setColorFilter(new Color(color).android, android.graphics.PorterDuff.Mode.SRC_IN);
|
509
509
|
}
|
510
510
|
if (indeterminateDrawable) {
|
511
|
-
indeterminateDrawable.setColorFilter(new
|
511
|
+
indeterminateDrawable.setColorFilter(new Color(color).android, android.graphics.PorterDuff.Mode.SRC_IN);
|
512
512
|
}
|
513
|
-
}
|
514
|
-
|
515
|
-
|
513
|
+
}
|
514
|
+
_getResources() {
|
515
|
+
const ctx = Application.android.foregroundActivity;
|
516
516
|
return ctx.getResources();
|
517
|
-
}
|
518
|
-
|
517
|
+
}
|
518
|
+
_getBackgroundDrawable() {
|
519
519
|
return this._getResources().getDrawable(com.github.triniwiz.ns.loading.indicator.R.drawable.circle_shape);
|
520
|
-
}
|
521
|
-
|
520
|
+
}
|
521
|
+
_getProgressDrawable() {
|
522
522
|
return this._getResources().getDrawable(com.github.triniwiz.ns.loading.indicator.R.drawable.circular_progress_bar);
|
523
|
-
}
|
524
|
-
|
523
|
+
}
|
524
|
+
_getProgressDrawableThick() {
|
525
525
|
return this._getResources().getDrawable(com.github.triniwiz.ns.loading.indicator.R.drawable
|
526
526
|
.circular_progress_bar_thick);
|
527
|
-
}
|
528
|
-
|
529
|
-
|
530
|
-
exports.LoadingIndicator = LoadingIndicator;
|
531
|
-
//# sourceMappingURL=loading-indicator.android.js.map
|
527
|
+
}
|
528
|
+
}
|
529
|
+
//# sourceMappingURL=index.android.js.map
|