ShadowDrawable
This class is a thin wrapper around the library's core draw functionalities, allowing its shadows to be drawn manually without having to use the core module directly.
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.
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.
The color compat functionality is exposed here through the colorCompat property, which is set to black by default, disabling the compat tinting. Setting any non-black color enables color compat, and the ambientColor and spotColor values are then ignored.
Color compat requires an owner View in order to be able to hook into the hardware-accelerated draw routine, and that View must be attached to the onscreen hierarchy. Instances created with the @RequiresApi(29) constructor will throw an IllegalStateException upon attempts to modify colorCompat.
Color compat shadows are always clipped to the drawable's bounds.
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.
All ShadowDrawable instances created with an owner should call dispose. This is technically not necessary for the @RequiresApi(29) ones, but it is still safe to call dispose on those 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.
Constructors
The base constructor for all API levels requires an owner View that must be attached to the onscreen hierarchy.
At API level 29, an owner View is not required, but color compat is unavailable for these instances.
Properties
Analogous to RenderNode#getAmbientShadowColor() and RenderNode#setAmbientShadowColor().
Analogous to RenderNode#getCameraDistance() and RenderNode#setCameraDistance().
Determines whether the shadow will be clipped to the drawable's bounds.
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 ambient and spot values are ignored.
Analogous to RenderNode#getElevation() and RenderNode#setElevation().
Flag to indicate whether the library shadow should always be composited through a layer, regardless of the color compat state.
Analogous to RenderNode#getPivotX() and RenderNode#setPivotX().
Analogous to RenderNode#getPivotY() and RenderNode#setPivotY().
Analogous to RenderNode#getRotationX() and RenderNode#setRotationX().
Analogous to RenderNode#getRotationY() and RenderNode#setRotationY().
Analogous to RenderNode#getRotationZ() and RenderNode#setRotationZ().
Analogous to RenderNode#getScaleX() and RenderNode#setScaleX().
Analogous to RenderNode#getScaleY() and RenderNode#setScaleY().
Analogous to RenderNode#getSpotShadowColor() and RenderNode#setSpotShadowColor().
Analogous to RenderNode#getTranslationX() and RenderNode#setTranslationX().
Analogous to RenderNode#getTranslationY() and RenderNode#setTranslationY().
Analogous to RenderNode#getTranslationZ() and RenderNode#setTranslationZ().
Functions
Analogous to RenderNode#getAlpha(), but returns an Int to conform to Drawable's API.
Analogous to RenderNode#getInverseMatrix().
Analogous to RenderNode#getMatrix().
Analogous to RenderNode#hasIdentityMatrix().
Analogous to RenderNode#setAlpha(), but takes an Int to conform to Drawable's API.
Sets the function through which to provide irregular Paths for clipping on API levels 30 and above.
Analogous to RenderNode#setOutline().