mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
chore: cleanup
This commit is contained in:
@@ -1,19 +1,18 @@
|
||||
import { ActivityIndicator as ActivityIndicatorDefinition } from ".";
|
||||
import { View, CSSType } from "../core/view";
|
||||
import { booleanConverter } from "../core/view-base";
|
||||
import { Property } from "../core/properties";
|
||||
import { ActivityIndicator as ActivityIndicatorDefinition } from '.';
|
||||
import { View, CSSType } from '../core/view';
|
||||
import { booleanConverter } from '../core/view-base';
|
||||
import { Property } from '../core/properties';
|
||||
|
||||
@CSSType("ActivityIndicator")
|
||||
export class ActivityIndicatorBase extends View
|
||||
implements ActivityIndicatorDefinition {
|
||||
public busy: boolean;
|
||||
@CSSType('ActivityIndicator')
|
||||
export class ActivityIndicatorBase extends View implements ActivityIndicatorDefinition {
|
||||
public busy: boolean;
|
||||
}
|
||||
|
||||
ActivityIndicatorBase.prototype.recycleNativeView = "auto";
|
||||
ActivityIndicatorBase.prototype.recycleNativeView = 'auto';
|
||||
|
||||
export const busyProperty = new Property<ActivityIndicatorBase, boolean>({
|
||||
name: "busy",
|
||||
defaultValue: false,
|
||||
valueConverter: booleanConverter,
|
||||
name: 'busy',
|
||||
defaultValue: false,
|
||||
valueConverter: booleanConverter,
|
||||
});
|
||||
busyProperty.register(ActivityIndicatorBase);
|
||||
|
||||
@@ -1,80 +1,56 @@
|
||||
import {
|
||||
ActivityIndicatorBase,
|
||||
busyProperty,
|
||||
} from "./activity-indicator-common";
|
||||
import {
|
||||
colorProperty,
|
||||
visibilityProperty,
|
||||
Visibility,
|
||||
} from "../styling/style-properties";
|
||||
import { Color } from "../../color";
|
||||
import { ActivityIndicatorBase, busyProperty } from './activity-indicator-common';
|
||||
import { colorProperty, visibilityProperty, Visibility } from '../styling/style-properties';
|
||||
import { Color } from '../../color';
|
||||
|
||||
export * from "./activity-indicator-common";
|
||||
export * from './activity-indicator-common';
|
||||
|
||||
export class ActivityIndicator extends ActivityIndicatorBase {
|
||||
nativeViewProtected: android.widget.ProgressBar;
|
||||
nativeViewProtected: android.widget.ProgressBar;
|
||||
|
||||
public createNativeView() {
|
||||
const progressBar = new android.widget.ProgressBar(this._context);
|
||||
progressBar.setVisibility(android.view.View.INVISIBLE);
|
||||
progressBar.setIndeterminate(true);
|
||||
public createNativeView() {
|
||||
const progressBar = new android.widget.ProgressBar(this._context);
|
||||
progressBar.setVisibility(android.view.View.INVISIBLE);
|
||||
progressBar.setIndeterminate(true);
|
||||
|
||||
return progressBar;
|
||||
}
|
||||
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
|
||||
);
|
||||
}
|
||||
}
|
||||
[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}".`
|
||||
);
|
||||
}
|
||||
}
|
||||
[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();
|
||||
}
|
||||
}
|
||||
[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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
import { View } from "../core/view";
|
||||
import { View } from '../core/view';
|
||||
|
||||
/**
|
||||
* Represents a UI widget which displays a progress indicator hinting the user for some background operation running.
|
||||
*/
|
||||
export class ActivityIndicator extends View {
|
||||
/**
|
||||
* Gets the native [android widget](http://developer.android.com/reference/android/widget/ProgressBar.html) that represents the user interface for this component. Valid only when running on Android OS.
|
||||
*/
|
||||
android: any /* android.widget.ProgressBar */;
|
||||
/**
|
||||
* Gets the native [android widget](http://developer.android.com/reference/android/widget/ProgressBar.html) that represents the user interface for this component. Valid only when running on Android OS.
|
||||
*/
|
||||
android: any /* android.widget.ProgressBar */;
|
||||
|
||||
/**
|
||||
* Gets the native iOS [UIActivityIndicatorView](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIActivityIndicatorView_Class/index.html) that represents the user interface for this component. Valid only when running on iOS.
|
||||
*/
|
||||
ios: any /* UIActivityIndicatorView */;
|
||||
/**
|
||||
* Gets the native iOS [UIActivityIndicatorView](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIActivityIndicatorView_Class/index.html) that represents the user interface for this component. Valid only when running on iOS.
|
||||
*/
|
||||
ios: any /* UIActivityIndicatorView */;
|
||||
|
||||
/**
|
||||
* Gets or sets a value indicating whether the widget is currently displaying progress.
|
||||
*/
|
||||
busy: boolean;
|
||||
/**
|
||||
* Gets or sets a value indicating whether the widget is currently displaying progress.
|
||||
*/
|
||||
busy: boolean;
|
||||
}
|
||||
|
||||
@@ -1,62 +1,53 @@
|
||||
import {
|
||||
ActivityIndicatorBase,
|
||||
busyProperty,
|
||||
} from "./activity-indicator-common";
|
||||
import { colorProperty } from "../styling/style-properties";
|
||||
import { Color } from "../../color";
|
||||
import { ios } from "../../utils/utils";
|
||||
import { ActivityIndicatorBase, busyProperty } from './activity-indicator-common';
|
||||
import { colorProperty } from '../styling/style-properties';
|
||||
import { Color } from '../../color';
|
||||
import { ios } from '../../utils';
|
||||
|
||||
export * from "./activity-indicator-common";
|
||||
export * from './activity-indicator-common';
|
||||
|
||||
const majorVersion = ios.MajorVersion;
|
||||
|
||||
export class ActivityIndicator extends ActivityIndicatorBase {
|
||||
nativeViewProtected: UIActivityIndicatorView;
|
||||
nativeViewProtected: UIActivityIndicatorView;
|
||||
|
||||
private _activityIndicatorViewStyle =
|
||||
majorVersion <= 12 || !UIActivityIndicatorViewStyle.Medium
|
||||
? UIActivityIndicatorViewStyle.Gray
|
||||
: UIActivityIndicatorViewStyle.Medium;
|
||||
private _activityIndicatorViewStyle = majorVersion <= 12 || !UIActivityIndicatorViewStyle.Medium ? UIActivityIndicatorViewStyle.Gray : UIActivityIndicatorViewStyle.Medium;
|
||||
|
||||
createNativeView() {
|
||||
const viewStyle = this._activityIndicatorViewStyle;
|
||||
const view = UIActivityIndicatorView.alloc().initWithActivityIndicatorStyle(
|
||||
viewStyle
|
||||
);
|
||||
view.hidesWhenStopped = true;
|
||||
createNativeView() {
|
||||
const viewStyle = this._activityIndicatorViewStyle;
|
||||
const view = UIActivityIndicatorView.alloc().initWithActivityIndicatorStyle(viewStyle);
|
||||
view.hidesWhenStopped = true;
|
||||
|
||||
return view;
|
||||
}
|
||||
return view;
|
||||
}
|
||||
|
||||
get ios(): UIActivityIndicatorView {
|
||||
return this.nativeViewProtected;
|
||||
}
|
||||
get ios(): UIActivityIndicatorView {
|
||||
return this.nativeViewProtected;
|
||||
}
|
||||
|
||||
[busyProperty.getDefault](): boolean {
|
||||
if ((<any>this.nativeViewProtected).isAnimating) {
|
||||
return (<any>this.nativeViewProtected).isAnimating();
|
||||
} else {
|
||||
return this.nativeViewProtected.animating;
|
||||
}
|
||||
}
|
||||
[busyProperty.setNative](value: boolean) {
|
||||
let nativeView = this.nativeViewProtected;
|
||||
if (value) {
|
||||
nativeView.startAnimating();
|
||||
} else {
|
||||
nativeView.stopAnimating();
|
||||
}
|
||||
[busyProperty.getDefault](): boolean {
|
||||
if ((<any>this.nativeViewProtected).isAnimating) {
|
||||
return (<any>this.nativeViewProtected).isAnimating();
|
||||
} else {
|
||||
return this.nativeViewProtected.animating;
|
||||
}
|
||||
}
|
||||
[busyProperty.setNative](value: boolean) {
|
||||
let nativeView = this.nativeViewProtected;
|
||||
if (value) {
|
||||
nativeView.startAnimating();
|
||||
} else {
|
||||
nativeView.stopAnimating();
|
||||
}
|
||||
|
||||
if (nativeView.hidesWhenStopped) {
|
||||
this.requestLayout();
|
||||
}
|
||||
}
|
||||
if (nativeView.hidesWhenStopped) {
|
||||
this.requestLayout();
|
||||
}
|
||||
}
|
||||
|
||||
[colorProperty.getDefault](): UIColor {
|
||||
return this.nativeViewProtected.color;
|
||||
}
|
||||
[colorProperty.setNative](value: UIColor | Color) {
|
||||
this.nativeViewProtected.color =
|
||||
value instanceof Color ? value.ios : value;
|
||||
}
|
||||
[colorProperty.getDefault](): UIColor {
|
||||
return this.nativeViewProtected.color;
|
||||
}
|
||||
[colorProperty.setNative](value: UIColor | Color) {
|
||||
this.nativeViewProtected.color = value instanceof Color ? value.ios : value;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user