Skip to content

Commit 0e399a6

Browse files
committed
chore: working on activity indicators
1 parent df7b8f4 commit 0e399a6

File tree

4 files changed

+67
-12
lines changed

4 files changed

+67
-12
lines changed

demo-vue/app/examples/ActivityIndicators.vue

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<MDActivityIndicator color="green" busy class="loading" />
1212
<MDActivityIndicator color="orange" busy class="loading" width="100" height="100"/>
1313
<MDActivityIndicator class="loading" backgroundColor="yellow" busy/>
14-
<MDActivityIndicator color="brown" indeterminate="false" progress="0.5" maxValue="1" class="loading" horizontalAlignment="center"/>
14+
<MDActivityIndicator color="brown" :indeterminate="false" value="50" maxValue="100" class="loading" busy horizontalAlignment="center"/>
1515
</StackLayout>
1616
</Page>
1717
</template>
@@ -46,7 +46,4 @@ export default Vue.extend({
4646
});
4747
</script>
4848
<style lang="css">
49-
.loading {
50-
color:white;
51-
}
5249
</style>

src/activityindicator/index-common.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
import { CSSType, ActivityIndicator as NSActivityIndicator, Progress as NSProgress, Property, Utils, booleanConverter } from '@nativescript/core';
1+
import { CSSType, CoercibleProperty, ActivityIndicator as NSActivityIndicator, Progress as NSProgress, Property, Utils, booleanConverter } from '@nativescript/core';
22
import { applyMixins } from '@nativescript-community/ui-material-core';
33

44
@CSSType('MDActivityIndicator')
55
export class ActivityIndicatorBase extends NSActivityIndicator {
66
public indeterminate: boolean;
7+
public maxValue: number;
8+
public value: number;
79
public startAnimating() {
810
this.busy = true;
911
}
@@ -37,3 +39,26 @@ export const indeterminateProperty = new Property<ActivityIndicatorBase, boolean
3739
valueConverter: booleanConverter
3840
});
3941
indeterminateProperty.register(ActivityIndicatorBase);
42+
/**
43+
* Represents the observable property backing the value property of each Progress instance.
44+
*/
45+
export const valueProperty = new CoercibleProperty<ActivityIndicatorBase, number>({
46+
name: 'value',
47+
defaultValue: 0,
48+
coerceValue: (t, v) => (v < 0 ? 0 : Math.min(v, t.maxValue)),
49+
valueConverter: (v) => parseInt(v, 10)
50+
});
51+
valueProperty.register(ActivityIndicatorBase);
52+
53+
/**
54+
* Represents the observable property backing the maxValue property of each Progress instance.
55+
*/
56+
export const maxValueProperty = new Property<ActivityIndicatorBase, number>({
57+
name: 'maxValue',
58+
defaultValue: 100,
59+
valueChanged: (target, oldValue, newValue) => {
60+
valueProperty.coerce(target);
61+
},
62+
valueConverter: (v) => parseInt(v, 10)
63+
});
64+
maxValueProperty.register(ActivityIndicatorBase);
Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,30 @@
1-
import { ActivityIndicatorBase, indeterminateProperty } from './index-common';
1+
import { ActivityIndicatorBase, indeterminateProperty, maxValueProperty, valueProperty } from './index-common';
22

33
export class ActivityIndicator extends ActivityIndicatorBase {
4-
nativeViewProtected: android.widget.ProgressBar;
4+
// nativeViewProtected: com.google.android.material.progressindicator.CircularProgressIndicator;
5+
6+
// createNativeView() {
7+
// const progressBar = new com.google.android.material.progressindicator.CircularProgressIndicator(this._context);
8+
// progressBar.setVisibility(android.view.View.INVISIBLE);
9+
// progressBar.setIndeterminate(true);
10+
// return progressBar;
11+
// }
12+
13+
[valueProperty.getDefault](): number {
14+
return 0;
15+
}
16+
[valueProperty.setNative](value: number) {
17+
this.nativeViewProtected.setProgress(value);
18+
}
19+
20+
[maxValueProperty.getDefault](): number {
21+
return 100;
22+
}
23+
[maxValueProperty.setNative](value: number) {
24+
this.nativeViewProtected.setMax(value);
25+
}
526

627
[indeterminateProperty.setNative](value: boolean) {
7-
this.busy = true;
8-
// not supported for now with circular progress
928
this.nativeViewProtected.setIndeterminate(value);
1029
}
1130
}

src/activityindicator/index.ios.ts

Lines changed: 17 additions & 3 deletions
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, Utils, View, colorProperty } from '@nativescript/core';
3-
import { ActivityIndicatorBase, indeterminateProperty } from './index-common';
3+
import { ActivityIndicatorBase, indeterminateProperty, maxValueProperty, valueProperty } from './index-common';
44

55
export class ActivityIndicator extends ActivityIndicatorBase {
66
nativeViewProtected: MDCActivityIndicator;
@@ -9,7 +9,7 @@ export class ActivityIndicator extends ActivityIndicatorBase {
99
public createNativeView() {
1010
const view = MDCActivityIndicator.new();
1111
const color = (themer.getAppColorScheme() as MDCSemanticColorScheme).primaryColor;
12-
view.cycleColors = color ? NSArray.arrayWithObject(color) : null;
12+
view.cycleColors = color ? NSArray.arrayWithObject(color) : null;
1313
// const colorScheme = this.colorThemer || themer.getAppColorScheme();
1414
// if (colorScheme) {
1515
// MDCActivityIndicatorColorThemer.applySemanticColorSchemeToActivityIndicator(colorScheme, view);
@@ -77,11 +77,25 @@ export class ActivityIndicator extends ActivityIndicatorBase {
7777

7878
[colorProperty.setNative](value: UIColor | Color) {
7979
const color = value instanceof Color ? value.ios : value;
80-
this.nativeViewProtected.cycleColors = color ? NSArray.arrayWithObject(color) : null;
80+
this.nativeViewProtected.cycleColors = color ? NSArray.arrayWithObject(color) : null;
8181
// this.getColorThemer().primaryColor = value instanceof Color ? value.ios : value;
8282
// MDCActivityIndicatorColorThemer.applySemanticColorSchemeToActivityIndicator(this.getColorThemer(), this.nativeViewProtected);
8383
}
8484
[indeterminateProperty.setNative](value: boolean) {
8585
this.nativeViewProtected.indicatorMode = value ? MDCActivityIndicatorMode.Indeterminate : MDCActivityIndicatorMode.Determinate;
8686
}
87+
88+
[valueProperty.getDefault](): number {
89+
return 0;
90+
}
91+
[valueProperty.setNative](value: number) {
92+
this.nativeViewProtected.progress = value / this.maxValue;
93+
}
94+
95+
[maxValueProperty.getDefault](): number {
96+
return 100;
97+
}
98+
[maxValueProperty.setNative](value: number) {
99+
this.nativeViewProtected.progress = this.value / value;
100+
}
87101
}

0 commit comments

Comments
 (0)