@codeleap/mobile 3.11.1 → 3.12.0
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
|
@@ -42,12 +42,15 @@ const OuterInput:ValueBoundSelectProps<any, boolean>['outerInputComponent'] = (p
|
|
|
42
42
|
styles,
|
|
43
43
|
style,
|
|
44
44
|
placeholder,
|
|
45
|
+
disabled = false,
|
|
45
46
|
} = props
|
|
46
47
|
|
|
48
|
+
|
|
47
49
|
return <TextInput
|
|
48
50
|
value={TypeGuards.isString(currentValueLabel) ? currentValueLabel : null}
|
|
49
51
|
rightIcon={clearIcon}
|
|
50
|
-
onPress={() => toggle()}
|
|
52
|
+
onPress={disabled ? null : () => toggle()}
|
|
53
|
+
disabled={disabled}
|
|
51
54
|
label={label}
|
|
52
55
|
debugName={debugName}
|
|
53
56
|
styles={styles}
|
|
@@ -120,6 +123,7 @@ export const Select = <T extends string|number = string, Multi extends boolean =
|
|
|
120
123
|
getLabel,
|
|
121
124
|
searchInputProps,
|
|
122
125
|
outerInputComponent,
|
|
126
|
+
disabled = false,
|
|
123
127
|
...modalProps
|
|
124
128
|
} = allProps
|
|
125
129
|
|
|
@@ -314,7 +318,7 @@ export const Select = <T extends string|number = string, Multi extends boolean =
|
|
|
314
318
|
|
|
315
319
|
clearIcon={{
|
|
316
320
|
icon: inputIcon as IconPlaceholder,
|
|
317
|
-
onPress: onPressInputIcon,
|
|
321
|
+
onPress: disabled ? null : onPressInputIcon,
|
|
318
322
|
}}
|
|
319
323
|
|
|
320
324
|
currentValueLabel={currentValueLabel}
|
|
@@ -59,6 +59,7 @@ export type ValueBoundSelectProps<
|
|
|
59
59
|
getLabel?: (forOption: Multi extends true ? FormTypes.Options<T> : FormTypes.Options<T>[number]) => FormTypes.Label
|
|
60
60
|
outerInputComponent?: OuterInputComponent<T, Multi>
|
|
61
61
|
inputProps?: Partial<SelectOuterInputProps<T, Multi>>
|
|
62
|
+
disabled?: boolean
|
|
62
63
|
}
|
|
63
64
|
|
|
64
65
|
export type ReplaceSelectProps<Props, T, Multi extends boolean = false> = Omit<
|
|
@@ -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 }:
|
|
27
|
+
export function Provider({ children, AppPermissions, modalConfig }:PermissionProviderProps) {
|
|
28
28
|
|
|
29
29
|
const [state, setState] = useState(() => getStatuses(AppPermissions.values))
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
onMount(() => {
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
if (
|
|
33
|
+
AppState.addEventListener('change', (state) => {
|
|
34
|
+
if (state === 'active') {
|
|
35
35
|
AppPermissions.update().then((vals) => {
|
|
36
36
|
const statuses = getStatuses(vals)
|
|
37
37
|
if (!deepEqual(statuses, state)) {
|
|
@@ -41,53 +41,49 @@ export function Provider({ children, AppPermissions, modalConfig }: PermissionPr
|
|
|
41
41
|
}
|
|
42
42
|
})
|
|
43
43
|
|
|
44
|
-
|
|
45
|
-
subscription.remove()
|
|
46
|
-
}
|
|
47
|
-
}, [
|
|
48
|
-
JSON.stringify(state),
|
|
49
|
-
])
|
|
44
|
+
})
|
|
50
45
|
|
|
51
46
|
const setPermissionState = (forPermission: string, status: PermissionTypes.PermissionState) => {
|
|
52
47
|
setState({
|
|
53
48
|
...state,
|
|
54
|
-
[forPermission]: status
|
|
49
|
+
[forPermission]: status
|
|
55
50
|
})
|
|
56
|
-
}
|
|
51
|
+
}
|
|
52
|
+
|
|
57
53
|
|
|
58
54
|
return <PermissionContext.Provider value={{
|
|
59
55
|
state,
|
|
60
56
|
modalConfig: modalConfig,
|
|
61
57
|
manager: AppPermissions,
|
|
62
|
-
setState: setPermissionState
|
|
58
|
+
setState: setPermissionState
|
|
63
59
|
}}>
|
|
64
60
|
{children}
|
|
65
61
|
</PermissionContext.Provider>
|
|
66
62
|
}
|
|
67
63
|
|
|
68
|
-
type TAskManyResults<T extends string> =
|
|
64
|
+
type TAskManyResults<T extends string> =Record<T, PermissionTypes.PermissionStatus> & {
|
|
69
65
|
overall
|
|
70
66
|
: PermissionTypes.PermissionStatus
|
|
71
67
|
}
|
|
72
68
|
|
|
73
|
-
type AskManyOpts<T extends string
|
|
69
|
+
type AskManyOpts<T extends string|number|symbol > = {
|
|
74
70
|
breakOnDenied?: T[]
|
|
75
71
|
}
|
|
76
72
|
|
|
77
73
|
export type UsePermissions<
|
|
78
74
|
_PermissionNames extends string,
|
|
79
75
|
PermissionNames extends string = `${_PermissionNames}?` | _PermissionNames> = () => TPermissionContext & {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
76
|
+
askPermission: (name: PermissionNames, onResolve?: (status: PermissionTypes.PermissionStatus) => any) => Promise<PermissionTypes.PermissionStatus>
|
|
77
|
+
askMany<T extends PermissionNames, R = TAskManyResults<T>>(
|
|
78
|
+
perms: T[],
|
|
79
|
+
onResolve?: (res:R) => any,
|
|
80
|
+
options?: AskManyOpts<T>
|
|
81
|
+
):Promise<
|
|
82
|
+
R
|
|
83
|
+
>
|
|
84
|
+
}
|
|
89
85
|
|
|
90
|
-
export const usePermissions:
|
|
86
|
+
export const usePermissions:UsePermissions<any> = () => {
|
|
91
87
|
const modalCtx = useModalContext()
|
|
92
88
|
const permissionCtx = useContext(PermissionContext)
|
|
93
89
|
|
|
@@ -124,7 +120,7 @@ export const usePermissions: UsePermissions<any> = () => {
|
|
|
124
120
|
|
|
125
121
|
const askMany = async (
|
|
126
122
|
perms: any[],
|
|
127
|
-
onResolve?: (res:
|
|
123
|
+
onResolve?: (res:any) => any,
|
|
128
124
|
options?: AskManyOpts<any>,
|
|
129
125
|
) => {
|
|
130
126
|
|
|
@@ -188,7 +184,7 @@ export const usePermissions: UsePermissions<any> = () => {
|
|
|
188
184
|
modalCtx.toggleModal(prevModal, false, {})
|
|
189
185
|
})
|
|
190
186
|
}
|
|
191
|
-
const res:
|
|
187
|
+
const res:Parameters<typeof onResolve>[0] = {
|
|
192
188
|
...results,
|
|
193
189
|
overall: Object.values(results).every(x => x === 'granted') ? 'granted' : 'denied',
|
|
194
190
|
}
|