onPress

Wraps a handler so it fires only on key-down (press), removing the need for an if (press) guard inside onKey (or onUnhandledKey) handlers

import { onPress } from "@roku-sdk/navigation";
onPress(handler: () => KeyResult): KeyPressHandler

Description

Wraps a handler so it fires only on key-down (press), removing the need for an if (press) guard inside onKey (or onUnhandledKey) handlers.

The wrapped handler's verdict is passed through, so returning bubble from it declines the press. The release consumes, which is what a press-only handler wants: it moved nothing on key-up, but letting that key-up bubble past the boundary its press stopped at would be surprising.

Parameters

NameTypeDescription
handler() => KeyResultCalled on key-down. Return bubble to decline the press.

Return values

Returns KeyPressHandler.

Example

onKey: { OK: onPress(() => props.onSelect?.()) }
// equivalent to: OK: press => { if (press) props.onSelect?.(); }
// Declines the press when the grid is already at its last row.
onUnhandledKey: { down: onPress(() => tryMoveDown() || bubble) }

What’s Next

Did this page help you?