Skip to content

Commit 075ffa9

Browse files
committed
feat(android): rippleColor and elevation now support none uniform corner radius
1 parent e556c6d commit 075ffa9

File tree

3 files changed

+27
-27
lines changed

3 files changed

+27
-27
lines changed

packages/core/platforms/android/java/com/nativescript/material/core/Utils.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,18 +60,18 @@ public static ColorStateList getFullColorStateList(int activeColor, int inactive
6060
return new android.content.res.ColorStateList(states, colors);
6161
}
6262

63-
public static ShapeDrawable createForegroundShape(float radius) {
63+
public static ShapeDrawable createForegroundShape(float topLeftRadius, float topRightRadius, float bottomRightRadius, float bottomLeftRadius) {
6464
RoundRectShape shape = new RoundRectShape(
65-
new float[] { radius, radius, radius, radius, radius, radius, radius, radius }, null, null);
65+
new float[] { topLeftRadius, topLeftRadius, topRightRadius, topRightRadius, bottomRightRadius, bottomRightRadius, bottomLeftRadius, bottomLeftRadius }, null, null);
6666
return new ShapeDrawable(shape);
6767
}
6868

69-
public static Drawable createRippleDrawable(int rippleColor, float radius) {
69+
public static Drawable createRippleDrawable(int rippleColor, float topLeftRadius, float topRightRadius, float bottomRightRadius, float bottomLeftRadius) {
7070
if (Build.VERSION.SDK_INT >= 21) {
71-
ShapeDrawable rippleShape = radius != 0 ? createForegroundShape(radius) : null;
71+
ShapeDrawable rippleShape = createForegroundShape(topLeftRadius, topRightRadius, bottomRightRadius, bottomLeftRadius);
7272
return new RippleDrawable(ColorStateList.valueOf(rippleColor), null, rippleShape);
7373
} else {
74-
ShapeDrawable rippleShape = createForegroundShape(radius);
74+
ShapeDrawable rippleShape = createForegroundShape(topLeftRadius, topRightRadius, bottomRightRadius, bottomLeftRadius);
7575
StateListDrawable rippleDrawable = new StateListDrawable();
7676
if (rippleShape != null) {
7777
rippleShape.getPaint().setColor(rippleColor);

src/core/android/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,11 @@ function createForegroundShape(radius) {
190190
}
191191
return NUtils.createForegroundShape(radius);
192192
}
193-
export function createRippleDrawable(rippleColor: number, radius = 0) {
193+
export function createRippleDrawable(rippleColor: number, topLeftRadius = 0, topRightRadius = 0, bottomRightRadius = 0, bottomLeftRadius = 0) {
194194
if (!NUtils) {
195195
NUtils = (com as any).nativescript.material.core.Utils;
196196
}
197-
return NUtils.createRippleDrawable(rippleColor, radius);
197+
return NUtils.createRippleDrawable(rippleColor, topLeftRadius, topRightRadius, bottomRightRadius, bottomLeftRadius);
198198
}
199199

200200
export function handleClearFocus(view: android.view.View) {

src/core/index.android.ts

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,9 @@
1-
import {
2-
Application,
3-
Background,
4-
Button,
5-
Color,
6-
Length,
7-
PercentLength,
8-
Utils,
9-
View,
10-
androidDynamicElevationOffsetProperty,
11-
androidElevationProperty,
12-
backgroundInternalProperty
13-
} from '@nativescript/core';
14-
import { createRippleDrawable, createStateListAnimator, getAttrColor, getColorStateList, handleClearFocus, isPostLollipop, isPostLollipopMR1, isPostMarshmallow } from './android/utils';
15-
import { CornerFamily, applyMixins } from './index.common';
16-
import { cssProperty, dynamicElevationOffsetProperty, elevationProperty, rippleColorProperty } from './cssproperties';
1+
import { Background, Button, Color, Length, PercentLength, Utils, View, androidDynamicElevationOffsetProperty, androidElevationProperty, backgroundInternalProperty } from '@nativescript/core';
172
import { ad } from '@nativescript/core/utils';
183
import { ShapeProperties } from '.';
4+
import { createRippleDrawable, createStateListAnimator, getAttrColor, getColorStateList, handleClearFocus, isPostLollipop, isPostMarshmallow } from './android/utils';
5+
import { cssProperty, dynamicElevationOffsetProperty, elevationProperty, rippleColorProperty } from './cssproperties';
6+
import { CornerFamily, applyMixins } from './index.common';
197
export * from './cssproperties';
208
export { applyMixins };
219

@@ -232,9 +220,9 @@ export function overrideViewBase() {
232220
return getRippleColor(themer.getAccentColor());
233221
}
234222

235-
setRippleDrawable(view: android.view.View, radius = 0) {
223+
setRippleDrawable(view: android.view.View, topLeftRadius = 0, topRightRadius = 0, bottomRightRadius = 0, bottomLeftRadius = 0) {
236224
if (!this.rippleDrawable) {
237-
this.rippleDrawable = createRippleDrawable(this.getRippleColor(), radius);
225+
this.rippleDrawable = createRippleDrawable(this.getRippleColor(), topLeftRadius, topRightRadius, bottomRightRadius, bottomLeftRadius);
238226
if (isPostMarshmallow) {
239227
view.setForeground(this.rippleDrawable);
240228
}
@@ -259,7 +247,13 @@ export function overrideViewBase() {
259247
nativeViewProtected.setClickable(this.isUserInteractionEnabled);
260248
const rippleDrawable = this.rippleDrawable;
261249
if (!rippleDrawable) {
262-
this.setRippleDrawable(nativeViewProtected, Length.toDevicePixels(this.style.borderTopLeftRadius));
250+
this.setRippleDrawable(
251+
nativeViewProtected,
252+
Length.toDevicePixels(this.style.borderTopLeftRadius),
253+
Length.toDevicePixels(this.style.borderTopRightRadius),
254+
Length.toDevicePixels(this.style.borderBottomRightRadius),
255+
Length.toDevicePixels(this.style.borderBottomLeftRadius)
256+
);
263257
} else {
264258
if (isPostLollipop) {
265259
(rippleDrawable as android.graphics.drawable.RippleDrawable).setColor(getColorStateList(rippleColor));
@@ -277,7 +271,13 @@ export function overrideViewBase() {
277271
// native button have on the background. Setting color will remove the ripple!
278272
if (this.rippleDrawable || (value.color && this instanceof Button && this.rippleColor)) {
279273
this.rippleDrawable = null;
280-
this.setRippleDrawable(this.nativeViewProtected, value.borderTopLeftRadius);
274+
this.setRippleDrawable(
275+
this.nativeViewProtected,
276+
Length.toDevicePixels(this.style.borderTopLeftRadius),
277+
Length.toDevicePixels(this.style.borderTopRightRadius),
278+
Length.toDevicePixels(this.style.borderBottomRightRadius),
279+
Length.toDevicePixels(this.style.borderBottomLeftRadius)
280+
);
281281
}
282282
}
283283
}

0 commit comments

Comments
 (0)