Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix:(animated-circle) improve native setting for android #37

Merged
merged 12 commits into from
Oct 29, 2020
Prev Previous commit
Next Next commit
clean up the css props work
  • Loading branch information
bradmartin committed Oct 28, 2020
commit 0f112afc7429343adfca9863f394d6cba6a2b43f
102 changes: 75 additions & 27 deletions packages/animated-circle/index.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ export class AnimatedCircle extends AnimatedCircleCommon {
private _text = '';
private _textColor = new Color('orange');
private _textSize = 8;
private _fillColor: Color;
clockwise = true;
fillColor: any;

constructor() {
super();
Expand Down Expand Up @@ -105,16 +105,7 @@ export class AnimatedCircle extends AnimatedCircleCommon {
return this._maxValue;
}

set rimWidth(value: number) {
this._rimWidth = Number(value);
this.updateAnimatedCircle();
}

get rimWidth() {
return this._rimWidth;
}

[rimColorProperty.setNative](value: any) {
set rimColor(value: any) {
this._rimColor = value;
if (value instanceof Color) {
this.android.setRimColor(value.argb);
Expand All @@ -123,36 +114,57 @@ export class AnimatedCircle extends AnimatedCircleCommon {
}
}

[rimColorProperty.getDefault]() {
get rimColor() {
return this._rimColor;
}

[barColorProperty.setNative](value: any) {
get barColor(): Color {
return this._barColor;
}
set barColor(value: Color) {
this._barColor = value;
if (value instanceof Color) {
this.android.setBarColor([value.argb]);
} else if (typeof value === 'string') {
} else {
this.android.setBarColor([new Color(value).argb]);
}
}

[barColorProperty.getDefault]() {
return this._barColor;
set rimWidth(value: number) {
this._rimWidth = Number(value);
this.updateAnimatedCircle();
}

[spinBarColorProperty.setNative](value: any) {
get rimWidth() {
return this._rimWidth;
}

set spinBarColor(value: any) {
this._spinBarColor = value;
if (value instanceof Color) {
this.android.setSpinBarColor(value.argb);
} else if (typeof value === 'string') {
this.android.setSpinBarColor(new Color(value).argb);
} else {
this.android.setSpinBarColor(new Color(this.spinBarColor).argb);
}
}

[spinBarColorProperty.getDefault]() {
get spinBarColor() {
return this._spinBarColor;
}

get fillColor() {
return this._fillColor;
}

set fillColor(value: any) {
this._fillColor = value;
if (value instanceof Color) {
this.android.setFillCircleColor(value.argb);
} else {
this.android.setFillCircleColor(new Color(value).argb);
}
}

set startAngle(value: number) {
this._startAngle = Number(value);
this.updateAnimatedCircle();
Expand Down Expand Up @@ -182,23 +194,62 @@ export class AnimatedCircle extends AnimatedCircleCommon {

set textColor(value: string) {
this._textColor = new Color(value);
this.updateAnimatedCircle();
this.android.setTextColor(this._textColor.argb);
}

set textSize(value: number) {
this._textSize = value;
this.updateAnimatedCircle();
this.android.setTextSize(value);
}

get textSize() {
return this.android.getTextSize();
}

// CSS Properties

[rimColorProperty.setNative](value: any) {
this._rimColor = value;
if (value instanceof Color) {
this.android?.setRimColor(value.argb);
} else {
this.android?.setRimColor(new Color(value).argb);
}
}

[rimColorProperty.getDefault]() {
return this._rimColor;
}

[barColorProperty.setNative](value: any) {
this._barColor = value;
if (value instanceof Color) {
this.android?.setBarColor([value.argb]);
} else {
this.android?.setBarColor([new Color(value).argb]);
}
}

[barColorProperty.getDefault]() {
return this._barColor;
}

[spinBarColorProperty.setNative](value: any) {
this._spinBarColor = value;
if (value instanceof Color) {
this.android?.setSpinBarColor(value.argb);
} else {
this.android?.setSpinBarColor(new Color(this.spinBarColor).argb);
}
}

[spinBarColorProperty.getDefault]() {
return this._spinBarColor;
}

private updateAnimatedCircle(): void {
if (this.android) {
this.android.setText(this._text);
this.android.setTextColor(this._textColor.argb);
this.android.setTextSize(this._textSize);
if (this.animated) {
if (this.animateFrom) {
this.android.setValueAnimated(this.animateFrom, this.progress, this.animationDuration);
Expand Down Expand Up @@ -228,9 +279,6 @@ export class AnimatedCircle extends AnimatedCircleCommon {
if (this.rimWidth) {
this.android.setRimWidth(this.rimWidth);
}
if (this.fillColor) {
this.android.setFillCircleColor(new Color(this.fillColor).argb);
}

this.android.setDirection(this.clockwise ? at.grabner.circleprogress.Direction.CW : at.grabner.circleprogress.Direction.CCW);
}
Expand Down