【发布时间】:2021-03-15 10:26:29
【问题描述】:
有没有办法在 react native 中显示或预览上传的文件(png、doc、pdf)? 我已经编写了要上传的代码并且它正在工作,但我想显示该文件。有人知道吗? 我正在使用 Expo 和 TypeScript 的原生反应
【问题讨论】:
标签: typescript react-native expo
有没有办法在 react native 中显示或预览上传的文件(png、doc、pdf)? 我已经编写了要上传的代码并且它正在工作,但我想显示该文件。有人知道吗? 我正在使用 Expo 和 TypeScript 的原生反应
【问题讨论】:
标签: typescript react-native expo
尝试使用react-native-pdf 存储库
import React from 'react';
import { StyleSheet, Dimensions, View } from 'react-native';
import Pdf from 'react-native-pdf';
export default class PDFExample extends React.Component {
render() {
const source = {uri:'http://samples.leanpub.com/thereactnativebook-sample.pdf',cache:true};
//const source = require('./test.pdf'); // ios only
//const source = {uri:'bundle-assets://test.pdf'};
//const source = {uri:'file:///sdcard/test.pdf'};
//const source = {uri:"data:application/pdf;base64,JVBERi0xLjcKJc..."};
return (
<View style={styles.container}>
<Pdf
source={source}
onLoadComplete={(numberOfPages,filePath)=>{
console.log(`number of pages: ${numberOfPages}`);
}}
onPageChanged={(page,numberOfPages)=>{
console.log(`current page: ${page}`);
}}
onError={(error)=>{
console.log(error);
}}
onPressLink={(uri)=>{
console.log(`Link presse: ${uri}`)
}}
style={styles.pdf}/>
</View>
)
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'flex-start',
alignItems: 'center',
marginTop: 25,
},
pdf: {
flex:1,
width:Dimensions.get('window').width,
height:Dimensions.get('window').height,
}
});
【讨论】: