Skip to content

ShadowMode

zed-alpha edited this page May 10, 2026 · 1 revision

Package: com.zedalpha.shadowgadgets.view


ShadowMode

(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.

View.shadowMode

(docs)

public val View.shadowMode: ShadowMode

An extension that returns the receiver's current ShadowMode.

View.doOnShadowModeChange

(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
        }
}

Examples

The demo app handles Error modes exactly as shown above in its ViewRootTopic class.

Clone this wiki locally