1.0.1 • Published 6 years ago
react-native-viewfile v1.0.1
react-native-view-file
建议与react-native-fs结合着使用。
安装:
下载依赖:
yarn add react-native-fs react-native-viewfile
链接:
react-native link react-native-fs react-native-viewfile
简单例子:
import { viewFile } from 'react-native-viewfile';
const filePath = '手机本地文件路径';
viewFile(filePath, 'doc', '测试文档的标题.doc');
与react-native-fs
在一起使用的例子:
import { Platform } from 'react-native';
import { viewFile } from 'react-native-viewfile';
import { ExternalDirectoryPath, CachesDirectoryPath, downloadFile } from 'react-native-fs';
const filePath = `${Platform.OS === 'android' ? ExternalDirectoryPath : CachesDirectoryPath}/test.docx`;
const { promise, jobId } = downloadFile({
fromUrl: 'http://xxxxxx',
toFile: filePath,
});
promise.then(({statusCode}) => {
if (statusCode < 500 && statusCode >= 200) {
viewFile(filePath, 'apk', '文档.apk');
}
});