PressableFeedback

Native press feedback (scale, highlight) for custom tappable content.

  • Composed
  • New in 0.1
import { PressableFeedback, HIGHLIGHT_OPACITY, PressSurface, pressableFeedbackPrimitive } from "nitro-ui-sdk/pressable-feedback";
HeroUI Native
PressableFeedback
Expo UI
No counterpart
  • PressableFeedback example screen, light appearance
    Light
  • PressableFeedback example screen, dark appearance
    Dark
On this page

Turns any content into one accessible button with native press feedback: a card, a row, an album tile. The content is decorative; label names the whole control. The feedback (scale, highlight, opacity or none) runs as a native animation, and under Reduce Motion it becomes an instant dim. It is also the body every action family in the kit is built on. Use Button or IconButton when the control is a standard button, and ListRow for list rows.

Anatomy

import { Text } from "nitro-ui-renderer";
import { PressableFeedback } from "nitro-ui-sdk/pressable-feedback";

export function Anatomy() {
  return (
    <PressableFeedback.Root label="Open album Summer" feedback="highlight" onPress={() => {}}>
      <Text>{"Summer"}</Text>
    </PressableFeedback.Root>
  );
}
Part Description
PressableFeedback.Root The native pressable host around the content. It owns the name, the press, the long press and the feedback.
highlight (style part) The overlay drawn over the content while pressed with feedback="highlight". It is not a component; style it through styles.highlight.

Usage

import { Text, View } from "nitro-ui-renderer";
import { PressableFeedback } from "nitro-ui-sdk/pressable-feedback";
import { textStyle, useTheme } from "nitro-ui-sdk/theme";

export function AlbumCard({ open }: { open: () => void }) {
  const { tokens } = useTheme();
  return (
    <PressableFeedback.Root label="Open album Summer in Lisbon" onPress={open}>
      <View layout={{ padding: 16, gap: 4 }} style={{ background: tokens.colors.surface, cornerRadius: tokens.radius.card }}>
        <Text {...textStyle(tokens, "headline")}>{"Summer in Lisbon"}</Text>
        <Text {...textStyle(tokens, "subheadline", tokens.colors.muted)}>{"248 photos"}</Text>
      </View>
    </PressableFeedback.Root>
  );
}

A long press needs a name for its assistive action:

import { Text } from "nitro-ui-renderer";
import { PressableFeedback } from "nitro-ui-sdk/pressable-feedback";

export function Note({ open, showOptions }: { open: () => void; showOptions: () => void }) {
  return (
    <PressableFeedback.Root label="Open note Groceries" onPress={open} onLongPress={showOptions} longPressLabel="Show options">
      <Text>{"Groceries"}</Text>
    </PressableFeedback.Root>
  );
}

Variants and sizes

The variant is the feedback:

feedback Pressed Released
scale (default) Timing (motion.duration.fast) to motion.pressedScale. spring.snappy back to 1.
highlight The foreground color at 12% over the content, at once. Fades out.
opacity Dims to opacity.pressed at once. Fades back.
none Nothing moves. —

Under Reduce Motion every look except none dims the content instantly instead. There are no sizes: the content decides the size.

States

  • Disabled: dims to opacity.disabled, refuses presses and long presses, and stops tracking touches.
  • Pressed: follows the finger with 32 pt of slack, as UIKit controls do; leaving the area releases it, a scroll or a sheet drag cancels it.
  • Long press: fires after longPressDuration (0.5 s) with a medium impact; the press that follows is dropped.

Props

PressableFeedback.Root

Prop Type Default Description
label string required The name of the whole content.
children ReactNode required Decorative content; its text is not read separately.
onPress (details: ActionDetails) => void — Runs on every accepted press.
onLongPress (details: ActionDetails) => void — Runs after a held touch or the assistive action. Requires longPressLabel.
longPressLabel string — Spoken name of the long-press action for assistive technology.
longPressDuration number 0.5 Seconds before the long press (iOS).
feedback "scale" | "highlight" | "opacity" | "none" "scale" See Variants.
role "button" | "link" "button" Use link when the content navigates to a web destination.
disabled boolean false Refuses every press.
hint string — Accessibility hint.
haptic "light" | "medium" | "heavy" | "none" "light" Impact on a touch press. Long presses use medium impact. Set "none" to mute both.
api Controller<PressableFeedbackActions> — From pressableFeedbackPrimitive.createApi().
agentId string — Stable agent identity.
confirm { message, approveLabel, cancelLabel } — Asks before an agent presses.
styles PressableFeedbackStyles — root and highlight resolvers.
layout LayoutProps — Layout of the host.

Controller API

import { useState } from "react";
import { Text } from "nitro-ui-renderer";
import { PressableFeedback, pressableFeedbackPrimitive } from "nitro-ui-sdk/pressable-feedback";

export function Tile({ open }: { open: () => void }) {
  const [api] = useState(pressableFeedbackPrimitive.createApi);
  return (
    <PressableFeedback.Root label="Open tile" api={api} onPress={open}>
      <Text>{"Tile"}</Text>
    </PressableFeedback.Root>
  );
}
Action Signature Result
press (source?: ActionSource) => ActionStatus accepted, disabled, refused, or unavailable without onPress.
longPress (source?: ActionSource) => ActionStatus The same; unavailable without onLongPress.

Styles

import { Text } from "nitro-ui-renderer";
import { PressableFeedback, type PressableFeedbackStyles } from "nitro-ui-sdk/pressable-feedback";

const styles: PressableFeedbackStyles = {
  root: ({ tokens }) => ({ style: { cornerRadius: tokens.radius.card } }),
  highlight: ({ tokens }) => ({ style: { background: tokens.colors.accent } }),
};

export function Row() {
  return (
    <PressableFeedback.Root label="Storage" feedback="highlight" styles={styles} onPress={() => {}}>
      <Text>{"Storage"}</Text>
    </PressableFeedback.Root>
  );
}

Parts: root, highlight. The resolver receives { tokens, variant, size: "content", state: { disabled } } where variant is the feedback. Give the root the content’s cornerRadius so the highlight follows its shape.

Accessibility

  • One element with the button (or link) trait named by label; the content’s own text is not read.
  • A long press is listed as a custom action named longPressLabel.
  • Disabled adds notEnabled.
  • On iOS, the touch area grows to 44 × 44 pt around small content without changing its layout. On Android, the host reserves a 44 × 44 dp area.
  • Reduce Motion replaces movement with an instant dim.

Agent API

Action Arguments Notes
press none Listed when onPress is provided.
longPress none Listed only with onLongPress.

The entry has component: "PressableFeedback", role: "button" or "link" and state: { disabled }.

Platform notes

iOS Android
Host KitPressable: a UIView accessibility element with a UIGestureRecognizer tracker. UIKit delivers tap and long-press actions after recognition. When an enclosing scroll view begins panning, the tracker releases feedback and cancels pending actions. A recognized long press claims the touch until lift. Nested pressables and enabled UIControls keep their own touches. PressableGroup reports press feedback via setPressed and uses native click and long-click listeners. longPressLabel names the assistive long-click action.
Feedback view.animate / view.animateSpring (UIViewPropertyAnimator) started from JS on the main thread; no per-frame JS. The same calls, run by the renderer’s Android views.
Hit area minimumHitSize (44) through point(inside:). The host reserves at least 44 display-independent pixels on each axis. When layout is tighter, it expands the native touch area around the visual surface.
Long press duration longPressDuration. The system long-press timeout.
Verification Unit, type and iOS harness tests cover feedback and actions. A debug-only probe drives the mounted tracker through hit testing, drag-out, tap, long press and interrupted presses. It advances the surrounding UIKit pan recognizer and checks for active native opacity animation. Kotlin implementation is unbuilt here (no Android NDK).