Skip to content

Commit 4529e30

Browse files
committed
chore: refactoring
1 parent 50155e5 commit 4529e30

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/floatingactionbutton/floatingactionbutton.android.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { dynamicElevationOffsetProperty, elevationProperty, rippleColorProperty, shapeProperty, themer } from '@nativescript-community/ui-material-core';
2-
import { createStateListAnimator, isPostLollipop } from '@nativescript-community/ui-material-core/android/utils';
2+
import { createStateListAnimator, getColorStateList, isPostLollipop } from '@nativescript-community/ui-material-core/android/utils';
33
import { Background, Color, ImageSource, Length, backgroundInternalProperty, colorProperty } from '@nativescript/core';
44
import { textProperty } from '@nativescript/core/ui/text-base';
55
import { FloatingActionButtonBase, expandedProperty, imageSourceProperty, sizeProperty, srcProperty } from './floatingactionbutton-common';
@@ -83,7 +83,7 @@ export class FloatingActionButton extends FloatingActionButtonBase {
8383
} else {
8484
// if (android.os.Build.VERSION.SDK_INT >= 21) {
8585
if (value.color) {
86-
this.nativeViewProtected.setBackgroundTintList(android.content.res.ColorStateList.valueOf(value.color.android));
86+
this.nativeViewProtected.setBackgroundTintList(getColorStateList(value.color.android));
8787
}
8888
// } else {
8989
// (this as any)._redrawNativeBackground(value);
@@ -92,13 +92,16 @@ export class FloatingActionButton extends FloatingActionButtonBase {
9292
}
9393
}
9494
[colorProperty.setNative](value: Color) {
95-
this.nativeViewProtected.setIconTint(android.content.res.ColorStateList.valueOf(value.android));
95+
const color = !value || value instanceof Color ? value : new Color(value);
96+
this.nativeViewProtected.setIconTint(getColorStateList(color.android));
9697
}
97-
[rippleColorProperty.setNative](color: Color) {
98-
this.nativeViewProtected.setRippleColor(android.content.res.ColorStateList.valueOf(color.android));
98+
[rippleColorProperty.setNative](value: Color) {
99+
const color = !value || value instanceof Color ? value : new Color(value);
100+
this.nativeViewProtected.setRippleColor(getColorStateList(color.android));
99101
}
100-
[rippleColorProperty.setNative](color: Color) {
101-
this.nativeViewProtected.setRippleColor(android.content.res.ColorStateList.valueOf(color.android));
102+
[rippleColorProperty.setNative](value: Color) {
103+
const color = !value || value instanceof Color ? value : new Color(value);
104+
this.nativeViewProtected.setRippleColor(getColorStateList(color.android));
102105
}
103106
[expandedProperty.setNative](value: boolean) {
104107
if (value) {

0 commit comments

Comments
 (0)