Back to API Reference
Class

KeyboardBehavior

abstract
Inherits:InputBehavior

Base for input behaviors that react to the software keyboard's lifecycle — appearing, hiding, animating, or changing frame — while the field is focused. Subclass to build a reaction: keep the field above the keyboard (KeyboardAvoidanceBehavior), dock a toolbar to the keyboard top, resize a scroll container, dim a backdrop, and so on. Desktop emits no keyboard events, so every subclass is inert there.

Remarks

The base owns the wiring: it routes KeyboardChanged into the per-phase hooks below while the owning editor is focused, and drives OnKeyboardUpdate once per frame. The per-frame tick outlives focus by the tail of a client-side exit animation: while IsAnimating is set after OnFocusLost, ticks keep coming so the reaction can animate back to rest instead of snapping. Subclasses override the hooks they need and add their own serialized fields. Animation has two paths by platform (see OnKeyboardAnimationProgress vs OnKeyboardUpdate); a cross-platform subclass implements both.

Derived Types(1)

Types that inherit from KeyboardBehavior.

protected bool IsAnimating{ get }

Whether the reaction is mid client-side animation and still needs OnKeyboardUpdate ticks — including an exit animation started in OnFocusLost that must finish after focus is already gone. The base keeps the per-frame tick alive while this holds, then releases it, so the field animates to rest rather than snapping.

protected bool IsTearingDown{ get }

True only while the behavior is being disabled/destroyed. An exit reaction must settle to rest immediately here — no further tick can run to animate it.

protected override void OnEnable()
protected override void OnDisable()
protected virtual void OnFocusGained()

The owning field gained focus. Capture any baseline state to restore on focus loss. If the keyboard is already up (switching fields under an open keyboard) a synthetic OnKeyboardWillChangeFrame follows immediately so the reaction can position itself.

protected virtual void OnFocusLost()

The owning field lost focus. Restore any baseline state captured in OnFocusGained.

protected virtual void OnKeyboardWillShow()

System is about to show the keyboard; e carries the destination rect plus animation duration/easing. Start any client-driven animation here.

protected virtual void OnKeyboardAnimationProgress()

Per-frame system animation fraction, only on platforms reporting frame-synced animation (hasFrameSyncedAnimation = Android API 30+). Elsewhere this never fires — animate from OnKeyboardUpdate instead.

protected virtual void OnKeyboardDidShow()

The show animation finished and the keyboard is fully visible.

protected virtual void OnKeyboardWillHide()

System is about to hide the keyboard. Start any client-driven hide animation here.

protected virtual void OnKeyboardDidHide()

The hide animation finished and the keyboard is fully gone.

protected virtual void OnKeyboardWillChangeFrame()

Keyboard frame changed without a hide/show cycle — iPad split-keyboard toggle, hardware keyboard connect/disconnect, rotation, language switch, or a field switch under an open keyboard.

protected virtual void OnKeyboardUpdate()

Per-frame tick (unscaled delta) while focused, plus the tail of a client-side exit animation after focus loss (as long as IsAnimating holds). Drive client-side animation here on platforms without frame-synced progress (iOS, Android <30, WebGL).