当前位置: 首页 > news >正文

一款基于 ReactNative 最新发布的`Android/iOS` 新架构文档预览开源库

这是一款基于 ReactNative 发布的Android/iOS 新架构文档预览开源库 三端统一使用点击这里

版本:latest

rn-newarch-doc-viewer

[!TIP] Github 地址

安装与使用

[!TIP] 注意 ⚠️ 本库 android/ios 仅给予 Fabric 新架构支持,旧架构不在跟进,若需旧架构支持请移步原作者https://github.com/philipphecht/react-native-doc-viewer

确保你的 Android/iOS 已经开启了新架构支持 https://reactnative.cn/docs/0.72/the-new-architecture/use-app-template

npm
npm install rn-newarch-doc-viewer
yarn
yarn add rn-newarch-doc-viewer

若想更改库的别名 react-native-doc-viewer 来导入。你则需要把 rn-newarch-doc-viewer 库修改下,重新 yarn 执行

+  "dependencies": {"@react-native-oh/react-native-harmony": "0.72.48","patch-package": "^8.0.0","postinstall-postinstall": "^2.1.0","react": "18.2.0","react-native": "0.72.5",
-    "rn-newarch-doc-viewer":"^0.0.17"
+   "react-native-doc-viewer":"npm:rn-newarch-doc-viewer@0.0.17","react-native-ohos-docviewer": "^0.0.3"},

ios 需要

 cd iosbundle install && bundle exec pod install

下面的代码展示了这个库的基本使用场景:

import React, { useEffect } from "react";
import {Button,DeviceEventEmitter,SafeAreaView,StatusBar,StyleSheet,
} from "react-native";
import OpenFile from "react-native-doc-viewer";
import { getBase64ImagePath } from "./imgbase64";
const App = () => {useEffect(() => {//监听文件预览下载进度const subscribtion = DeviceEventEmitter.addListener("RNDownloaderProgress", (event) => {// 添加事件处理console.log("Download progress:", event.progress);});return () => {// 清理事件监听器subscribtion&& subscribtion.remove();};}, []);const previewImage = () => {OpenFile.openDoc([{url: "https://i.gsxcdn.com/2015162519_i828z3ug.jpeg",//ios required fileNamefileName:'sample',//android required cachecache:false},],(error: any, url: string) => {if (error) {} else {console.log(url);}});};const previewWord = () => {OpenFile.openDoc([{url: "https://calibre-ebook.com/downloads/demos/demo.docx",//ios required fileNamefileName:'demo',//android required cachecache:false},],(error: any, url: string) => {if (error) {} else {console.log(url);}});};const previewBase64 = () => {OpenFile.openDocb64([{base64: getBase64ImagePath(),fileName: "example",fileType: "jpg",},],(error: any, url: string) => {if (error) {} else {console.log(url);}});};const previewXML = () => {OpenFile.openDocBinaryinUrl([{url: "https://storage.googleapis.com/need-sure/example",//ios required fileNamefileName:'example',//android required cachecache:falsefileType: "xml",},],(error: any, url: string) => {if (error) {console.log("Error opening XML file:", error);} else {console.log(url);}});};return (<SafeAreaView style={styles.container}><StatusBar barStyle={"dark-content"} /><Button onPress={previewImage} title="预览图片" /><Button onPress={previewWord} title="预览word文档" /><Button onPress={previewBase64} title="base64打开预览" /><Button onPress={previewXML} title="预览XML" /></SafeAreaView>);
};
export default App;
const styles = StyleSheet.create({container: {flex: 1,},
});

更多详情用法参考 三端统一使用点击这里

开源不易,希望您可以动一动小手点点小 ⭐⭐
👴 希望大家如有好的需求踊跃提交,如有问题请提交 issue,空闲时间会扩充与修复优化

开源协议

本项目基于 The MIT License (MIT) ,请自由地享受和参与开源。

http://www.dtcms.com/a/305923.html

相关文章:

  • Three.js + AI:结合 Stable Diffusion 生成纹理贴图
  • 关于项目的一些完善功能
  • 【BUUCTF系列】[极客大挑战 2019] EasySQL 1
  • 性能优化(一):时间分片(Time Slicing):让你的应用在高负载下“永不卡顿”的秘密
  • Django常见模型字段
  • 【从零实践Onvif】01、Onvif详细介绍(从Onvif客户端开发的角度认识Onvif、Web Servies、WSDL、SOAP)
  • ECMAScript2021(ES12)新特性
  • Python深度挖掘:openpyxl与pandas高效数据处理实战指南
  • 网络编程-(网络计算机和网络通信)
  • Orange的运维学习日记--18.Linux sshd安全实践
  • CUDA编程9 - 卷积实践
  • String模拟实现的补充说明
  • 工业计算机ARM-如何实现工业数字化升级EC100!
  • QT跨平台应用程序开发框架(13)—— 绘图API
  • Linux设备驱动架构相关文章
  • @Scope(value = WebApplicationContext.SCOPE_REQUEST)和@Scope(“prototype“)区别
  • SQL 连接类型示例:内连接与外连接
  • 分布式系统:一致性
  • 二叉树(全)
  • InspireFace SDK gRPC 开发详细指导
  • 大厂主力双塔模型实践与线上服务
  • 嵌入式——C语言:内存管理、位运算符、构造数据类型(共用体、枚举)
  • NVIDIA Isaac平台推动医疗AI机器人发展研究
  • 【LeetCode 热题 100】33. 搜索旋转排序数组——(解法二)一次二分
  • ragflow 报错ERROR: [Errno 111] Connection refused
  • 2025年6月电子学会青少年软件编程(C语言)等级考试试卷(三级)
  • LeetCode 面试经典 150_数组/字符串_轮转数组(6_189_C++_中等)(额外数组;转置)
  • 磁盘io查看命令iostat与网络连接查看命令netstat
  • Apache HTTP Server 2.4.50 路径穿越漏洞(CVE-2021-42013)
  • 矩阵指数函数 e^A