Expandable text
Line-clamped text with an explicitly labelled disclosure, shown only when needed.
npx @swipeui/cli add expandable-textWhen 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.tsxand 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 installso versions match your SDK.
Usage
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
| Setting | Default | Behavior |
|---|---|---|
text | required | Full visible and spoken text; shaped scripts stay whole. |
lines | 3 | Positive 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. |
fade | true | Soft fade across the collapsed last line in either placement. |
fadeColor | background token | Surface behind the toggle; use the card token on cards. |
animated | true | Animate measured height with the layout role. |
collapsible | true | Show less after opening; false opens once. |
messages | Read more / Show less | Translatable { more, less } strings. |
labels | absent | Legacy [more, less] alias; wins over messages. |
expanded | uncontrolled | Controlled disclosure state. |
defaultExpanded | false | Initial disclosure state. |
onExpandedChange | absent | Reports disclosure changes. |
disabled | false | Disable the disclosure. |
haptics | true | Press feedback. |
motion | app feel | Shared layout and press feel. |
className | absent | Root classes. |
textClassName | absent | Visible and measuring text classes. |
testID | absent | Root 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
layoutandpressmotion roles, so it follows your app's feel. Passmotionto 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 on | Supported |
|---|---|
| Expo SDK 57 | Yes |
| Expo SDK 58 | Yes |
| React Native CLI (with Expo modules) | Yes |
| Expo Go | Yes |
| iOS | Yes |
| Android | Yes |
This table describes API support and static bundle checks. Native runtime, device accessibility and bare Uniwind compatibility remain pending.