Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 31 additions & 4 deletions packages/core/ui/core/view/index.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1319,10 +1319,37 @@ export class View extends ViewCommon {
// let s use outline provider when we can
if (shouldClipToOutline) {
ViewHelper.setOutlineProvider(nativeView, background.borderTopLeftRadius, background.borderTopRightRadius, background.borderBottomRightRadius, background.borderBottomLeftRadius);

}
if (nativeView._borderForeground) {
nativeView.setForeground(null);
nativeView._borderForeground = null;
}
} else {
ViewHelper.clearOutlineProvider(nativeView);
// the view clips its children to its rounded corners (outline). The border is then drawn by the foreground, over the children:
// the background drawable would be under them
const clipsChildren =
background.hasBorderRadius() &&
!background.hasBoxShadows() &&
!background.clipPath &&
SDK_VERSION >= 21 &&
(!background.hasBorderWidth() || SDK_VERSION >= 23) &&
(SDK_VERSION >= 33 || background.hasUniformBorderRadius());
if (clipsChildren) {
ViewHelper.setOutlineProvider(nativeView, background.borderTopLeftRadius, background.borderTopRightRadius, background.borderBottomRightRadius, background.borderBottomLeftRadius);
} else {
ViewHelper.clearOutlineProvider(nativeView);
}
const borderOnTop = clipsChildren && background.hasBorderWidth();
if (borderOnTop) {
if (!nativeView._borderForeground) {
nativeView._borderForeground = new org.nativescript.widgets.BorderDrawable(layout.getDisplayDensity(), this.toString());
}
refreshBorderDrawable(this, nativeView._borderForeground, 'border');
nativeView.setForeground(nativeView._borderForeground);
} else if (nativeView._borderForeground) {
nativeView.setForeground(null);
nativeView._borderForeground = null;
}
if (background.clearFlags & BackgroundClearFlags.CLEAR_BACKGROUND_COLOR) {
if (backgroundDrawable) {
backgroundDrawable.mutate();
Expand All @@ -1342,10 +1369,10 @@ export class View extends ViewCommon {
} else {
if (isBorderDrawable) {
// org.nativescript.widgets.BorderDrawable
refreshBorderDrawable(this, backgroundDrawable);
refreshBorderDrawable(this, backgroundDrawable, borderOnTop ? 'background' : 'all');
} else {
const borderDrawable = new org.nativescript.widgets.BorderDrawable(layout.getDisplayDensity(), this.toString());
refreshBorderDrawable(this, borderDrawable);
refreshBorderDrawable(this, borderDrawable, borderOnTop ? 'background' : 'all');
nativeView.setBackground(borderDrawable);
}
}
Expand Down
21 changes: 12 additions & 9 deletions packages/core/ui/styling/background.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ function fromGradient(gradient: LinearGradient): org.nativescript.widgets.Linear
}

const pattern = /url\(('|")(.*?)\1\)/;
export function refreshBorderDrawable(view: View, borderDrawable: org.nativescript.widgets.BorderDrawable) {
/**
* `mode`: `background` draws no border, `border` draws only the border (used as the foreground of a view clipping its children to its rounded corners)
*/
export function refreshBorderDrawable(view: View, borderDrawable: org.nativescript.widgets.BorderDrawable, mode: 'all' | 'background' | 'border' = 'all') {
const nativeView = <android.view.View>view.nativeViewProtected;
const context = nativeView.getContext();

Expand Down Expand Up @@ -81,10 +84,10 @@ export function refreshBorderDrawable(view: View, borderDrawable: org.nativescri
background.borderBottomColor ? background.borderBottomColor.android : blackColor,
background.borderLeftColor ? background.borderLeftColor.android : blackColor,

background.borderTopWidth,
background.borderRightWidth,
background.borderBottomWidth,
background.borderLeftWidth,
mode === 'background' ? 0 : background.borderTopWidth,
mode === 'background' ? 0 : background.borderRightWidth,
mode === 'background' ? 0 : background.borderBottomWidth,
mode === 'background' ? 0 : background.borderLeftWidth,

background.borderTopLeftRadius,
background.borderTopRightRadius,
Expand All @@ -93,10 +96,10 @@ export function refreshBorderDrawable(view: View, borderDrawable: org.nativescri

background.clipPath instanceof ClipPathFunction ? background.clipPath.toString() : background.clipPath,

background.color ? background.color.android : 0,
imageUri,
bitmap,
gradient,
mode !== 'border' && background.color ? background.color.android : 0,
mode === 'border' ? null : imageUri,
mode === 'border' ? null : bitmap,
mode === 'border' ? null : gradient,
context,
background.repeat,
background.position,
Expand Down
2 changes: 1 addition & 1 deletion packages/core/ui/styling/background.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,4 @@ export namespace ad {
export function onBackgroundOrBorderPropertyChanged(v: View);
}

export function refreshBorderDrawable(view: View, borderDrawable: any /* org.nativescript.widgets.BorderDrawable */): void;
export function refreshBorderDrawable(view: View, borderDrawable: any /* org.nativescript.widgets.BorderDrawable */, mode?: 'all' | 'background' | 'border'): void;
1 change: 1 addition & 0 deletions packages/core/ui/utils.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export interface NativeScriptAndroidView extends android.view.View {
_cachedDrawable: android.graphics.drawable.Drawable;
_borderForeground?: org.nativescript.widgets.BorderDrawable;
}

export interface NativeScriptUIView extends UIView {
Expand Down
Loading