From 016313bef1e139228a8d336c59f7d1d868b302de Mon Sep 17 00:00:00 2001 From: Martin Guillon Date: Wed, 17 Feb 2021 17:07:38 +0100 Subject: [PATCH] fix: automated tests are now passing --- packages/core/ui/action-bar/index.android.ts | 11 ++++++++++- packages/core/ui/button/index.android.ts | 11 +++++++++-- packages/core/ui/core/view/index.android.ts | 2 +- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/packages/core/ui/action-bar/index.android.ts b/packages/core/ui/action-bar/index.android.ts index e8faf9c0c..0fdbdf3c2 100644 --- a/packages/core/ui/action-bar/index.android.ts +++ b/packages/core/ui/action-bar/index.android.ts @@ -225,7 +225,16 @@ export class ActionBar extends ActionBarBase { const nativeView = this.nativeViewProtected; if (backgroundDrawable && onlyColor && sdkVersion() >= 21) { if (isBorderDrawable && (nativeView)._cachedDrawable) { - backgroundDrawable = (nativeView)._cachedDrawable.newDrawable(nativeView.getResources()); + backgroundDrawable = (nativeView)._cachedDrawable; + // we need to duplicate the drawable or we lose the "default" cached drawable + const constantState = backgroundDrawable.getConstantState(); + if (constantState) { + try { + backgroundDrawable = constantState.newDrawable(nativeView.getResources()); + // eslint-disable-next-line no-empty + } catch {} + } + nativeView.setBackground(backgroundDrawable); nativeView.setBackground(backgroundDrawable); } diff --git a/packages/core/ui/button/index.android.ts b/packages/core/ui/button/index.android.ts index 036737b3d..9b9092a09 100644 --- a/packages/core/ui/button/index.android.ts +++ b/packages/core/ui/button/index.android.ts @@ -62,10 +62,17 @@ export class Button extends ButtonBase { public _applyBackground(background: Background, isBorderDrawable, onlyColor: boolean, backgroundDrawable: any) { const nativeView = this.nativeViewProtected; - console.log('_applyBackground', nativeView, backgroundDrawable, onlyColor, isBorderDrawable); if (backgroundDrawable && onlyColor) { if (isBorderDrawable && (nativeView)._cachedDrawable) { - backgroundDrawable = (nativeView)._cachedDrawable.newDrawable(nativeView.getResources()); + backgroundDrawable = (nativeView)._cachedDrawable; + // we need to duplicate the drawable or we lose the "default" cached drawable + const constantState = backgroundDrawable.getConstantState(); + if (constantState) { + try { + backgroundDrawable = constantState.newDrawable(nativeView.getResources()); + // eslint-disable-next-line no-empty + } catch {} + } nativeView.setBackground(backgroundDrawable); } diff --git a/packages/core/ui/core/view/index.android.ts b/packages/core/ui/core/view/index.android.ts index e9052d1d9..84883dc4d 100644 --- a/packages/core/ui/core/view/index.android.ts +++ b/packages/core/ui/core/view/index.android.ts @@ -996,7 +996,7 @@ export class View extends ViewCommon { if (constantState) { try { drawable = constantState.newDrawable(nativeView.getResources()); - // eslint-disable-next-line no-empty + // eslint-disable-next-line no-empty } catch {} } }