Skip to main content

Interactive

Interactive is a pressable primitive that adds touch feedback to custom controls, such as cards or rows in a list.

Import

import { Interactive } from '@vortexlabs/vortex-native';
import type { InteractiveProps } from '@vortexlabs/vortex-native';

Other links

import { Interactive, Text } from "@vortexlabs/vortex-native";
import { useState } from "react";

export const Example = () => {
  const [count, setCount] = useState(0);
  const disabled = false;

  return (
    <Interactive
      disabled={disabled}
      pressShrink={true}
      touchHitbox
      onPress={() => setCount((value) => value + 1)}
    >
      {({ pressed }) => (
        <Text color={pressed || disabled ? "subtle" : "default"}>
          {pressed ? "Pressed" : count ? `Presses: ${count}` : "Press me"}
        </Text>
      )}
    </Interactive>
  );
};

Features

  • Supports presses, long presses, and URL navigation.
  • Exposes pressed state to children and styles.
  • Supports touch target expansion, press shrink, and haptics.

Pressable Card

Use function children to change the card's surface while pressed. Place secondary controls outside the card so screen readers can reach them separately.

import { Interactive, Stack, Text } from "@vortexlabs/vortex-native";
import { useState } from "react";

export const PressableCard = () => {
  const [detailsOpen, setDetailsOpen] = useState(false);

  return (
    <Stack gap={2}>
      <Interactive
        pressShrink
        onPress={() => setDetailsOpen((open) => !open)}
        attributes={{ "aria-expanded": detailsOpen, "aria-label": "Project details" }}
      >
        {({ pressed }) => (
          <Stack
            padding={4}
            gap={2}
            borderRadius="md"
            borderColor="default"
            backgroundColor={pressed ? "surface" : "default"}
          >
            <Text size="body-lg" weight="semibold">Pressable card</Text>
            <Text size="link-sm" color="primary">
              {detailsOpen ? "Hide details" : "Open details"}
            </Text>
          </Stack>
        )}
      </Interactive>
      {detailsOpen ? (
        <Stack paddingInline={4}>
          <Text>Project status: In progress</Text>
        </Stack>
      ) : null}
    </Stack>
  );
};

Long Press

Provide onLongPress for a secondary action. On iOS and Android, screen readers can invoke it without a touch event.

import { Interactive, Stack, Text } from "@vortexlabs/vortex-native";
import { useState } from "react";

export const LongPressExample = () => {
  const [action, setAction] = useState("Press or hold the control");

  return (
    <Stack gap={2}>
      <Interactive
        onPress={() => setAction("Pressed")}
        onLongPress={() => setAction("Held")}
        touchHitbox
      >
        Press and hold
      </Interactive>
      <Text attributes={{ accessibilityLiveRegion: "polite" }}>{action}</Text>
    </Stack>
  );
};

Disabled

Set disabled to prevent presses and navigation. Style the content to show that the control is unavailable.

import { Interactive, Stack, Text } from "@vortexlabs/vortex-native";

export const DisabledExamples = () => (
  <Stack direction="row" gap={4} wrap>
    <Interactive disabled>
      <Text color="subtle">Disabled button</Text>
    </Interactive>
    <Interactive disabled href="https://vortex.mobile">
      <Text color="subtle">Disabled link</Text>
    </Interactive>
  </Stack>
);

Press Feedback

Use the style callback to change the appearance while pressed. Enable pressShrink to also scale the control on press. The provider setting and Reduce Motion can turn the animation off.

import { Interactive, Stack, Text } from "@vortexlabs/vortex-native";

export const PressFeedbackExample = () => (
  <Stack direction="row" gap={3} wrap>
    <Interactive style={({ pressed }) => ({ opacity: pressed ? 0.7 : 1 })}>
      <Stack padding={3} borderRadius="md" borderColor="default" backgroundColor="surface">
        <Text>Fixed size</Text>
      </Stack>
    </Interactive>
    <Interactive pressShrink style={({ pressed }) => ({ opacity: pressed ? 0.7 : 1 })}>
      <Stack padding={3} borderRadius="md" borderColor="default" backgroundColor="surface">
        <Text>Shrinks on press</Text>
      </Stack>
    </Interactive>
  </Stack>
);

Scrolling Lists

Set delayPressIn on scrollable rows to wait 100ms before showing the pressed state.

<Interactive delayPressIn onPress={openItem}>
  {({ pressed }) => (
    <Text color={pressed ? "subtle" : "default"}>Open item</Text>
  )}
</Interactive>

Touch Hitbox

Set touchHitbox to extend a small control's press area without changing its layout. The default theme targets 44pt. Leave room around the control and use the Icon source example to define Hexagon.

<Stack width={44} height={44} align="center" justify="center">
  <Interactive
    touchHitbox
    onPress={openDetails}
    attributes={{ "aria-label": "Open details" }}
  >
    <Icon src={Hexagon} />
  </Interactive>
</Stack>

Set href to open an external URL with React Native Linking. Call event.preventDefault() in onPress when your app needs to confirm the destination first.

<Interactive href="https://vortex.mobile">Vortex website</Interactive>

App Routes

For an in-app route such as /about, wrap the supplied pressable in an Expo Router link using render.

import { Interactive } from "@vortexlabs/vortex-native";
import { Link as RouterLink } from "expo-router";

export const AboutLink = () => (
  <Interactive
    render={(element) => (
      <RouterLink href="/about" asChild>
        {element}
      </RouterLink>
    )}
    attributes={{ role: "link" }}
  >
    About
  </Interactive>
);

Haptics

Set haptic to play feedback on press. A touch long press with onLongPress plays a medium impact. Configure an adapter in VortexProvider.

<Interactive haptic="selection" onPress={selectOption}>
  Select option
</Interactive>

Accessibility

Description
Set href for link semantics. The default role is button.
Set attributes={{ 'aria-label': 'Open details' }} for an icon-only pressable.