doOnShadowModeChange

Callback for ShadowMode changes. The target View is passed as the receiver for action, allowing for unqualified access to its members.

This is a persistent callback, not a one-shot event. To disable, call again passing null for the action.

It is recommended to handle this in the same manner as View updates in recycling Adapters: always account for all possible modes, since multi-property updates could potentially involve invalid intermediate states.

For example, do not do this:

target.doOnShadowModeChange { mode ->
if (mode == ShadowMode.Error) {
foreground = FallbackDrawable()
}
}

Instead, do this:

target.doOnShadowModeChange { mode ->
foreground =
if (mode == ShadowMode.Error) {
FallbackDrawable()
} else {
null
}
}