Skip to content

Commit 84d241b

Browse files
committed
feat: rippleColorAlpha property
fix: default rippleColor alpha fix
1 parent ae4d6cc commit 84d241b

19 files changed

+143
-51
lines changed

src/button/button-common.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@ export abstract class ButtonBase extends Button {
1919
/**
2020
* Gets or sets the ripple-color of the button.
2121
*/
22-
@cssProperty rippleColor: Color | string;
22+
@cssProperty rippleColor: Color;
23+
24+
/**
25+
* Gets or sets the ripple-color alpha of the button.
26+
*/
27+
@cssProperty rippleColorAlpha: number;
2328

2429
/**
2530
* Gets or sets the {@link VerticalTextAlignment|vertical text alignment} of the button.

src/button/button.android.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { VerticalTextAlignment, verticalTextAlignmentProperty } from '@nativescript-community/text';
2-
import { dynamicElevationOffsetProperty, elevationProperty, rippleColorProperty, shapeProperty, themer } from '@nativescript-community/ui-material-core';
2+
import { dynamicElevationOffsetProperty, elevationProperty, getRippleColor, rippleColorAlphaProperty, rippleColorProperty, shapeProperty, themer } from '@nativescript-community/ui-material-core';
33
import { createStateListAnimator, getColorStateList, getHorizontalGravity, getLayout, getVerticalGravity, isPostLollipop } from '@nativescript-community/ui-material-core/android/utils';
44
import {
55
Background,
@@ -87,8 +87,13 @@ export class Button extends ButtonBase {
8787
// (<any>nativeView).clickListener = clickListener;
8888
// }
8989
[rippleColorProperty.setNative](value: Color) {
90-
const color = !value || value instanceof Color ? value : new Color(value);
91-
this.nativeViewProtected.setRippleColor(color ? getColorStateList(color.android) : null);
90+
this.nativeViewProtected.setRippleColor(value ? getColorStateList(getRippleColor(value, this.rippleColorAlpha)) : null);
91+
}
92+
[rippleColorAlphaProperty.setNative](value: number) {
93+
const rippleColor = this.rippleColor;
94+
if (rippleColor) {
95+
this.nativeViewProtected.setRippleColor(getColorStateList(getRippleColor(rippleColor, value)));
96+
}
9297
}
9398
defaultAppearanceModel;
9499
[shapeProperty.setNative](shape: string) {

src/button/button.ios.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { dynamicElevationOffsetProperty, elevationProperty, getRippleColor, rippleColorProperty, shapeProperty, themer } from '@nativescript-community/ui-material-core';
1+
import { dynamicElevationOffsetProperty, elevationProperty, getRippleColor, rippleColorAlphaProperty, rippleColorProperty, shapeProperty, themer } from '@nativescript-community/ui-material-core';
22
import {
33
Background,
44
Color,
@@ -225,7 +225,14 @@ export class Button extends ButtonBase {
225225
this.nativeViewProtected.uppercaseTitle = value !== 'none';
226226
}
227227
[rippleColorProperty.setNative](color: Color) {
228-
this.nativeViewProtected.inkColor = getRippleColor(color);
228+
this.nativeViewProtected.inkColor = getRippleColor(color, this.rippleColorAlpha);
229+
}
230+
231+
[rippleColorAlphaProperty.setNative](value: number) {
232+
const rippleColor = this.rippleColor;
233+
if (rippleColor) {
234+
this.nativeViewProtected.inkColor = getRippleColor(rippleColor, value);
235+
}
229236
}
230237

231238
[elevationProperty.setNative](value: number) {

src/cardview/cardview-common.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ export abstract class CardViewBase extends ContentView {
77
@cssProperty dynamicElevationOffset: number;
88
@cssProperty rippleColor: Color;
99
@cssProperty shape: string;
10+
@cssProperty rippleColorAlpha: number;
1011
}

src/cardview/cardview.android.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { dynamicElevationOffsetProperty, elevationProperty, getRippleColor, rippleColorProperty, shapeProperty, themer } from '@nativescript-community/ui-material-core';
1+
import { dynamicElevationOffsetProperty, elevationProperty, getRippleColor, rippleColorAlphaProperty, rippleColorProperty, shapeProperty, themer } from '@nativescript-community/ui-material-core';
22
import { createStateListAnimator, getAttrColor, getColorStateList, isPostLollipop } from '@nativescript-community/ui-material-core/android/utils';
33
import { Color, Length, backgroundInternalProperty } from '@nativescript/core';
44
import { CardViewBase } from './cardview-common';
@@ -360,13 +360,13 @@ export class CardView extends CardViewBase {
360360
androidx.core.view.ViewCompat.setTranslationZ(this.nativeViewProtected, newValue);
361361
}
362362
}
363-
[rippleColorProperty.setNative](color: Color) {
364-
const rippleColor = color ? color.android : -1;
365-
// if (isPostLollipopMR1) {
366-
// (this.rippleDrawable as android.graphics.drawable.RippleDrawable).setColor(getColorStateList(rippleColor));
367-
// } else {
368-
// this.rippleShape.getPaint().setColor(rippleColor);
369-
// }
370-
(this.nativeViewProtected as any).setRippleColor(getColorStateList(rippleColor));
363+
[rippleColorProperty.setNative](value: Color) {
364+
this.nativeViewProtected.setRippleColor(value ? getColorStateList(getRippleColor(value, this.rippleColorAlpha)) : null);
365+
}
366+
[rippleColorAlphaProperty.setNative](value: number) {
367+
const rippleColor = this.rippleColor;
368+
if (rippleColor) {
369+
this.nativeViewProtected.setRippleColor(getColorStateList(getRippleColor(rippleColor, value)));
370+
}
371371
}
372372
}

src/cardview/cardview.ios.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { dynamicElevationOffsetProperty, elevationProperty, getRippleColor, rippleColorProperty, shapeProperty, themer } from '@nativescript-community/ui-material-core';
1+
import { dynamicElevationOffsetProperty, elevationProperty, getRippleColor, rippleColorAlphaProperty, rippleColorProperty, shapeProperty, themer } from '@nativescript-community/ui-material-core';
22
import {
33
Background,
44
Color,
@@ -188,8 +188,16 @@ export class CardView extends CardViewBase {
188188
// this.nativeViewProtected.cornerRadius = value.borderTopLeftRadius / scale;
189189
}
190190
}
191+
191192
[rippleColorProperty.setNative](color: Color) {
192-
this.nativeViewProtected.inkView.inkColor = getRippleColor(color);
193+
this.nativeViewProtected.inkView.inkColor = getRippleColor(color, this.rippleColorAlpha);
194+
}
195+
196+
[rippleColorAlphaProperty.setNative](value: number) {
197+
const rippleColor = this.rippleColor;
198+
if (rippleColor) {
199+
this.nativeViewProtected.inkView.inkColor = getRippleColor(rippleColor, value);
200+
}
193201
}
194202

195203
[shapeProperty.setNative](shape) {

src/core-tabs/tab-navigation-base/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ export class TabNavigationBase extends View implements TabNavigationBaseDefiniti
270270
// overridden by inheritors
271271
}
272272

273-
public setTabBarRippleColor(value: Color) {
273+
public setTabBarRippleColor(value: Color, alpha?:number) {
274274
// overridden by inheritors
275275
}
276276

src/core-tabs/tab-navigation/index.ios.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { getIconSpecSize, itemsProperty, selectedIndexProperty, tabStripProperty
77
import { TabStrip } from '../tab-strip';
88
import { TabStripItem } from '../tab-strip-item';
99
import { TabNavigationBase, swipeEnabledProperty } from './index-common';
10+
import { getRippleColor } from '@nativescript-community/ui-material-core';
1011

1112
export { TabContentItem, TabStrip, TabStripItem };
1213

@@ -905,9 +906,9 @@ export abstract class TabNavigation<
905906
});
906907
}
907908

908-
public setTabBarRippleColor(value: Color) {
909+
public setTabBarRippleColor(value: Color, alpha?:number) {
909910
this.mRippleColor = value;
910-
this.viewController.tabBar.rippleColor = value.ios;
911+
this.viewController.tabBar.rippleColor = getRippleColor(value, alpha);
911912
}
912913

913914
public getTabBarRippleColor(): Color {

src/core-tabs/tab-strip/index.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
/**
22
* @module @nativescript-community/ui-material-core-tabs/tab-strip
33
*/
4-
import { rippleColorProperty } from '@nativescript-community/ui-material-core/cssproperties';
4+
import { rippleColorAlphaProperty, rippleColorProperty } from '@nativescript-community/ui-material-core/cssproperties';
55
import { AddArrayFromBuilder, AddChildFromBuilder, CSSType, Color, CssProperty, Property, Style, View, ViewBase, booleanConverter } from '@nativescript/core';
66
import { backgroundColorProperty, backgroundInternalProperty, colorProperty, fontInternalProperty } from '@nativescript/core/ui/styling/style-properties';
77
import { textTransformProperty } from '@nativescript/core/ui/text-base';
88
import { TabNavigationBase } from '../tab-navigation-base';
99
import { TabStripItem } from '../tab-strip-item';
1010
import { TabStrip as TabStripDefinition } from '.';
11+
import { getRippleColor } from '@nativescript-community/ui-material-core/index.ios';
1112

1213
// Place this on top because the webpack ts-loader doesn't work when export
1314
// is after reference
@@ -180,8 +181,11 @@ export class TabStrip extends View implements TabStripDefinition, AddChildFromBu
180181

181182
[rippleColorProperty.setNative](value: Color) {
182183
const parent = this.parent as TabNavigationBase;
183-
184-
return parent && parent.setTabBarRippleColor(value);
184+
return parent && parent.setTabBarRippleColor(value, this.rippleColorAlpha);
185+
}
186+
[rippleColorAlphaProperty.setNative](value: number) {
187+
const parent = this.parent as TabNavigationBase;
188+
return parent && parent.setTabBarRippleColor(this.rippleColor, value);
185189
}
186190
}
187191

src/core/cssproperties.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ export const rippleColorProperty = new CssProperty<Style, Color>({
1919
valueConverter: (v) => new Color(v)
2020
});
2121
rippleColorProperty.register(Style);
22+
export const rippleColorAlphaProperty = new CssProperty<Style, number>({
23+
name: 'rippleColorAlpha',
24+
cssName: 'ripple-color-alpha',
25+
valueConverter: parseFloat
26+
});
27+
rippleColorAlphaProperty.register(Style);
2228
export const elevationProperty = new CssProperty<Style, CoreTypes.LengthType>({
2329
name: 'elevation',
2430
cssName: 'elevation',

0 commit comments

Comments
 (0)