@brown-bear/react-native-autoheight-webview

中文文档
2.0.4发布于 2025/08/20MITTypeScriptCommonJS近 30 天下载 8715

An auto height webview for React Native, even auto width for inline html

原始使用文档
文档目录15 节
  1. 🚀 Features
  2. 📦 Installation
  3. 📖 Usage
  4. 📱 Demo
  5. ⚙️ API Reference
  6. Props
  7. FileObject
  8. 📋 Requirements
  9. 📚 Documentation
  10. 🤝 Contributing
  11. 📄 License
  12. 💝 Support
  13. Support the Original Author (iou90)
  14. Support This Fork
  15. 🔗 Links

@brown-bear/react-native-autoheight-webview

An auto height webview for React Native, with support for auto width on inline HTML content. This is a fork of the original project iou90.

License: MIT

🚀 Features

  • Auto Height: Automatically adjusts webview height based on content
  • Auto Width: Supports auto width for inline HTML content
  • Cross Platform: Works on both iOS and Android
  • Customizable: Support for custom CSS, JavaScript, and styling
  • Performance Optimized: Efficient size calculation and updates

📦 Installation

This package requires react-native-webview as a peer dependency.

npm install @brown-bear/react-native-autoheight-webview react-native-webview

📖 Usage

import AutoHeightWebView from '@brown-bear/react-native-autoheight-webview'
import { Dimensions } from 'react-native'

<AutoHeightWebView
style={{
width: Dimensions.get('window').width - 15,
marginTop: 35
}}
customScript={document.body.style.background = 'lightyellow';}
customStyle={ * { font-family: 'Times New Roman'; } p { font-size: 16px; } }
onSizeUpdated={size => console.log(size.height)}
files={[{
href: 'cssfileaddress',
type: 'text/css',
rel: 'stylesheet'
}]}
source={{
html: <p style="font-weight: 400;font-style: normal;font-size: 21px;line-height: 1.58;letter-spacing: -.003em;"> Tags are great for describing the essence of your story in a single word or phrase, but stories are rarely about a single thing. <span style="background-color: transparent !important;background-image: linear-gradient(to bottom, rgba(146, 249, 190, 1), rgba(146, 249, 190, 1));"> If I pen a story about moving across the country to start a new job in a car with my husband, two cats, a dog, and a tarantula, I wouldn't only tag the piece with "moving". I'd also use the tags "pets", "marriage", "career change", and "travel tips". </span> </p>
}}
scalesPageToFit={true}
viewportContent={'width=device-width, user-scalable=no'}
// Additional react-native-webview props supported
/>

📱 Demo

Demo |

You can also try the demo project for a full example.

⚙️ API Reference

Props

PropTypeDefaultDescription
styleViewStyle-Component styling. For iOS text selection issues, reduce width by 15+ and add marginTop 35+
customScriptstring-Custom JavaScript code to inject into the webview
customStylestring-Custom CSS content added to the page's <head>
onSizeUpdatedfunction-Callback triggered when height or width changes
filesFileObject[]-Array of local or remote files to include
sourceobject-WebView source object (HTML, URI, etc.)
scalesPageToFitbooleanfalseEnable page scaling (differs from react-native-webview default)
scrollEnabledWithZoomedinbooleanfalseAllow scrolling on iOS when zoomed in
viewportContentstring'width=device-width' (iOS)Viewport meta tag content
showsVerticalScrollIndicatorbooleanfalseShow vertical scroll indicator
showsHorizontalScrollIndicatorbooleanfalseShow horizontal scroll indicator
originWhiteliststring[]['*']Allowed origins for navigation

FileObject

interface FileObject {
href: string; // File URL or path
type: string; // MIME type (e.g., 'text/css')
rel: string; // Relationship (e.g., 'stylesheet')
}

📋 Requirements

  • React Native >= 0.78
  • react-native-webview >= 13.13.2

📚 Documentation

For earlier versions and migration guides, see the original author's README.

Note: Bug fixes and new features are only included in the latest version.

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

📄 License

This project is licensed under the MIT License.

💝 Support

Support the Original Author (iou90)

Donate

Support This Fork

"Buy Me A Coffee"


Made with ❤️ by the React Native community

版本与发布记录

@brown-bear/react-native-autoheight-webview 共发布 5 个版本,首次发布于 2025/08/20;过去 12 个月发布了 0 个版本。

版本发布日期距今
2.0.4latest2025/08/201.2 年前
2.0.32025/08/201.2 年前
2.0.22025/08/201.2 年前
2.0.12025/08/201.2 年前
2.0.02025/08/201.2 年前

关于 @brown-bear/react-native-autoheight-webview 的常见问题

@brown-bear/react-native-autoheight-webview 是什么?

An auto height webview for React Native, even auto width for inline html

如何安装 @brown-bear/react-native-autoheight-webview?

在项目目录运行 npm install @brown-bear/react-native-autoheight-webview,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(*)、react-native(*)、react-native-webview(>= 13.13.2)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@brown-bear/react-native-autoheight-webview 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@brown-bear/react-native-autoheight-webview 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@brown-bear/react-native-autoheight-webview 可以商用吗?

@brown-bear/react-native-autoheight-webview 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@brown-bear/react-native-autoheight-webview 的下载量有多少?

根据 npm 官方下载统计,@brown-bear/react-native-autoheight-webview 在 2026/10/09 – 2026/11/07 这 30 天内被下载 8,715 次,日均约 291 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@brown-bear/react-native-autoheight-webview 还在维护吗?

最新版本 2.0.4 发布于 2025/08/20(1.2 年前);至今共发布 5 个版本,其中过去 12 个月发布了 0 个;首次发布于 2025/08/20。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。