@codeleap/mobile 3.12.19 → 3.12.20

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codeleap/mobile",
3
- "version": "3.12.19",
3
+ "version": "3.12.20",
4
4
  "main": "src/index.ts",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {
@@ -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
- onUpdate(() => {
31
+ onMount(() => {
32
32
 
33
- const subscription = AppState.addEventListener('change', (appState) => {
34
- if (appState === 'active') {
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
- return () => {
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> = Record<T, PermissionTypes.PermissionStatus> & {
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 | number | symbol> = {
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
- 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
- }
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: UsePermissions<any> = () => {
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: any) => any,
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: Parameters<typeof onResolve>[0] = {
187
+ const res:Parameters<typeof onResolve>[0] = {
192
188
  ...results,
193
189
  overall: Object.values(results).every(x => x === 'granted') ? 'granted' : 'denied',
194
190
  }