加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

React Native File选择器

发布时间:2020-12-15 05:07:52 所属栏目:百科 来源:网络整理
导读:这是麻烦:我已经搜索了高低,我不能在我的生活中找到如何在React Native中显示文件选择器对话框.最接近的是图像选择器(第三方组件),但它是一个专门的界面,不允许我从 Android的文件系统中挑选任意文件. 有人知道,我怎么选择文件? 我正在使用这个包 react-na
这是麻烦:我已经搜索了高低,我不能在我的生活中找到如何在React Native中显示文件选择器对话框.最接近的是图像选择器(第三方组件),但它是一个专门的界面,不允许我从 Android的文件系统中挑选任意文件.
有人知道,我怎么选择文件?
我正在使用这个包 react-native-file-picker

>从github安装包

npm install https://github.com/Lichwa/react-native-file-picker –save
>然后链接它:

rnpm link react-native-file-picker
>导入包

var FilePickerManager = require(‘NativeModules’).FilePickerManager;
>然后像这样使用它:

const options = {
    title: 'File Picker',chooseFileButtonTitle: 'Choose File...'
};

FilePickerManager.showFilePicker(options,(response) => {
    console.log('Response = ',response);

    if (response.didCancel) {
        console.log('User cancelled photo picker');
    }
    else if (response.error) {
        console.log('ImagePickerManager Error: ',response.error);
    }
    else if (response.customButton) {
        console.log('User tapped custom button: ',response.customButton);
    }
    else {
        this.setState({
            file: response
        });
    }
});

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读