Skip to content

Commit adaa796

Browse files
authored
feat(ios): added activity indicator iosIndicatorViewStyle property (NativeScript#10650)
1 parent e853fca commit adaa796

File tree

3 files changed

+39
-10
lines changed

3 files changed

+39
-10
lines changed

packages/core/ui/activity-indicator/activity-indicator-common.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import { ActivityIndicator as ActivityIndicatorDefinition } from '.';
1+
import { ActivityIndicator as ActivityIndicatorDefinition, IOSIndicatorViewStyle } from '.';
22
import { View, CSSType } from '../core/view';
33
import { booleanConverter } from '../core/view-base';
44
import { Property } from '../core/properties';
55

66
@CSSType('ActivityIndicator')
77
export class ActivityIndicatorBase extends View implements ActivityIndicatorDefinition {
88
public busy: boolean;
9+
public iosIndicatorViewStyle: IOSIndicatorViewStyle;
910
}
1011

1112
ActivityIndicatorBase.prototype.recycleNativeView = 'auto';
@@ -16,3 +17,9 @@ export const busyProperty = new Property<ActivityIndicatorBase, boolean>({
1617
valueConverter: booleanConverter,
1718
});
1819
busyProperty.register(ActivityIndicatorBase);
20+
21+
export const iosIndicatorViewStyleProperty = new Property<ActivityIndicatorBase, IOSIndicatorViewStyle>({
22+
name: 'iosIndicatorViewStyle',
23+
defaultValue: 'medium',
24+
});
25+
iosIndicatorViewStyleProperty.register(ActivityIndicatorBase);

packages/core/ui/activity-indicator/index.d.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { View } from '../core/view';
22

3+
export type IOSIndicatorViewStyle = 'medium' | 'large';
4+
35
/**
46
* Represents a UI widget which displays a progress indicator hinting the user for some background operation running.
57
*
@@ -22,4 +24,9 @@ export class ActivityIndicator extends View {
2224
* @nsProperty
2325
*/
2426
busy: boolean;
27+
28+
/**
29+
* Gets or sets the iOS indicator view style (e.g. medium, large).
30+
*/
31+
iosIndicatorViewStyle: IOSIndicatorViewStyle;
2532
}

packages/core/ui/activity-indicator/index.ios.ts

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import { ActivityIndicatorBase, busyProperty } from './activity-indicator-common';
1+
import { ActivityIndicatorBase, busyProperty, iosIndicatorViewStyleProperty } from './activity-indicator-common';
22
import { colorProperty } from '../styling/style-properties';
33
import { Color } from '../../color';
44
import { iOSNativeHelper } from '../../utils';
5+
import { IOSIndicatorViewStyle } from '.';
56

67
export * from './activity-indicator-common';
78

@@ -10,10 +11,8 @@ const majorVersion = iOSNativeHelper.MajorVersion;
1011
export class ActivityIndicator extends ActivityIndicatorBase {
1112
nativeViewProtected: UIActivityIndicatorView;
1213

13-
private _activityIndicatorViewStyle = majorVersion <= 12 || !UIActivityIndicatorViewStyle.Medium ? UIActivityIndicatorViewStyle.Gray : UIActivityIndicatorViewStyle.Medium;
14-
1514
createNativeView() {
16-
const viewStyle = this._activityIndicatorViewStyle;
15+
const viewStyle = this._getNativeIndicatorViewStyle(this.iosIndicatorViewStyle);
1716
const view = UIActivityIndicatorView.alloc().initWithActivityIndicatorStyle(viewStyle);
1817
view.hidesWhenStopped = true;
1918

@@ -25,15 +24,27 @@ export class ActivityIndicator extends ActivityIndicatorBase {
2524
return this.nativeViewProtected;
2625
}
2726

28-
[busyProperty.getDefault](): boolean {
29-
if ((<any>this.nativeViewProtected).isAnimating) {
30-
return (<any>this.nativeViewProtected).isAnimating();
31-
} else {
32-
return this.nativeViewProtected.animating;
27+
private _getNativeIndicatorViewStyle(value: IOSIndicatorViewStyle): UIActivityIndicatorViewStyle {
28+
let viewStyle: UIActivityIndicatorViewStyle;
29+
30+
switch (value) {
31+
case 'large':
32+
viewStyle = majorVersion > 12 ? UIActivityIndicatorViewStyle.Large : UIActivityIndicatorViewStyle.WhiteLarge;
33+
break;
34+
default:
35+
viewStyle = majorVersion > 12 ? UIActivityIndicatorViewStyle.Medium : UIActivityIndicatorViewStyle.Gray;
36+
break;
3337
}
38+
39+
return viewStyle;
40+
}
41+
42+
[busyProperty.getDefault](): boolean {
43+
return this.nativeViewProtected.animating;
3444
}
3545
[busyProperty.setNative](value: boolean) {
3646
const nativeView = this.nativeViewProtected;
47+
3748
if (value) {
3849
nativeView.startAnimating();
3950
} else {
@@ -51,4 +62,8 @@ export class ActivityIndicator extends ActivityIndicatorBase {
5162
[colorProperty.setNative](value: UIColor | Color) {
5263
this.nativeViewProtected.color = value instanceof Color ? value.ios : value;
5364
}
65+
66+
[iosIndicatorViewStyleProperty.setNative](value: IOSIndicatorViewStyle) {
67+
this.nativeViewProtected.activityIndicatorViewStyle = this._getNativeIndicatorViewStyle(value);
68+
}
5469
}

0 commit comments

Comments
 (0)