摘要:文檔查看組件,可以在手機(jī)上直接打開(kāi)文檔,支持遠(yuǎn)程和本地文檔。
本文原創(chuàng)首發(fā)于公眾號(hào):ReactNative開(kāi)發(fā)圈,轉(zhuǎn)載需注明出處。
安裝方法React Native 文檔查看組件:react-native-doc-viewer,可以在手機(jī)上直接打開(kāi)文檔,支持遠(yuǎn)程和本地文檔。支持的文檔格式:xls,ppt,doc,xlsx,pptx,docx,png,jpg,pdf,mp4。支持iOS和Android。
npm install react-native-doc-viewer --save react-native link react-native-doc-viewerAPI說(shuō)明
openDoc 打開(kāi)遠(yuǎn)程貨或本地文檔
openDocb64 打開(kāi)Base64字符串格式文檔
openDocBinaryinUrl 打開(kāi)二進(jìn)制文件
playMovie 打開(kāi)視頻文件
使用示例import React, { Component } from "react"; import { AppRegistry, StyleSheet, Text, View, Platform, Button, Alert, ActivityIndicator } from "react-native"; import OpenFile from "react-native-doc-viewer"; var RNFS = require("react-native-fs"); var SavePath = Platform.OS === "ios" ? RNFS.MainBundlePath : RNFS.DocumentDirectoryPath; export default class Component02 extends Component { static navigationOptions = ({ navigation }) => ({ title: `${navigation.state.params.name}`, }); state = { animating: false } /* * Handle WWW File Method * fileType Default == "" you can use it, to set the File Extension (pdf,doc,xls,ppt etc) when in the Url the File Extension is missing. */ handlePress = () => { this.setState({ animating: true }); if (Platform.OS === "ios") { OpenFile.openDoc([{ url: "https://calibre-ebook.com/downloads/demos/demo.docx", fileNameOptional: "test filename" }], (error, url) => { if (error) { this.setState({ animating: false }); } else { this.setState({ animating: false }); console.log(url) } }) } else { //Android this.setState({ animating: true }); OpenFile.openDoc([{ url: "https://www.huf-haus.com/fileadmin/Bilder/Header/ART_3/Header_HUF_Haus_ART_3___1_.jpg", // Local "file://" + filepath fileName: "sample", cache: false, fileType: "jpg" }], (error, url) => { if (error) { this.setState({ animating: false }); console.error(error); } else { this.setState({ animating: false }); console.log(url) } }) } } /* * Handle Local File Method * fileType Default == "" you can use it, to set the File Extension (pdf,doc,xls,ppt etc) when in the Url the File Extension is missing. */ handlePressLocal = () => { this.setState({ animating: true }); if (Platform.OS === "ios") { OpenFile.openDoc([{ url: SavePath + "demo.docx", fileNameOptional: "test filename" }], (error, url) => { if (error) { this.setState({ animating: false }); } else { this.setState({ animating: false }); console.log(url) } }) } else { OpenFile.openDoc([{ url: SavePath + "demo.jpg", fileName: "sample", cache: false, fileType: "jpg" }], (error, url) => { if (error) { this.setState({ animating: false }); } else { this.setState({ animating: false }); console.log(url) } }) } } /* * Binary in URL * Binary String in Url * fileType Default == "" you can use it, to set the File Extension (pdf,doc,xls,ppt etc) when in the Url you dont have an File Extensions */ handlePressBinaryinUrl = () => { this.setState({ animating: true }); if (Platform.OS === "ios") { OpenFile.openDocBinaryinUrl([{ url: "https://storage.googleapis.com/need-sure/example", fileName: "sample", fileType: "xml" }], (error, url) => { if (error) { console.error(error); this.setState({ animating: false }); } else { console.log(url) this.setState({ animating: false }); } }) } else { OpenFile.openDocBinaryinUrl([{ url: "https://storage.googleapis.com/need-sure/example", fileName: "sample", fileType: "xml", cache: true }], (error, url) => { if (error) { console.error(error); this.setState({ animating: false }); } else { console.log(url) this.setState({ animating: false }); } }) } } /* * Base64String * put only the base64 String without data:application/octet-stream;base64 * fileType Default == "" you can use it, to set the File Extension (pdf,doc,xls,ppt etc) when in the Url you dont have an File Extensions */ handlePressb64 = () => { this.setState({ animating: true }); if (Platform.OS === "ios") { OpenFile.openDocb64([{ base64: "", fileName: "sample.png", fileType: "png" }], (error, url) => { if (error) { console.error(error); this.setState({ animating: false }); } else { console.log(url) this.setState({ animating: false }); } }) } else { OpenFile.openDocb64([{ base64: "", fileName: "sample", fileType: "png", cache: true }], (error, url) => { if (error) { console.error(error); this.setState({ animating: false }); } else { console.log(url) this.setState({ animating: false }); } }) } } /* * mp4 Video */ handlePressVideo(video) { this.setState({ animating: true }); if (Platform.OS === "ios") { OpenFile.playMovie(video, (error, url) => { if (error) { console.error(error); this.setState({ animating: false }); } else { console.log(url) this.setState({ animating: false }); } }) } else { this.setState({ animating: false }); Alert.alert("Coming soon for Android") } } setToggleTimeout() { this.setTimeout(() => { this.setState({ animating: !this.state.animating }); this.setToggleTimeout(); }, 2000); } render() { return (Screenshots 示例源碼); } } const styles = StyleSheet.create({ container: { flex: 1, justifyContent: "center", alignItems: "center", backgroundColor: "#F5FCFF", }, welcome: { fontSize: 20, textAlign: "center", margin: 10, }, instructions: { textAlign: "center", color: "#333333", marginBottom: 5, }, }); Doc Viewer React Native
GitHub - forrest23/ReactNativeComponents: React Native組件大全
組件地址GitHub - philipphecht/react-native-doc-viewer: React Native Doc Viewer (Supports file formats: xls,ppt,doc,xlsx,pptx,docx,png,jpg,pdf)
舉手之勞關(guān)注我的微信公眾號(hào):ReactNative開(kāi)發(fā)圈
文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請(qǐng)注明本文地址:http://m.specialneedsforspecialkids.com/yun/92045.html
摘要:寫(xiě)在前面一個(gè)好的缺不了好的三方支持,生活在這個(gè)活躍的開(kāi)源社區(qū),尋找合適的三方組件是一個(gè)開(kāi)發(fā)者最基本的能力。下面分享幾個(gè)我收集的三方模塊,希望對(duì)大家有點(diǎn)幫助。 寫(xiě)在前面 一個(gè)好的App缺不了好的三方支持,生活在ReactNative這個(gè)活躍的開(kāi)源社區(qū),尋找合適的三方組件是一個(gè)開(kāi)發(fā)者最基本的能力。不過(guò)不積跬步,無(wú)以至千里,不積小流,無(wú)以成江海。下面分享幾個(gè)我收集的三方模塊,希望對(duì)大家有點(diǎn)幫...
摘要:如果你想減少包大小,你可以這樣引入事實(shí)上,每個(gè)組件都是支持單獨(dú)安裝的,我們也推薦你使用這種方式引入組件。以下是運(yùn)行示例后各界面的截圖組件圖標(biāo)右上角的圓形徽標(biāo)數(shù)字。 1. 前言 一直以來(lái)都想做個(gè)組件庫(kù),一方面是對(duì)工作中常遇問(wèn)題的總結(jié),另一方面也確實(shí)能夠提升工作效率(誰(shuí)又不想造一個(gè)屬于自己的輪子呢~),于是乎就有了本文的主角兒rn-components-kit。 市面上web的UI組件庫(kù)如...
摘要:組件開(kāi)發(fā)利器對(duì)于前端開(kāi)發(fā)來(lái)說(shuō),組件化技術(shù)已經(jīng)是一門(mén)必修課了,這其中又主要以和為主。 react、vue 組件開(kāi)發(fā)利器:storybook 對(duì)于前端開(kāi)發(fā)來(lái)說(shuō),組件化技術(shù)已經(jīng)是一門(mén)必修課了,這其中又主要以 react 和 vue 為主。但平時(shí)在開(kāi)發(fā)組件,尤其是公共組件或者第三方組件庫(kù)的時(shí)候,往往會(huì)有一些困擾: 不能很好的管理多個(gè)組件,尤其是在組件預(yù)覽的時(shí)候,不能一目了然 在組件預(yù)覽的時(shí)候...
摘要:數(shù)據(jù)可視化庫(kù)超過(guò)的的可能是最流行和最廣泛的數(shù)據(jù)可視化庫(kù)。是一組組件,用于高效地渲染大型列表和表格數(shù)據(jù)。一種優(yōu)雅而靈活的方式,可以利用組件來(lái)支持實(shí)際的數(shù)據(jù)可視化。 想閱讀更多優(yōu)質(zhì)文章請(qǐng)猛戳GitHub博客,一年百來(lái)篇優(yōu)質(zhì)文章等著你! React Native 組件庫(kù) 1. NativeBase showImg(https://segmentfault.com/img/bVbrLHH?w=...
閱讀 3088·2021-09-22 15:20
閱讀 2608·2019-08-30 15:54
閱讀 1973·2019-08-30 14:06
閱讀 3122·2019-08-30 13:05
閱讀 2467·2019-08-29 18:36
閱讀 578·2019-08-29 15:10
閱讀 533·2019-08-29 11:17
閱讀 830·2019-08-28 18:11