SwipeUI

Expandable text

Line-clamped text with an explicitly labelled disclosure, shown only when needed.

npx @swipeui/cli add expandable-text
Variant
Preset
Material
Scheme
Feel
Real free component with a browser animation bridge. Native motion, haptics and materials need a device.

When to use it

  • Long descriptions, reviews or bios that should start short with a Read more link.
  • Product details where the first lines are enough for most people.
  • Comments and captions in feeds.

When not to use it

  • Whole cards that expand. Use Expandable card.
  • Several collapsible sections. Use Accordion.
  • Short text that already fits.

Installation

Run this from your app's root. If SwipeUI isn't set up yet, run npx @swipeui/cli init first; it sets up Uniwind, the theme tokens and the cn helper.

npx @swipeui/cli add expandable-text
  • Adds components/swipeui/ui/expandable-text.tsx and 7 shared helpers.
  • Installs react-native-reanimated, react-native-svg, uniwind, react-native-worklets, clsx, tailwind-merge, class-variance-authority, expo-haptics. In Expo apps it uses npx expo install so versions match your SDK.

Usage

app/review.tsx
import { ExpandableText } from '@/components/swipeui/ui/expandable-text';

<ExpandableText text={review} lines={3} />;

Examples

review, bio, caption share their content and outside Lines, Fade and Below controls in the app and website. Below switches between the inline and below-fade placements. On a card, pass its surface token as fadeColor.

Settings

SettingDefaultBehavior
textrequiredFull visible and spoken text; shaped scripts stay whole.
lines3Positive collapsed line limit. Disclosure appears only on overflow.
togglePlacement'inline'Last-line Read more, or 'below' for a compact link immediately below the faded line.
fadetrueSoft fade across the collapsed last line in either placement.
fadeColorbackground tokenSurface behind the toggle; use the card token on cards.
animatedtrueAnimate measured height with the layout role.
collapsibletrueShow less after opening; false opens once.
messagesRead more / Show lessTranslatable { more, less } strings.
labelsabsentLegacy [more, less] alias; wins over messages.
expandeduncontrolledControlled disclosure state.
defaultExpandedfalseInitial disclosure state.
onExpandedChangeabsentReports disclosure changes.
disabledfalseDisable the disclosure.
hapticstruePress feedback.
motionapp feelShared layout and press feel.
classNameabsentRoot classes.
textClassNameabsentVisible and measuring text classes.
testIDabsentRoot and suffixed part IDs.

Migrating from 1.x

Pass togglePlacement="below" to keep the disclosure below the text. It now sits close to a vertically faded last line. Existing props, including labels, keep working. The URL and install name stay the same; the category is now Text and motion.

Accessibility

One text element carries the full plain string. The disclosure is a button that reports expanded and disabled states. Reduce Motion sets the new height instantly; the hidden measuring copy is excluded from assistive technology.

Behavior and gestures

  • Read more appears inline over the last line, or immediately below its fade; only on overflow.
  • Expanded text has a start-aligned Show less; collapsible=false opens once.
  • togglePlacement=below places the link close below a vertical last-line fade; labels overrides messages.

Accessibility

  • The toggle is a button that reports expanded state.
  • The text stays one run, so right-to-left and complex scripts read correctly.
  • Labels can be translated.

Motion

  • Uses the layout and press motion roles, so it follows your app's feel. Pass motion to tune this one instance.
  • Measured height uses the layout role; Reduce Motion or animated=false changes it instantly.
  • The inline toggle uses the shared press scale.

Performance

  • Measures the text once to decide whether a toggle is needed.

Notes for AI

  • Set lines to the collapsed length you want.

Compatibility

Runs onSupported
Expo SDK 57Yes
Expo SDK 58Yes
React Native CLI (with Expo modules)Yes
Expo GoYes
iOSYes
AndroidYes

This table describes API support and static bundle checks. Native runtime, device accessibility and bare Uniwind compatibility remain pending.

Related items