Web Analytics

react-native-nitro-text

⭐ 200 stars Simplified Chinese by patrickkabwe

react-native-nitro-text

一个在 iOS 和 Android 上都更加丰富且高性能的文本组件。

https://github.com/user-attachments/assets/57f56b3f-3988-4235-af83-a5f2cfd82121

npm version Discord npm downloads npm downloads mit licence


功能

需求

安装

yarn add react-native-nitro-text react-native-nitro-modules

iOS

cd ios && pod install && cd ..
就是这样。你现在可以在你的应用中使用 NitroText 组件了。

使用方法

import { NitroText as Text } from 'react-native-nitro-text'

export function Title() { return ( 🚀 NitroText Showcase ) }

选择

iOS 使用原生选择。 在 Android 上,NitroText 当前回退到 React Native 的 Text

import { NitroText as Text } from 'react-native-nitro-text'

export function SelectionExample() { return ( Long-press to select this text. NitroText supports smooth selection, even with inline styles and longer paragraphs. ) }

HTML 渲染

当您传入 renderer="html" 时,NitroText 可以解析 HTML 字符串子元素和内联 CSS。

import { NitroText } from 'react-native-nitro-text'

export function HtmlExample() { const html =

Renderer demo

This text comes from HTML with semantic tags.

Inline CSS works too.

return {html} }

自定义选择菜单

NitroText 支持在选中文本时出现的自定义菜单项。传入一个包含菜单项数组的 menus 属性,每个菜单项包含一个 titleaction 回调。

import { NitroText } from 'react-native-nitro-text'
import { useMemo } from 'react'

export function MenuExample() { const menus = useMemo( () => [ { title: 'Copy', action: () => console.log('Copy action') }, { title: 'Share', action: () => console.log('Share action') }, { title: 'Translate', action: () => console.log('Translate action') }, ], [] )

return ( Select this text to see custom menu options appear in the selection menu. ) }

平台支持

为什么选择 NitroText?

自定义原生文本视图,具有最小的 JS 开销和原生 iOS 选择功能。非常适合重度/嵌套样式文本和大型列表。它是 RN Text 组件的替代品。

开发

致谢

基于 create-nitro-module 启动。

贡献

欢迎 PR!重大更改请先提出 issue。

💬 如需快速支持,请加入我们的 Discord 频道

--- Tranlated By Open Ai Tx | Last indexed: 2026-05-13 ---