npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

react-native-highlight-text-view

v0.1.30

Published

A native text input for React Native that supports inline text highlighting

Readme

react-native-highlight-text

A native text input for React Native that supports inline text highlighting

Installation

npm install react-native-highlight-text

Usage

import { useState } from 'react';
import { HighlightTextView } from 'react-native-highlight-text-view';

export default function App() {
  const [text, setText] = useState('Hello World');

  return (
    <HighlightTextView
      color="#00A4A3"
      textColor="#000000"
      textAlign="flex-start"
      fontSize="32"
      paddingLeft="8"
      paddingRight="8"
      paddingTop="4"
      paddingBottom="4"
      text={text}
      isEditable={true}
      onChange={(e) => {
        setText(e.nativeEvent.text);
      }}
      style={{ width: '100%', height: 200 }}
    />
  );
}

Props

| Prop | Type | Default | Description | | ----------------------- | ---------------------------------------------------- | --------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | color | string | #FFFF00 | Background highlight color (hex format) | | textColor | string | - | Text color (hex format) | | textAlign | string | left | Text alignment. Supports: 'left', 'center', 'right', 'justify', 'flex-start', 'flex-end', 'top', 'bottom', 'top-left', 'top-center', 'top-right', 'bottom-left', 'bottom-center', 'bottom-right' | | verticalAlign | 'top' \| 'center' \| 'middle' \| 'bottom' | - | Vertical alignment (iOS only). Alternative to using combined textAlign values. Note: Android does not support vertical alignment and will use default vertical positioning. | | fontFamily | string | - | Font family name | | fontSize | string | 32 | Font size in points | | letterSpacing | string | 0 | Extra space between characters, in layout points (same semantics as React Native's letterSpacing). | | lineHeight | string | 0 | Line height override (0 means use default line height) | | highlightBorderRadius | string | 0 | Border radius for the highlight background | | padding | string | 4 | Padding around each character highlight (expands background outward) | | paddingLeft | string | - | Left padding for character highlight | | paddingRight | string | - | Right padding for character highlight | | paddingTop | string | - | Top padding for character highlight | | paddingBottom | string | - | Bottom padding for character highlight | | backgroundInsetTop | string | 0 | Shrinks background from top (useful for fonts with large vertical metrics) | | backgroundInsetBottom | string | 0 | Shrinks background from bottom (useful for fonts with large vertical metrics) | | backgroundInsetLeft | string | 0 | Shrinks background from left | | backgroundInsetRight | string | 0 | Shrinks background from right | | text | string | - | Controlled text value | | isEditable | boolean | true | Whether the text is editable | | autoFocus | boolean | false | If true, automatically focuses the text input and opens the keyboard when component mounts (only works when isEditable is true) | | onChange | (event: { nativeEvent: { text: string } }) => void | - | Callback fired when text changes |

Understanding Padding vs Background Insets

  • Padding props (paddingTop, paddingBottom, etc.): Expand the background outward from the text, adding extra colored area around glyphs.
  • Background inset props (backgroundInsetTop, backgroundInsetBottom, etc.): Shrink the background inward from the font's line box, creating tighter wrapping around actual glyphs.

Use case for background insets: Some fonts (like Eczar, Georgia, etc.) have large built-in vertical metrics (ascender/descender), making highlights appear too tall. Use backgroundInsetTop and backgroundInsetBottom to create a tighter fit around the visible glyphs.

Example with large-metric font:

<HighlightTextView
  fontFamily="Eczar"
  fontSize="32"
  paddingLeft="8"
  paddingRight="8"
  paddingTop="4"
  paddingBottom="4"
  backgroundInsetTop="6"
  backgroundInsetBottom="6"
  text="Tight Background"
/>

Example with touching backgrounds (tight line spacing): To make backgrounds touch vertically across multiple lines, combine lineHeight with backgroundInset:

<HighlightTextView
  fontSize="32"
  lineHeight="36" // Slightly larger than fontSize for tight spacing
  paddingLeft="8"
  paddingRight="8"
  paddingTop="4"
  paddingBottom="4"
  backgroundInsetTop="14" // Large inset reduces background height
  backgroundInsetBottom="14" // Creates room for lines to touch
  highlightBorderRadius="4"
  text="Multiple lines with touching backgrounds create smooth vertical flow"
/>

Tip: Set lineHeight to approximately fontSize + 4 to fontSize + 8, then adjust backgroundInsetTop and backgroundInsetBottom until backgrounds touch smoothly.

Note: Vertical alignment is currently supported on iOS only. On Android, text will use default vertical positioning.

Auto-focusing the Input

To automatically open the keyboard when the component mounts, use the autoFocus prop:

<HighlightTextView
  color="#00A4A3"
  textColor="#FFFFFF"
  fontSize="20"
  text={text}
  isEditable={true}
  autoFocus={true} // Keyboard opens automatically
  onChange={(e) => setText(e.nativeEvent.text)}
  style={{ width: '100%', height: 100 }}
/>

This eliminates the need for double-tapping to open the keyboard - it will open on first render.

Dynamic Font Family Changes

IMPORTANT: When changing fontFamily dynamically at runtime (especially to fonts with different ascender/descender values like Eczar, Georgia, etc.), you must use the key prop to force React to remount the component. This ensures the native layout recalculates with the new font metrics.

Why this is needed: Fonts like Eczar have significantly larger vertical metrics than system fonts. Without remounting, the highlight background may appear cut off at the bottom or lose corner radius.

Solution: Pass the fontFamily as the key prop:

const [fontFamily, setFontFamily] = useState('system');

return (
  <HighlightTextView
    key={fontFamily} 
    fontFamily={fontFamily}
    fontSize="32"
    color="#00A4A3"
    textColor="#FFFFFF"
    paddingLeft="8"
    paddingRight="8"
    paddingTop="4"
    paddingBottom="4"
    backgroundInsetTop="6" 
    backgroundInsetBottom="6"
    highlightBorderRadius="8"
    text="Beautiful Eczar Font"
    style={{ width: '100%', height: 150 }}
  />
);

What happens:

  • Font changes → key changes → React unmounts old component and mounts new one
  • New mount → Native component calculates fresh layout with correct font metrics
  • Perfect rendering → Background highlights render correctly without cutting

Without key prop: Background may cut off, corner radius may disappear
With key prop: Perfect rendering every time ✅

Contributing

License MIT

Made with create-react-native-library