Skip to content

Commit 70d8145

Browse files
committed
feat: progress supports indeterminate and busy
1 parent d159800 commit 70d8145

File tree

3 files changed

+75
-4
lines changed

3 files changed

+75
-4
lines changed

src/progress/progress-common.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
import { cssProperty } from '@nativescript-community/ui-material-core';
2-
import { CSSType, Color, CssProperty, Progress as NSProgress, Style } from '@nativescript/core';
2+
import { CSSType, Color, CssProperty, Progress as NSProgress, Property, Style, booleanConverter } from '@nativescript/core';
33

44
@CSSType('MDProgress')
55
export abstract class ProgressBase extends NSProgress {
66
@cssProperty progressColor: Color;
77
@cssProperty progressBackgroundColor: Color;
8+
public indeterminate: boolean;
9+
public busy: boolean;
10+
public startAnimating() {
11+
this.busy = true;
12+
}
13+
public stopAnimating() {
14+
this.busy = false;
15+
}
816
}
917

1018
export const progressColorProperty = new CssProperty<Style, Color>({
@@ -19,5 +27,15 @@ export const progressBackgroundColorProperty = new CssProperty<Style, Color>({
1927
equalityComparer: Color.equals,
2028
valueConverter: v => new Color(v)
2129
});
30+
export const busyProperty = new Property<ProgressBase, boolean>({
31+
name: 'busy',
32+
valueConverter: booleanConverter
33+
});
34+
export const indeterminateProperty = new Property<ProgressBase, boolean>({
35+
name: 'indeterminate',
36+
valueConverter: booleanConverter
37+
});
38+
busyProperty.register(ProgressBase);
39+
indeterminateProperty.register(ProgressBase);
2240
progressColorProperty.register(Style);
2341
progressBackgroundColorProperty.register(Style);

src/progress/progress.android.ts

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { themer } from '@nativescript-community/ui-material-core';
2-
import { Color, colorProperty } from '@nativescript/core';
3-
import { ProgressBase, progressBackgroundColorProperty, progressColorProperty } from './progress-common';
2+
import { Color, colorProperty, visibilityProperty } from '@nativescript/core';
3+
import { Visibility } from '@nativescript/core/ui/enums';
4+
import { ProgressBase, busyProperty, indeterminateProperty, progressBackgroundColorProperty, progressColorProperty } from './progress-common';
45

56
export class Progress extends ProgressBase {
67
constructor() {
@@ -15,4 +16,36 @@ export class Progress extends ProgressBase {
1516
[progressBackgroundColorProperty.setNative](color: Color) {
1617
this.nativeViewProtected.setProgressBackgroundTintList(color ? android.content.res.ColorStateList.valueOf(color.android) : null);
1718
}
19+
[indeterminateProperty.setNative](value: boolean) {
20+
this.nativeViewProtected.setIndeterminate(value);
21+
}
22+
[busyProperty.getDefault]() {
23+
return false;
24+
}
25+
[busyProperty.setNative](value) {
26+
// if (value) {
27+
this.nativeViewProtected.setVisibility(value ? android.view.View.VISIBLE : android.view.View.INVISIBLE);
28+
// }
29+
}
30+
// [visibilityProperty.setNative](value) {
31+
// switch (value) {
32+
// case Visibility.VISIBLE:
33+
// this.nativeViewProtected.setVisibility(this.busy ? android.view.View.VISIBLE : android.view.View.INVISIBLE);
34+
// break;
35+
// case Visibility.HIDDEN:
36+
// this.nativeViewProtected.setVisibility(android.view.View.INVISIBLE);
37+
// break;
38+
// case Visibility.COLLAPSE:
39+
// this.nativeViewProtected.setVisibility(android.view.View.GONE);
40+
// break;
41+
// default:
42+
// throw new Error(`Invalid visibility value: ${value}. Valid values are: "${Visibility.VISIBLE}", "${Visibility.HIDDEN}", "${Visibility.COLLAPSE}".`);
43+
// }
44+
// }
45+
public startAnimating() {
46+
this.busy = true;
47+
}
48+
public stopAnimating() {
49+
this.busy = false;
50+
}
1851
}

src/progress/progress.ios.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { themer } from '@nativescript-community/ui-material-core';
22
import { Color, Screen } from '@nativescript/core';
3-
import { ProgressBase, progressBackgroundColorProperty, progressColorProperty } from './progress-common';
3+
import { ProgressBase, busyProperty, indeterminateProperty, progressBackgroundColorProperty, progressColorProperty } from './progress-common';
44

55
export class Progress extends ProgressBase {
66
nativeViewProtected: MDCProgressView;
@@ -25,4 +25,24 @@ export class Progress extends ProgressBase {
2525
[progressBackgroundColorProperty.setNative](color: Color) {
2626
this.nativeViewProtected.trackTintColor = color ? color.ios : null;
2727
}
28+
[indeterminateProperty.setNative](value: boolean) {
29+
this.nativeViewProtected.mode = value ? MDCProgressViewMode.Indeterminate : MDCProgressViewMode.Determinate;
30+
if (this.busy) {
31+
this.nativeViewProtected.startAnimating();
32+
}
33+
}
34+
[busyProperty.setNative](value) {
35+
const nativeView = this.nativeViewProtected;
36+
if (nativeView.mode === MDCProgressViewMode.Determinate) {
37+
return;
38+
}
39+
if (value) {
40+
nativeView.startAnimating();
41+
} else {
42+
nativeView.stopAnimating();
43+
}
44+
// if (nativeView.hidesWhenStopped) {
45+
// this.requestLayout();
46+
// }
47+
}
2848
}

0 commit comments

Comments
 (0)