@codeleap/mobile 3.10.7 → 3.11.1
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,9 +78,17 @@ 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 handleResolve = (files: Array<FileResult>) => {
|
|
85
|
+
if (resolveWithFile.current) {
|
|
86
|
+
resolveWithFile?.current?.(files)
|
|
87
|
+
resolveWithFile.current = null
|
|
88
|
+
}
|
|
89
|
+
onFileSelect?.(files)
|
|
90
|
+
}
|
|
91
|
+
|
|
84
92
|
async function openFileSystem() {
|
|
85
93
|
try {
|
|
86
94
|
let files = await DocumentPicker.pick(options)
|
|
@@ -88,13 +96,9 @@ const _FileInput = forwardRef<
|
|
|
88
96
|
files = [files]
|
|
89
97
|
}
|
|
90
98
|
|
|
91
|
-
const filesWithPreview = files.map((file) => ({ preview: file.uri, file }))
|
|
99
|
+
const filesWithPreview = files.map((file) => ({ preview: file.uri, file })) as FileResult[]
|
|
92
100
|
|
|
93
|
-
|
|
94
|
-
resolveWithFile.current(filesWithPreview)
|
|
95
|
-
resolveWithFile.current = undefined
|
|
96
|
-
}
|
|
97
|
-
onFileSelect?.(filesWithPreview)
|
|
101
|
+
handleResolve?.(filesWithPreview)
|
|
98
102
|
} catch (err) {
|
|
99
103
|
handleError(err)
|
|
100
104
|
}
|
|
@@ -113,13 +117,13 @@ const _FileInput = forwardRef<
|
|
|
113
117
|
} as Options
|
|
114
118
|
|
|
115
119
|
const handlePickerResolution = (data: ImageOrVideo | ImageOrVideo[]) => {
|
|
116
|
-
let imageArray:ImageOrVideo[] = []
|
|
120
|
+
let imageArray: ImageOrVideo[] = []
|
|
117
121
|
if (!Array.isArray(data)) {
|
|
118
122
|
imageArray = [data]
|
|
119
123
|
} else {
|
|
120
124
|
imageArray = data
|
|
121
125
|
}
|
|
122
|
-
|
|
126
|
+
handleResolve?.(imageArray.map(parsePickerData))
|
|
123
127
|
}
|
|
124
128
|
const onPress = (open?: FileInputImageSource, options?: Options) => {
|
|
125
129
|
if (open == 'fs') {
|
|
@@ -166,7 +170,7 @@ const _FileInput = forwardRef<
|
|
|
166
170
|
{
|
|
167
171
|
text: 'Cancel',
|
|
168
172
|
style: 'cancel',
|
|
169
|
-
onPress: () => {},
|
|
173
|
+
onPress: () => { },
|
|
170
174
|
...alertProps?.options?.[0],
|
|
171
175
|
},
|
|
172
176
|
],
|
|
@@ -200,7 +204,7 @@ export const FileInput = _FileInput as unknown as ((props: FileInputProps) => JS
|
|
|
200
204
|
export const useFileInput = () => {
|
|
201
205
|
const inputRef = useRef<FileInputRef>(null)
|
|
202
206
|
|
|
203
|
-
const openFilePicker = (imageSource:FileInputImageSource = null):Promise<FileResult[]> => {
|
|
207
|
+
const openFilePicker = (imageSource: FileInputImageSource = null): Promise<FileResult[]> => {
|
|
204
208
|
return inputRef.current?.openFilePicker(imageSource)
|
|
205
209
|
}
|
|
206
210
|
|
|
@@ -24,14 +24,14 @@ function getStatuses(state: PermissionsRecord) {
|
|
|
24
24
|
return Object.fromEntries(statuses)
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
export function Provider({ children, AppPermissions, modalConfig }:PermissionProviderProps) {
|
|
27
|
+
export function Provider({ children, AppPermissions, modalConfig }: PermissionProviderProps) {
|
|
28
28
|
|
|
29
29
|
const [state, setState] = useState(() => getStatuses(AppPermissions.values))
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
onUpdate(() => {
|
|
32
32
|
|
|
33
|
-
AppState.addEventListener('change', (
|
|
34
|
-
if (
|
|
33
|
+
const subscription = AppState.addEventListener('change', (appState) => {
|
|
34
|
+
if (appState === 'active') {
|
|
35
35
|
AppPermissions.update().then((vals) => {
|
|
36
36
|
const statuses = getStatuses(vals)
|
|
37
37
|
if (!deepEqual(statuses, state)) {
|
|
@@ -41,49 +41,53 @@ export function Provider({ children, AppPermissions, modalConfig }:PermissionPro
|
|
|
41
41
|
}
|
|
42
42
|
})
|
|
43
43
|
|
|
44
|
-
|
|
44
|
+
return () => {
|
|
45
|
+
subscription.remove()
|
|
46
|
+
}
|
|
47
|
+
}, [
|
|
48
|
+
JSON.stringify(state),
|
|
49
|
+
])
|
|
45
50
|
|
|
46
51
|
const setPermissionState = (forPermission: string, status: PermissionTypes.PermissionState) => {
|
|
47
52
|
setState({
|
|
48
53
|
...state,
|
|
49
|
-
[forPermission]: status
|
|
54
|
+
[forPermission]: status,
|
|
50
55
|
})
|
|
51
|
-
}
|
|
52
|
-
|
|
56
|
+
}
|
|
53
57
|
|
|
54
58
|
return <PermissionContext.Provider value={{
|
|
55
59
|
state,
|
|
56
60
|
modalConfig: modalConfig,
|
|
57
61
|
manager: AppPermissions,
|
|
58
|
-
setState: setPermissionState
|
|
62
|
+
setState: setPermissionState,
|
|
59
63
|
}}>
|
|
60
64
|
{children}
|
|
61
65
|
</PermissionContext.Provider>
|
|
62
66
|
}
|
|
63
67
|
|
|
64
|
-
type TAskManyResults<T extends string> =Record<T, PermissionTypes.PermissionStatus> & {
|
|
68
|
+
type TAskManyResults<T extends string> = Record<T, PermissionTypes.PermissionStatus> & {
|
|
65
69
|
overall
|
|
66
70
|
: PermissionTypes.PermissionStatus
|
|
67
71
|
}
|
|
68
72
|
|
|
69
|
-
type AskManyOpts<T extends string|number|symbol
|
|
73
|
+
type AskManyOpts<T extends string | number | symbol> = {
|
|
70
74
|
breakOnDenied?: T[]
|
|
71
75
|
}
|
|
72
76
|
|
|
73
77
|
export type UsePermissions<
|
|
74
78
|
_PermissionNames extends string,
|
|
75
79
|
PermissionNames extends string = `${_PermissionNames}?` | _PermissionNames> = () => TPermissionContext & {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}
|
|
80
|
+
askPermission: (name: PermissionNames, onResolve?: (status: PermissionTypes.PermissionStatus) => any) => Promise<PermissionTypes.PermissionStatus>
|
|
81
|
+
askMany<T extends PermissionNames, R = TAskManyResults<T>>(
|
|
82
|
+
perms: T[],
|
|
83
|
+
onResolve?: (res: R) => any,
|
|
84
|
+
options?: AskManyOpts<T>
|
|
85
|
+
): Promise<
|
|
86
|
+
R
|
|
87
|
+
>
|
|
88
|
+
}
|
|
85
89
|
|
|
86
|
-
export const usePermissions:UsePermissions<any> = () => {
|
|
90
|
+
export const usePermissions: UsePermissions<any> = () => {
|
|
87
91
|
const modalCtx = useModalContext()
|
|
88
92
|
const permissionCtx = useContext(PermissionContext)
|
|
89
93
|
|
|
@@ -120,7 +124,7 @@ export const usePermissions:UsePermissions<any> = () => {
|
|
|
120
124
|
|
|
121
125
|
const askMany = async (
|
|
122
126
|
perms: any[],
|
|
123
|
-
onResolve?: (res:any) => any,
|
|
127
|
+
onResolve?: (res: any) => any,
|
|
124
128
|
options?: AskManyOpts<any>,
|
|
125
129
|
) => {
|
|
126
130
|
|
|
@@ -184,7 +188,7 @@ export const usePermissions:UsePermissions<any> = () => {
|
|
|
184
188
|
modalCtx.toggleModal(prevModal, false, {})
|
|
185
189
|
})
|
|
186
190
|
}
|
|
187
|
-
const res:Parameters<typeof onResolve>[0] = {
|
|
191
|
+
const res: Parameters<typeof onResolve>[0] = {
|
|
188
192
|
...results,
|
|
189
193
|
overall: Object.values(results).every(x => x === 'granted') ? 'granted' : 'denied',
|
|
190
194
|
}
|