forked from wangfpp/react-native-file-selector
-
Notifications
You must be signed in to change notification settings - Fork 1
/
RNFileSelector.js
96 lines (81 loc) · 2.4 KB
/
RNFileSelector.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import React, { PureComponent } from "react";
import { ViewPropTypes, NativeModules, Platform } from "react-native";
import PropTypes from "prop-types";
const { RNFileSelector } = NativeModules;
class FileSelector extends PureComponent {
static propTypes = {
...ViewPropTypes,
filter: PropTypes.string,
filterDirectories: PropTypes.bool,
path: PropTypes.string,
hiddenFiles: PropTypes.bool,
closeMenu: PropTypes.bool,
title: PropTypes.string,
onDone: PropTypes.func,
onCancel: PropTypes.func,
editable: PropTypes.bool
};
static defaultProps = {
visible: false,
filterDirectories: false,
path: '',
hiddenFiles: false,
closeMenu: true,
title: '',
editable: false
};
static Show(props) {
if (props.filter === undefined) {
props.filter = FileSelector.defaultProps.filter
} if (props.filterDirectories === undefined) {
props.filterDirectories = FileSelector.defaultProps.filterDirectories
} if (props.path === undefined) {
props.path = FileSelector.defaultProps.path;
} if (props.hiddenFiles === undefined) {
props.hiddenFiles = FileSelector.defaultProps.hiddenFiles
} if (props.closeMenu === undefined) {
props.closeMenu = FileSelector.defaultProps.closeMenu
} if (props.title === undefined) {
props.title = FileSelector.defaultProps.title
} if (props.editable === undefined) {
props.editable = FileSelector.defaultProps.editable
}
if (props.filter === undefined) {
if (Platform.OS === 'ios') {
props.filter = []
} else if (Platform.OS === 'android') {
props.filter = ''
}
}
RNFileSelector.Show(props, path => {
props.onDone && props.onDone(path)
}, () => {
props.onCancel && props.onCancel()
});
}
componentDidMount() {
this._show();
}
componentDidUpdate() {
this._show();
}
_show() {
if (this.props.visible) {
FileSelector.Show({
filter: this.props.filter,
filterDirectories: this.props.filterDirectories,
path: this.props.path,
hiddenFiles: this.props.hiddenFiles,
closeMenu: this.props.closeMenu,
title: this.props.title,
editable: this.props.editable,
onDone: this.props.onDone,
onCancel: this.props.onCancel
});
}
}
render() {
return null;
}
}
export default FileSelector;