mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-14 10:01:08 +08:00
feat(ios): added activity indicator iosIndicatorViewStyle property (#10650)
This commit is contained in:

committed by
GitHub

parent
e853fca3c9
commit
adaa796bda
@ -1,4 +1,4 @@
|
|||||||
import { ActivityIndicator as ActivityIndicatorDefinition } from '.';
|
import { ActivityIndicator as ActivityIndicatorDefinition, IOSIndicatorViewStyle } from '.';
|
||||||
import { View, CSSType } from '../core/view';
|
import { View, CSSType } from '../core/view';
|
||||||
import { booleanConverter } from '../core/view-base';
|
import { booleanConverter } from '../core/view-base';
|
||||||
import { Property } from '../core/properties';
|
import { Property } from '../core/properties';
|
||||||
@ -6,6 +6,7 @@ import { Property } from '../core/properties';
|
|||||||
@CSSType('ActivityIndicator')
|
@CSSType('ActivityIndicator')
|
||||||
export class ActivityIndicatorBase extends View implements ActivityIndicatorDefinition {
|
export class ActivityIndicatorBase extends View implements ActivityIndicatorDefinition {
|
||||||
public busy: boolean;
|
public busy: boolean;
|
||||||
|
public iosIndicatorViewStyle: IOSIndicatorViewStyle;
|
||||||
}
|
}
|
||||||
|
|
||||||
ActivityIndicatorBase.prototype.recycleNativeView = 'auto';
|
ActivityIndicatorBase.prototype.recycleNativeView = 'auto';
|
||||||
@ -16,3 +17,9 @@ export const busyProperty = new Property<ActivityIndicatorBase, boolean>({
|
|||||||
valueConverter: booleanConverter,
|
valueConverter: booleanConverter,
|
||||||
});
|
});
|
||||||
busyProperty.register(ActivityIndicatorBase);
|
busyProperty.register(ActivityIndicatorBase);
|
||||||
|
|
||||||
|
export const iosIndicatorViewStyleProperty = new Property<ActivityIndicatorBase, IOSIndicatorViewStyle>({
|
||||||
|
name: 'iosIndicatorViewStyle',
|
||||||
|
defaultValue: 'medium',
|
||||||
|
});
|
||||||
|
iosIndicatorViewStyleProperty.register(ActivityIndicatorBase);
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
import { View } from '../core/view';
|
import { View } from '../core/view';
|
||||||
|
|
||||||
|
export type IOSIndicatorViewStyle = 'medium' | 'large';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a UI widget which displays a progress indicator hinting the user for some background operation running.
|
* Represents a UI widget which displays a progress indicator hinting the user for some background operation running.
|
||||||
*
|
*
|
||||||
@ -22,4 +24,9 @@ export class ActivityIndicator extends View {
|
|||||||
* @nsProperty
|
* @nsProperty
|
||||||
*/
|
*/
|
||||||
busy: boolean;
|
busy: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets or sets the iOS indicator view style (e.g. medium, large).
|
||||||
|
*/
|
||||||
|
iosIndicatorViewStyle: IOSIndicatorViewStyle;
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
import { ActivityIndicatorBase, busyProperty } from './activity-indicator-common';
|
import { ActivityIndicatorBase, busyProperty, iosIndicatorViewStyleProperty } from './activity-indicator-common';
|
||||||
import { colorProperty } from '../styling/style-properties';
|
import { colorProperty } from '../styling/style-properties';
|
||||||
import { Color } from '../../color';
|
import { Color } from '../../color';
|
||||||
import { iOSNativeHelper } from '../../utils';
|
import { iOSNativeHelper } from '../../utils';
|
||||||
|
import { IOSIndicatorViewStyle } from '.';
|
||||||
|
|
||||||
export * from './activity-indicator-common';
|
export * from './activity-indicator-common';
|
||||||
|
|
||||||
@ -10,10 +11,8 @@ const majorVersion = iOSNativeHelper.MajorVersion;
|
|||||||
export class ActivityIndicator extends ActivityIndicatorBase {
|
export class ActivityIndicator extends ActivityIndicatorBase {
|
||||||
nativeViewProtected: UIActivityIndicatorView;
|
nativeViewProtected: UIActivityIndicatorView;
|
||||||
|
|
||||||
private _activityIndicatorViewStyle = majorVersion <= 12 || !UIActivityIndicatorViewStyle.Medium ? UIActivityIndicatorViewStyle.Gray : UIActivityIndicatorViewStyle.Medium;
|
|
||||||
|
|
||||||
createNativeView() {
|
createNativeView() {
|
||||||
const viewStyle = this._activityIndicatorViewStyle;
|
const viewStyle = this._getNativeIndicatorViewStyle(this.iosIndicatorViewStyle);
|
||||||
const view = UIActivityIndicatorView.alloc().initWithActivityIndicatorStyle(viewStyle);
|
const view = UIActivityIndicatorView.alloc().initWithActivityIndicatorStyle(viewStyle);
|
||||||
view.hidesWhenStopped = true;
|
view.hidesWhenStopped = true;
|
||||||
|
|
||||||
@ -25,15 +24,27 @@ export class ActivityIndicator extends ActivityIndicatorBase {
|
|||||||
return this.nativeViewProtected;
|
return this.nativeViewProtected;
|
||||||
}
|
}
|
||||||
|
|
||||||
[busyProperty.getDefault](): boolean {
|
private _getNativeIndicatorViewStyle(value: IOSIndicatorViewStyle): UIActivityIndicatorViewStyle {
|
||||||
if ((<any>this.nativeViewProtected).isAnimating) {
|
let viewStyle: UIActivityIndicatorViewStyle;
|
||||||
return (<any>this.nativeViewProtected).isAnimating();
|
|
||||||
} else {
|
switch (value) {
|
||||||
return this.nativeViewProtected.animating;
|
case 'large':
|
||||||
|
viewStyle = majorVersion > 12 ? UIActivityIndicatorViewStyle.Large : UIActivityIndicatorViewStyle.WhiteLarge;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
viewStyle = majorVersion > 12 ? UIActivityIndicatorViewStyle.Medium : UIActivityIndicatorViewStyle.Gray;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return viewStyle;
|
||||||
|
}
|
||||||
|
|
||||||
|
[busyProperty.getDefault](): boolean {
|
||||||
|
return this.nativeViewProtected.animating;
|
||||||
}
|
}
|
||||||
[busyProperty.setNative](value: boolean) {
|
[busyProperty.setNative](value: boolean) {
|
||||||
const nativeView = this.nativeViewProtected;
|
const nativeView = this.nativeViewProtected;
|
||||||
|
|
||||||
if (value) {
|
if (value) {
|
||||||
nativeView.startAnimating();
|
nativeView.startAnimating();
|
||||||
} else {
|
} else {
|
||||||
@ -51,4 +62,8 @@ export class ActivityIndicator extends ActivityIndicatorBase {
|
|||||||
[colorProperty.setNative](value: UIColor | Color) {
|
[colorProperty.setNative](value: UIColor | Color) {
|
||||||
this.nativeViewProtected.color = value instanceof Color ? value.ios : value;
|
this.nativeViewProtected.color = value instanceof Color ? value.ios : value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[iosIndicatorViewStyleProperty.setNative](value: IOSIndicatorViewStyle) {
|
||||||
|
this.nativeViewProtected.activityIndicatorViewStyle = this._getNativeIndicatorViewStyle(value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user