@codeleap/mobile 3.10.1 → 3.10.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -41,10 +41,10 @@ const pickerDefaults = {
|
|
|
41
41
|
cropping: true,
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
function parsePickerData(data:ImageOrVideo):FileResult {
|
|
44
|
+
function parsePickerData(data: ImageOrVideo): FileResult {
|
|
45
45
|
|
|
46
46
|
const filePathData = parseFilePathData(data.path)
|
|
47
|
-
const d:MobileFile = {
|
|
47
|
+
const d: MobileFile = {
|
|
48
48
|
...data,
|
|
49
49
|
name: filePathData.name,
|
|
50
50
|
size: data.size,
|
|
@@ -78,22 +78,27 @@ const _FileInput = forwardRef<
|
|
|
78
78
|
onOpenFileSystem = null,
|
|
79
79
|
onError,
|
|
80
80
|
} = fileInputProps
|
|
81
|
-
const resolveWithFile = useRef<(file:FileResult[]) => any>()
|
|
81
|
+
const resolveWithFile = useRef<(file: FileResult[]) => any>()
|
|
82
82
|
const { logger } = useCodeleapContext()
|
|
83
83
|
|
|
84
|
+
const resolveFiles = (files) => {
|
|
85
|
+
if (resolveWithFile.current) {
|
|
86
|
+
resolveWithFile.current(files ?? [])
|
|
87
|
+
resolveWithFile.current = undefined
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
84
91
|
async function openFileSystem() {
|
|
85
92
|
try {
|
|
86
93
|
let files = await DocumentPicker.pick(options)
|
|
94
|
+
|
|
87
95
|
if (!Array.isArray(files)) {
|
|
88
96
|
files = [files]
|
|
89
97
|
}
|
|
90
98
|
|
|
91
99
|
const filesWithPreview = files.map((file) => ({ preview: file.uri, file }))
|
|
92
100
|
|
|
93
|
-
|
|
94
|
-
resolveWithFile.current(filesWithPreview)
|
|
95
|
-
resolveWithFile.current = undefined
|
|
96
|
-
}
|
|
101
|
+
resolveFiles(filesWithPreview)
|
|
97
102
|
onFileSelect?.(filesWithPreview)
|
|
98
103
|
} catch (err) {
|
|
99
104
|
handleError(err)
|
|
@@ -113,13 +118,17 @@ const _FileInput = forwardRef<
|
|
|
113
118
|
} as Options
|
|
114
119
|
|
|
115
120
|
const handlePickerResolution = (data: ImageOrVideo | ImageOrVideo[]) => {
|
|
116
|
-
let imageArray:ImageOrVideo[] = []
|
|
121
|
+
let imageArray: ImageOrVideo[] = []
|
|
117
122
|
if (!Array.isArray(data)) {
|
|
118
123
|
imageArray = [data]
|
|
119
124
|
} else {
|
|
120
125
|
imageArray = data
|
|
121
126
|
}
|
|
122
|
-
|
|
127
|
+
const images = imageArray.map(parsePickerData)
|
|
128
|
+
|
|
129
|
+
resolveFiles(images)
|
|
130
|
+
|
|
131
|
+
onFileSelect?.(images)
|
|
123
132
|
}
|
|
124
133
|
const onPress = (open?: FileInputImageSource, options?: Options) => {
|
|
125
134
|
if (open == 'fs') {
|
|
@@ -166,7 +175,7 @@ const _FileInput = forwardRef<
|
|
|
166
175
|
{
|
|
167
176
|
text: 'Cancel',
|
|
168
177
|
style: 'cancel',
|
|
169
|
-
onPress: () => {},
|
|
178
|
+
onPress: () => { },
|
|
170
179
|
...alertProps?.options?.[0],
|
|
171
180
|
},
|
|
172
181
|
],
|
|
@@ -200,7 +209,7 @@ export const FileInput = _FileInput as unknown as ((props: FileInputProps) => JS
|
|
|
200
209
|
export const useFileInput = () => {
|
|
201
210
|
const inputRef = useRef<FileInputRef>(null)
|
|
202
211
|
|
|
203
|
-
const openFilePicker = (imageSource:FileInputImageSource = null):Promise<FileResult[]> => {
|
|
212
|
+
const openFilePicker = (imageSource: FileInputImageSource = null): Promise<FileResult[]> => {
|
|
204
213
|
return inputRef.current?.openFilePicker(imageSource)
|
|
205
214
|
}
|
|
206
215
|
|