ShadowDrawable

This class is a thin wrapper around the library's core draw functionalities, allowing its shadows to be drawn manually.

The user is responsible for invalidating the current draw whenever a property's value is changed. Failure to do so can result in a few different possible defects, depending on the specific setup, including misaligned clip regions, stale draws, etc.

Clipped instances with irregular shapes on API levels 30+ must have the outline Path set manually using the setClipPathProvider function. This is analogous to setting a ViewPathProvider on a target View.

All ShadowDrawable instances created with an owner should call dispose. This is technically not necessary for the those created with the @RequiresApi(29) constructor, but it is still safe to call dispose on such instances. Use after disposal is not an automatic Exception, but it is not advised, and there is no guaranteed behavior.

The Drawable class's required setColorFilter override is a no-op here.

The color compat functionality is exposed here through the colorCompat property, which is set to black by default, disabling the tinting. Setting any non-black color enables color compat, and the ambientColor and spotColor values are then ignored.

Color compat requires an owner View that must be attached to the onscreen hierarchy. Instances created with the @RequiresApi(29) constructor will throw an IllegalStateException upon any attempt to set colorCompat.

Normally the owner is just the View in which the draw happens, though that's not strictly necessary. However, due to a limitation in the core graphics framework, the color compat mechanism needs to track its onscreen location, and the lighting effects may go out of sync with the expected appearance if the drawing View moves differently than the owner.

Color compat shadows are always clipped to the drawable's bounds.

Constructors

Link copied to clipboard
constructor(owner: View, isClipped: Boolean)

The base constructor for all API levels requires an owner View that must be attached to the onscreen hierarchy.

@RequiresApi(value = 29)
constructor(isClipped: Boolean)

At API level 29, an owner View is not required, but color compat is unavailable for these instances.

Properties

Link copied to clipboard
open override var alpha: Int
Link copied to clipboard

Determines whether the shadow will be clipped to the drawable's bounds.

Link copied to clipboard

The color that the compat mechanism uses to tint the shadow. The default value is black (#FF000000), which disables the tint. If any other color is set, the compat mechanism takes over, and the ambientColor and spotColor values are ignored.

Link copied to clipboard
Link copied to clipboard

Flag to indicate whether the library shadow should always be composited through a layer, regardless of the color compat state.

Link copied to clipboard
Link copied to clipboard
open override val opacity: Int
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Functions

Link copied to clipboard
fun dispose()

Releases any active internal resources.

Link copied to clipboard
open override fun draw(canvas: Canvas)
Link copied to clipboard
open override fun getAlpha(): Int

Analogous to RenderNode#getAlpha(), but returns an Int to conform to Drawable's API.

Link copied to clipboard
Link copied to clipboard
fun getMatrix(outMatrix: Matrix)
Link copied to clipboard
open override fun getOpacity(): Int
Link copied to clipboard
Link copied to clipboard
open override fun setAlpha(alpha: Int)

Analogous to RenderNode#setAlpha(), but takes an Int to conform to Drawable's API.

Link copied to clipboard
fun setClipPathProvider(provider: (Path) -> Unit?)

Sets the function through which to provide irregular Paths for clipping on API levels 30 and above.

Link copied to clipboard
open override fun setColorFilter(colorFilter: ColorFilter?)
Link copied to clipboard
fun setOutline(outline: Outline)
Link copied to clipboard
fun setPosition(left: Int, top: Int, right: Int, bottom: Int)