@codeleap/mobile 3.12.18 → 3.12.19

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.18",
3
+ "version": "3.12.19",
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
- onMount(() => {
31
+ onUpdate(() => {
32
32
 
33
- AppState.addEventListener('change', (state) => {
34
- if (state === 'active') {
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
- 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
- }
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
  }