From 24cd1221e29aa4eeedd4ec75cfbae2f603e5917e Mon Sep 17 00:00:00 2001 From: Martin Guillon Date: Sat, 14 Nov 2026 15:59:51 +0100 Subject: [PATCH] fix(android): keep a ripple foreground with the border drawn over the children The border drawn over the children and a ripple (set by the ui-core plugin) both used the single view foreground, so one erased the other: a view with a border radius, a border width and a ripple lost its border. Removing the border also cleared the ripple. The foreground is now set by View._updateForeground(), from the border (_borderForeground) and the ripple (_rippleForeground): both go in a LayerDrawable, the border over the ripple. Co-Authored-By: Claude Sonnet 5.5 --- packages/core/ui/core/view/index.android.ts | 27 ++++++++++++++++++--- packages/core/ui/utils.d.ts | 1 + 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/packages/core/ui/core/view/index.android.ts b/packages/core/ui/core/view/index.android.ts index 837accf220..6a49bd3c87 100644 --- a/packages/core/ui/core/view/index.android.ts +++ b/packages/core/ui/core/view/index.android.ts @@ -1321,8 +1321,8 @@ export class View extends ViewCommon { ViewHelper.setOutlineProvider(nativeView, background.borderTopLeftRadius, background.borderTopRightRadius, background.borderBottomRightRadius, background.borderBottomLeftRadius); } if (nativeView._borderForeground) { - nativeView.setForeground(null); nativeView._borderForeground = null; + this._updateForeground(); } } else { // the view clips its children to its rounded corners (outline). The border is then drawn by the foreground, over the children: @@ -1345,10 +1345,10 @@ export class View extends ViewCommon { nativeView._borderForeground = new org.nativescript.widgets.BorderDrawable(layout.getDisplayDensity(), this.toString()); } refreshBorderDrawable(this, nativeView._borderForeground, 'border'); - nativeView.setForeground(nativeView._borderForeground); + this._updateForeground(); } else if (nativeView._borderForeground) { - nativeView.setForeground(null); nativeView._borderForeground = null; + this._updateForeground(); } if (background.clearFlags & BackgroundClearFlags.CLEAR_BACKGROUND_COLOR) { if (backgroundDrawable) { @@ -1397,6 +1397,27 @@ export class View extends ViewCommon { } org.nativescript.widgets.Utils.drawBoxShadow(nativeView, nativeArray); } + /** + * The native view has a single foreground, shared by the border drawn over the children (`_borderForeground`) and a ripple + * (`_rippleForeground`, set by the ui-core plugin). Both are kept: the border is drawn over the ripple. + */ + _updateForeground(): void { + const nativeView = this.nativeViewProtected; + if (!nativeView) { + return; + } + const ripple = nativeView._rippleForeground; + const border = nativeView._borderForeground; + if (ripple && border) { + const layers = Array.create(android.graphics.drawable.Drawable, 2); + layers[0] = ripple; + layers[1] = border; + nativeView.setForeground(new android.graphics.drawable.LayerDrawable(layers)); + } else { + nativeView.setForeground(ripple || border || null); + } + } + _redrawNativeBackground(value: android.graphics.drawable.Drawable | Background): void { if (value instanceof Background) { this.onBackgroundOrBorderPropertyChanged(); diff --git a/packages/core/ui/utils.d.ts b/packages/core/ui/utils.d.ts index 82914d80bb..d28a362509 100644 --- a/packages/core/ui/utils.d.ts +++ b/packages/core/ui/utils.d.ts @@ -1,6 +1,7 @@ export interface NativeScriptAndroidView extends android.view.View { _cachedDrawable: android.graphics.drawable.Drawable; _borderForeground?: org.nativescript.widgets.BorderDrawable; + _rippleForeground?: android.graphics.drawable.Drawable; } export interface NativeScriptUIView extends UIView {