From 20e6f11eeb99a347cdf6872dfda72ca7977e86fa Mon Sep 17 00:00:00 2001 From: Nathan Walker Date: Mon, 23 May 2022 20:01:55 -0700 Subject: [PATCH] fix(android): race condition on offBackgroundColor view change detection --- packages/core/ui/switch/index.android.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/core/ui/switch/index.android.ts b/packages/core/ui/switch/index.android.ts index f57169c93a..bcf2805b5e 100644 --- a/packages/core/ui/switch/index.android.ts +++ b/packages/core/ui/switch/index.android.ts @@ -57,11 +57,13 @@ export class Switch extends SwitchBase { } private setNativeBackgroundColor(value: string | number | Color) { - if (value instanceof Color) { - // todo: use https://developer.android.com/reference/androidx/core/graphics/BlendModeColorFilterCompat - this.nativeViewProtected.getTrackDrawable().setColorFilter(value.android, android.graphics.PorterDuff.Mode.SRC_OVER); - } else { - this.nativeViewProtected.getTrackDrawable().clearColorFilter(); + if (this.nativeViewProtected) { + if (value instanceof Color) { + // todo: use https://developer.android.com/reference/androidx/core/graphics/BlendModeColorFilterCompat + this.nativeViewProtected.getTrackDrawable().setColorFilter(value.android, android.graphics.PorterDuff.Mode.SRC_OVER); + } else { + this.nativeViewProtected.getTrackDrawable().clearColorFilter(); + } } }