Files
NativeScript/tns-core-modules/ui/activity-indicator/activity-indicator.android.ts
Hristo Hristov 0f14101238 recycling now happens only if nativeView and android properties are not accessed. (#4627)
recycleNativeView filed now accepts: "always" | "never" | "auto". Always will recycle the nativeView no matter if its nativeView or android proprties are accessed. Never will disable recycling. Auto will recycle it only if nativeView and android properties are not accessed.
2017-08-01 15:04:16 +03:00

54 lines
2.1 KiB
TypeScript

import { ActivityIndicatorBase, busyProperty, colorProperty, visibilityProperty, Visibility, Color } from "./activity-indicator-common";
export * from "./activity-indicator-common";
export class ActivityIndicator extends ActivityIndicatorBase {
nativeViewProtected: android.widget.ProgressBar;
public createNativeView() {
const progressBar = new android.widget.ProgressBar(this._context);
progressBar.setVisibility(android.view.View.INVISIBLE);
progressBar.setIndeterminate(true);
return progressBar;
}
[busyProperty.getDefault](): boolean {
return false;
}
[busyProperty.setNative](value: boolean) {
if (this.visibility === Visibility.VISIBLE) {
this.nativeViewProtected.setVisibility(value ? android.view.View.VISIBLE : android.view.View.INVISIBLE);
}
}
[visibilityProperty.getDefault](): Visibility {
return Visibility.HIDDEN;
}
[visibilityProperty.setNative](value: Visibility) {
switch (value) {
case Visibility.VISIBLE:
this.nativeViewProtected.setVisibility(this.busy ? android.view.View.VISIBLE : android.view.View.INVISIBLE);
break;
case Visibility.HIDDEN:
this.nativeViewProtected.setVisibility(android.view.View.INVISIBLE);
break;
case Visibility.COLLAPSE:
this.nativeViewProtected.setVisibility(android.view.View.GONE);
break;
default:
throw new Error(`Invalid visibility value: ${value}. Valid values are: "${Visibility.VISIBLE}", "${Visibility.HIDDEN}", "${Visibility.COLLAPSE}".`);
}
}
[colorProperty.getDefault](): number {
return -1;
}
[colorProperty.setNative](value: number | Color) {
if (value instanceof Color) {
this.nativeViewProtected.getIndeterminateDrawable().setColorFilter(value.android, android.graphics.PorterDuff.Mode.SRC_IN);
} else {
this.nativeViewProtected.getIndeterminateDrawable().clearColorFilter();
}
}
}