mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
Fix crash where some android Drawables doesn't implement getConstantState... (#4742)
Changed all places where getConstantState was used.
This commit is contained in:
@@ -459,7 +459,16 @@ export class View extends ViewCommon {
|
||||
[backgroundInternalProperty.getDefault](): android.graphics.drawable.Drawable {
|
||||
const nativeView = this.nativeViewProtected;
|
||||
const drawable = nativeView.getBackground();
|
||||
return drawable ? drawable.getConstantState().newDrawable(nativeView.getResources()) : null;
|
||||
if (drawable) {
|
||||
const constantState = drawable.getConstantState();
|
||||
if (constantState) {
|
||||
return constantState.newDrawable(nativeView.getResources());
|
||||
} else {
|
||||
return drawable;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
[backgroundInternalProperty.setNative](value: android.graphics.drawable.Drawable | Background) {
|
||||
this._redrawNativeBackground(value);
|
||||
|
||||
Reference in New Issue
Block a user