Skip to content

fix(android): Background color is not applied to certain views #10652

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
4 changes: 4 additions & 0 deletions packages/core/ui/action-bar/index.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@ export class ActionBar extends ActionBarBase {
this.update();
}

override get needsNativeDrawableFill(): boolean {
return true;
}

public update() {
if (!this.nativeViewProtected) {
return;
Expand Down
4 changes: 4 additions & 0 deletions packages/core/ui/button/index.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ export class Button extends ButtonBase {
}
}

override get needsNativeDrawableFill(): boolean {
return true;
}

[minWidthProperty.getDefault](): CoreTypes.LengthType {
const dips = org.nativescript.widgets.ViewHelper.getMinWidth(this.nativeViewProtected);

Expand Down
3 changes: 2 additions & 1 deletion packages/core/ui/core/view/index.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1134,7 +1134,8 @@ export class View extends ViewCommon {
nativeView.setBackground(backgroundDrawable);
}

if (backgroundDrawable) {
// Apply color to drawables when there is the need to maintain visual things like button ripple effect
if (this.needsNativeDrawableFill && backgroundDrawable) {
backgroundDrawable.mutate();

AndroidHelper.setDrawableColor(backgroundColor, backgroundDrawable);
Expand Down
4 changes: 4 additions & 0 deletions packages/core/ui/core/view/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,10 @@ export abstract class View extends ViewCommon {
* @private
*/
isLayoutRequired: boolean;
/**
* @private
*/
get needsNativeDrawableFill(): boolean;
/**
* @private
*/
Expand Down
4 changes: 4 additions & 0 deletions packages/core/ui/core/view/view-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -984,6 +984,10 @@ export abstract class ViewCommon extends ViewBase implements ViewDefinition {
return true;
}

get needsNativeDrawableFill(): boolean {
return false;
}

public measure(widthMeasureSpec: number, heightMeasureSpec: number): void {
this._setCurrentMeasureSpecs(widthMeasureSpec, heightMeasureSpec);
}
Expand Down
Loading