-
Notifications
You must be signed in to change notification settings - Fork 5
ShadowMode
Package: com.zedalpha.shadowgadgets.view
(docs)
public enum class ShadowMode { Native, Library, Error }An enum describing the possible shadow modes.
-
Native: The native shadow is in place. -
Library: A library shadow is attached and working normally. -
Error: The library encountered an issue and has disabled the shadow.
(docs)
public val View.shadowMode: ShadowModeAn extension that returns the receiver's current ShadowMode.
(docs)
public fun View.doOnShadowModeChange(action: (View.(mode: ShadowMode) -> Unit)?)A callback that's meant mainly for error handling.
All known error states are generally fixable
with simple design-time property adjustments, except for one: potential failures
on non-ViewGroup roots, e.g., ImageViews added directly to WindowManager.
There's no way to know all the specific environments in which they may fail, so
this runtime callback is offered as an opportunity for the user to apply their
own fallback.
It is recommended to handle this in the same manner as View updates in
recycling Adapters – always account for all possible states – since
multi-property updates could potentially involve invalid intermediate states.
For example, don't do this:
target.doOnShadowModeChange { mode ->
if (mode == ShadowMode.Disabled) {
foreground = FallbackShadowDrawable()
}
}Instead, do this:
target.doOnShadowModeChange { mode ->
foreground =
if (mode == ShadowMode.Disabled) {
FallbackShadowDrawable()
} else {
null
}
}The demo app handles Error modes exactly as shown above in its
ViewRootTopic class.