UNPKG

@nativescript/core

Version:

A JavaScript library providing an easy to use api for interacting with iOS and Android platform APIs.

56 lines 2.3 kB
import { Color } from '../../../../color'; import { SDK_VERSION } from '../../../../utils/constants'; export * from './view-helper-common'; export const IOSHelper = 0; const androidxGraphics = androidx.core.graphics; export class AndroidHelper { static getDrawableColor(drawable) { if (!drawable) { return null; } let color; if (drawable instanceof org.nativescript.widgets.BorderDrawable) { color = drawable.getBackgroundColor(); } else if (drawable instanceof android.graphics.drawable.ColorDrawable) { color = drawable.getColor(); } else { // This is a way to retrieve drawable color when set using color filter color = drawable._backgroundColor; } return new Color(color); } static setDrawableColor(color, drawable, blendMode) { // ColorDrawable is an older class that had support for setColorFilter on API 21 if (SDK_VERSION < 21 && drawable instanceof android.graphics.drawable.ColorDrawable) { drawable.setColor(color); } else { drawable.setColorFilter(androidxGraphics.BlendModeColorFilterCompat.createBlendModeColorFilterCompat(color, blendMode ?? androidxGraphics.BlendModeCompat.SRC_IN)); // This is a way to retrieve drawable color when set using color filter drawable._backgroundColor = color; } } static clearDrawableColor(drawable) { // ColorDrawable is an older class that had support for setColorFilter on API 21 if (SDK_VERSION < 21 && drawable instanceof android.graphics.drawable.ColorDrawable) { drawable.setColor(-1); } else { drawable.clearColorFilter(); // This is a way to retrieve drawable color when set using color filter delete drawable._backgroundColor; } } static getCopyOrDrawable(drawable, resources) { if (drawable) { const constantState = drawable.getConstantState(); if (constantState) { return resources ? constantState.newDrawable(resources) : constantState.newDrawable(); } } return drawable; } } //# sourceMappingURL=index.android.js.map