@codeleap/mobile 5.0.7 → 5.0.8

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.
Files changed (79) hide show
  1. package/dist/components/DatePickerModal/index.js +1 -3
  2. package/dist/components/DatePickerModal/index.js.map +1 -1
  3. package/dist/components/DatePickerModal/types.d.ts +1 -0
  4. package/dist/components/InputBase/useInputBase.js +2 -9
  5. package/dist/components/InputBase/useInputBase.js.map +1 -1
  6. package/dist/components/NumberIncrement/index.js +4 -2
  7. package/dist/components/NumberIncrement/index.js.map +1 -1
  8. package/dist/components/NumberIncrement/useNumberIncrement.js +13 -13
  9. package/dist/components/NumberIncrement/useNumberIncrement.js.map +1 -1
  10. package/dist/components/TextInput/index.js +2 -2
  11. package/dist/components/TextInput/index.js.map +1 -1
  12. package/dist/deprecated/index.d.ts +1 -0
  13. package/dist/deprecated/index.js +3 -0
  14. package/dist/deprecated/index.js.map +1 -0
  15. package/dist/{utils/PermissionManager/context.d.ts → deprecated/permissions/Context.d.ts} +2 -2
  16. package/dist/{utils/PermissionManager/context.js → deprecated/permissions/Context.js} +2 -2
  17. package/dist/deprecated/permissions/Context.js.map +1 -0
  18. package/dist/{utils/PermissionManager → deprecated/permissions}/index.d.ts +2 -1
  19. package/dist/{utils/PermissionManager → deprecated/permissions}/index.js +2 -1
  20. package/dist/deprecated/permissions/index.js.map +1 -0
  21. package/dist/{utils/MobilePermissionManager/PermissionManager.js → deprecated/permissions/package/Manager.js} +1 -1
  22. package/dist/deprecated/permissions/package/Manager.js.map +1 -0
  23. package/dist/deprecated/permissions/package/Permission.js.map +1 -0
  24. package/dist/{utils/MobilePermissionManager → deprecated/permissions/package}/index.d.ts +1 -1
  25. package/dist/{utils/MobilePermissionManager → deprecated/permissions/package}/index.js +1 -1
  26. package/dist/deprecated/permissions/package/index.js.map +1 -0
  27. package/dist/deprecated/permissions/package/types.js.map +1 -0
  28. package/dist/{utils/PermissionManager → deprecated/permissions}/types.d.ts +1 -1
  29. package/dist/deprecated/permissions/types.js.map +1 -0
  30. package/dist/hooks/index.d.ts +1 -0
  31. package/dist/hooks/index.js +1 -0
  32. package/dist/hooks/index.js.map +1 -1
  33. package/dist/hooks/useAppState.d.ts +4 -0
  34. package/dist/hooks/useAppState.js +16 -0
  35. package/dist/hooks/useAppState.js.map +1 -0
  36. package/dist/index.d.ts +1 -0
  37. package/dist/index.js +1 -0
  38. package/dist/index.js.map +1 -1
  39. package/dist/utils/hooks.d.ts +1 -4
  40. package/dist/utils/hooks.js +2 -15
  41. package/dist/utils/hooks.js.map +1 -1
  42. package/dist/utils/index.d.ts +0 -3
  43. package/dist/utils/index.js +0 -3
  44. package/dist/utils/index.js.map +1 -1
  45. package/package.json +15 -17
  46. package/package.json.bak +1 -3
  47. package/src/components/DatePickerModal/index.tsx +1 -2
  48. package/src/components/DatePickerModal/types.ts +1 -0
  49. package/src/components/InputBase/useInputBase.ts +3 -9
  50. package/src/components/NumberIncrement/index.tsx +5 -3
  51. package/src/components/NumberIncrement/useNumberIncrement.ts +15 -15
  52. package/src/components/TextInput/index.tsx +2 -2
  53. package/src/deprecated/index.ts +1 -0
  54. package/src/{utils/PermissionManager/context.tsx → deprecated/permissions/Context.tsx} +19 -19
  55. package/src/{utils/PermissionManager → deprecated/permissions}/index.ts +4 -8
  56. package/src/{utils/MobilePermissionManager/PermissionManager.ts → deprecated/permissions/package/Manager.ts} +11 -11
  57. package/src/{utils/MobilePermissionManager → deprecated/permissions/package}/Permission.ts +4 -4
  58. package/src/{utils/MobilePermissionManager → deprecated/permissions/package}/index.ts +1 -1
  59. package/src/{utils/MobilePermissionManager → deprecated/permissions/package}/types.ts +12 -12
  60. package/src/deprecated/permissions/types.ts +27 -0
  61. package/src/hooks/index.ts +2 -1
  62. package/src/hooks/useAppState.ts +23 -0
  63. package/src/index.ts +1 -0
  64. package/src/utils/hooks.ts +2 -18
  65. package/src/utils/index.ts +1 -6
  66. package/dist/utils/MobilePermissionManager/Permission.js.map +0 -1
  67. package/dist/utils/MobilePermissionManager/PermissionManager.js.map +0 -1
  68. package/dist/utils/MobilePermissionManager/index.js.map +0 -1
  69. package/dist/utils/MobilePermissionManager/types.js.map +0 -1
  70. package/dist/utils/PermissionManager/context.js.map +0 -1
  71. package/dist/utils/PermissionManager/index.js.map +0 -1
  72. package/dist/utils/PermissionManager/types.js.map +0 -1
  73. package/src/utils/PermissionManager/types.ts +0 -27
  74. /package/dist/{utils/MobilePermissionManager/PermissionManager.d.ts → deprecated/permissions/package/Manager.d.ts} +0 -0
  75. /package/dist/{utils/MobilePermissionManager → deprecated/permissions/package}/Permission.d.ts +0 -0
  76. /package/dist/{utils/MobilePermissionManager → deprecated/permissions/package}/Permission.js +0 -0
  77. /package/dist/{utils/MobilePermissionManager → deprecated/permissions/package}/types.d.ts +0 -0
  78. /package/dist/{utils/MobilePermissionManager → deprecated/permissions/package}/types.js +0 -0
  79. /package/dist/{utils/PermissionManager → deprecated/permissions}/types.js +0 -0
@@ -3,8 +3,6 @@ export * from './hooks';
3
3
  export * from './misc';
4
4
  export * from './NotificationManager';
5
5
  export * from './ModalManager';
6
- import * as Permissions from './PermissionManager';
7
- export { Permissions };
8
6
  export * from './KeyboardAware';
9
7
  export * from './input';
10
8
  export * from './theme';
@@ -12,5 +10,4 @@ export * from './locale';
12
10
  export * from './Subscription';
13
11
  export * from './useQueryListRefresh';
14
12
  export * from './StorageManager';
15
- export * from './MobilePermissionManager';
16
13
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,SAAS,CAAA;AACvB,cAAc,QAAQ,CAAA;AACtB,cAAc,uBAAuB,CAAA;AACrC,cAAc,gBAAgB,CAAA;AAC9B,OAAO,KAAK,WAAW,MAAM,qBAAqB,CAAA;AAElD,OAAO,EAAE,WAAW,EAAE,CAAA;AACtB,cAAc,iBAAiB,CAAA;AAC/B,cAAc,SAAS,CAAA;AACvB,cAAc,SAAS,CAAA;AACvB,cAAc,UAAU,CAAA;AACxB,cAAc,gBAAgB,CAAA;AAC9B,cAAc,uBAAuB,CAAA;AAErC,cAAc,kBAAkB,CAAA;AAChC,cAAc,2BAA2B,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,SAAS,CAAA;AACvB,cAAc,QAAQ,CAAA;AACtB,cAAc,uBAAuB,CAAA;AACrC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,SAAS,CAAA;AACvB,cAAc,SAAS,CAAA;AACvB,cAAc,UAAU,CAAA;AACxB,cAAc,gBAAgB,CAAA;AAC9B,cAAc,uBAAuB,CAAA;AACrC,cAAc,kBAAkB,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codeleap/mobile",
3
- "version": "5.0.7",
3
+ "version": "5.0.8",
4
4
  "main": "src/index.ts",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {
@@ -9,28 +9,26 @@
9
9
  "directory": "packages/mobile"
10
10
  },
11
11
  "devDependencies": {
12
- "@codeleap/types": "5.0.7",
13
- "@codeleap/utils": "5.0.7",
14
- "@codeleap/hooks": "5.0.7",
15
- "@codeleap/form": "5.0.7",
16
- "@codeleap/i18n": "5.0.7",
17
- "@codeleap/query": "5.0.7",
18
- "@codeleap/logger": "5.0.7",
19
- "@codeleap/config": "5.0.7"
12
+ "@codeleap/types": "5.0.8",
13
+ "@codeleap/utils": "5.0.8",
14
+ "@codeleap/hooks": "5.0.8",
15
+ "@codeleap/form": "5.0.8",
16
+ "@codeleap/query": "5.0.8",
17
+ "@codeleap/logger": "5.0.8",
18
+ "@codeleap/config": "5.0.8"
20
19
  },
21
20
  "scripts": {
22
21
  "build": "tsc --build",
23
22
  "lint": "eslint -c .eslintrc.js --fix \"./src/**/*.{ts,tsx,js,jsx}\""
24
23
  },
25
24
  "peerDependencies": {
26
- "@codeleap/types": "5.0.7",
27
- "@codeleap/utils": "5.0.7",
28
- "@codeleap/hooks": "5.0.7",
29
- "@codeleap/form": "5.0.7",
30
- "@codeleap/i18n": "5.0.7",
31
- "@codeleap/query": "5.0.7",
32
- "@codeleap/logger": "5.0.7",
33
- "@codeleap/styles": "5.0.7",
25
+ "@codeleap/types": "5.0.8",
26
+ "@codeleap/utils": "5.0.8",
27
+ "@codeleap/hooks": "5.0.8",
28
+ "@codeleap/form": "5.0.8",
29
+ "@codeleap/query": "5.0.8",
30
+ "@codeleap/logger": "5.0.8",
31
+ "@codeleap/styles": "5.0.8",
34
32
  "@d11/react-native-fast-image": "8.8.0",
35
33
  "@react-native-firebase/messaging": "21.7.2",
36
34
  "@react-navigation/bottom-tabs": "7.2.0",
package/package.json.bak CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codeleap/mobile",
3
- "version": "5.0.7",
3
+ "version": "5.0.8",
4
4
  "main": "src/index.ts",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {
@@ -13,7 +13,6 @@
13
13
  "@codeleap/utils": "workspace:*",
14
14
  "@codeleap/hooks": "workspace:*",
15
15
  "@codeleap/form": "workspace:*",
16
- "@codeleap/i18n": "workspace:*",
17
16
  "@codeleap/query": "workspace:*",
18
17
  "@codeleap/logger": "workspace:*",
19
18
  "@codeleap/config": "workspace:*"
@@ -27,7 +26,6 @@
27
26
  "@codeleap/utils": "workspace:*",
28
27
  "@codeleap/hooks": "workspace:*",
29
28
  "@codeleap/form": "workspace:*",
30
- "@codeleap/i18n": "workspace:*",
31
29
  "@codeleap/query": "workspace:*",
32
30
  "@codeleap/logger": "workspace:*",
33
31
  "@codeleap/styles": "workspace:*",
@@ -1,7 +1,6 @@
1
1
  import React, { useMemo, useRef } from 'react'
2
2
  import { TypeGuards } from '@codeleap/types'
3
3
  import { useConditionalState } from '@codeleap/hooks'
4
- import { useI18N } from '@codeleap/i18n'
5
4
  import DatePicker from 'react-native-date-picker'
6
5
  import Modal from '../Modal'
7
6
  import { TextInput } from '../TextInput'
@@ -116,6 +115,7 @@ export const DatePickerModal = (props: DatePickerModalProps) => {
116
115
  onConfirm: _onConfirm,
117
116
  value: _value,
118
117
  onValueChange: _onValueChange,
118
+ locale,
119
119
  ...modalProps
120
120
  } = allProps
121
121
 
@@ -134,7 +134,6 @@ export const DatePickerModal = (props: DatePickerModalProps) => {
134
134
  const compositionStyles = useCompositionStyles(['input', 'doneButton', 'cancelButton', 'confirmButton'], styles)
135
135
 
136
136
  const formattedDate = value ? formatDate(value) : ''
137
- const { locale } = useI18N()
138
137
 
139
138
  const tempDate = useRef<Date | null>(initialDate instanceof Date ? initialDate : new Date(initialDate))
140
139
 
@@ -47,4 +47,5 @@ export type DatePickerModalProps =
47
47
  style?: StyledProp<DatePickerModalComposition>
48
48
  value?: Date
49
49
  onValueChange?: (value: Date) => void
50
+ locale?: string
50
51
  }
@@ -11,6 +11,8 @@ export function useInputBase<V, T extends Field<V, any, any, unknown> = Field<V
11
11
  params: Partial<IFieldRef<V>> = {},
12
12
  deps: any[] = []
13
13
  ) {
14
+ const [value, onValueChange] = customState
15
+
14
16
  const hasState = useMemo(() => customState.filter(Boolean)?.length >= 1, [])
15
17
 
16
18
  const wrapperRef = useRef<View>()
@@ -38,15 +40,7 @@ export function useInputBase<V, T extends Field<V, any, any, unknown> = Field<V
38
40
  ...params,
39
41
  },
40
42
  deps
41
- ] as unknown as Parameters<T['use']>, () => defaultField(hasState ? {
42
- state: {
43
- get: () => customState[0],
44
- set: (val: V) => customState[1](val),
45
- value: customState[0],
46
- listen: () => {},
47
- },
48
- validate: () => ({ isValid: true })
49
- } : {}))
43
+ ] as unknown as Parameters<T['use']>, () => defaultField(hasState ? { onValueChange, defaultValue: value } : {}))
50
44
 
51
45
  const validation = fieldHandle.validation
52
46
 
@@ -12,7 +12,7 @@ import { MobileStyleRegistry } from '../../Registry'
12
12
  import { useStylesFor } from '../../hooks'
13
13
  import CurrencyInput from 'react-native-currency-input'
14
14
  import { useInputBasePartialStyles } from '../InputBase/useInputBasePartialStyles'
15
- import { useNumberIncrement } from './useNumberIncrement'
15
+ import { MAX_VALID_DIGITS, useNumberIncrement } from './useNumberIncrement'
16
16
 
17
17
  export * from './styles'
18
18
  export * from './types'
@@ -179,10 +179,10 @@ export const NumberIncrement = forwardRef<NativeTextInput, NumberIncrementProps>
179
179
  allowFontScaling={false}
180
180
  editable={!disabled}
181
181
  placeholderTextColor={partialStyles?.placeholder?.color}
182
- value={isFormatted ? formatter(fieldHandle?.value ?? min) : String(fieldHandle?.value ?? min)}
183
182
  selectionColor={partialStyles?.selection?.color}
184
- onChangeText={handleChangeInput}
185
183
  {...textInputProps}
184
+ onChangeText={handleChangeInput}
185
+ value={isFormatted ? formatter(fieldHandle?.value ?? min) : String(fieldHandle?.value ?? min)}
186
186
  onBlur={handleBlur}
187
187
  onFocus={handleFocus}
188
188
  style={[styles.input, partialStyles.input]}
@@ -220,6 +220,8 @@ NumberIncrement.defaultProps = {
220
220
  timeoutActionFocus: 300,
221
221
  actionPressAutoFocus: true,
222
222
  actionDebounce: null,
223
+ min: 0,
224
+ max: MAX_VALID_DIGITS
223
225
  } as Partial<NumberIncrementProps>
224
226
 
225
227
  MobileStyleRegistry.registerComponent(NumberIncrement)
@@ -38,6 +38,16 @@ export function useNumberIncrement(props: Partial<NumberIncrementProps>) {
38
38
  [value, onValueChange]
39
39
  )
40
40
 
41
+ const incrementDisabled = useMemo(() => {
42
+ const maxLimit = TypeGuards.isNumber(max) && (Number(fieldHandle?.value) >= max)
43
+ return maxLimit
44
+ }, [fieldHandle?.value])
45
+
46
+ const decrementDisabled = useMemo(() => {
47
+ const minLimit = TypeGuards.isNumber(min) && (Number(fieldHandle?.value) <= min)
48
+ return minLimit
49
+ }, [fieldHandle?.value])
50
+
41
51
  const actionTimeoutRef = useRef(null)
42
52
 
43
53
  const clearActionTimeoutRef = useCallback(() => {
@@ -64,7 +74,7 @@ export function useNumberIncrement(props: Partial<NumberIncrementProps>) {
64
74
  setIsFocused(false)
65
75
  }, timeoutActionFocus)
66
76
  }
67
- }, [fieldHandle?.value])
77
+ }, [fieldHandle?.value, incrementDisabled, decrementDisabled])
68
78
 
69
79
  const checkValue = useCallback((newValue: number = null, withLimits = true) => {
70
80
  const value = newValue ?? fieldHandle?.value
@@ -87,14 +97,14 @@ export function useNumberIncrement(props: Partial<NumberIncrementProps>) {
87
97
  }
88
98
 
89
99
  return value
90
- }, [])
100
+ }, [fieldHandle?.value])
91
101
 
92
102
  const handleBlur = useCallback((e: NativeSyntheticEvent<TextInputFocusEventData>) => {
93
103
  fieldHandle.setValue(checkValue())
94
104
  validation.onInputBlurred()
95
105
  setIsFocused(false)
96
106
  onBlur?.(e)
97
- }, [validation.onInputBlurred, onBlur])
107
+ }, [validation.onInputBlurred, onBlur, checkValue])
98
108
 
99
109
  const handleFocus = useCallback((e: NativeSyntheticEvent<TextInputFocusEventData>) => {
100
110
  clearActionTimeoutRef()
@@ -108,22 +118,12 @@ export function useNumberIncrement(props: Partial<NumberIncrementProps>) {
108
118
  fieldHandle.setValue(value)
109
119
 
110
120
  return value
111
- }, [])
121
+ }, [checkValue])
112
122
 
113
123
  const handleMaskChange = useCallback((masked, unmasked) => {
114
124
  handleChangeInput?.(masked)
115
125
  if (onChangeMask) onChangeMask(masked, unmasked)
116
- }, [onChangeMask])
117
-
118
- const incrementDisabled = useMemo(() => {
119
- const maxLimit = TypeGuards.isNumber(max) && (Number(fieldHandle?.value) >= max)
120
- return maxLimit
121
- }, [fieldHandle?.value])
122
-
123
- const decrementDisabled = useMemo(() => {
124
- const minLimit = TypeGuards.isNumber(min) && (Number(fieldHandle?.value) <= min)
125
- return minLimit
126
- }, [fieldHandle?.value])
126
+ }, [onChangeMask, handleChangeInput])
127
127
 
128
128
  const hasValue = TypeGuards.isString(fieldHandle?.value)
129
129
  ? (fieldHandle?.value as string).length > 0
@@ -40,7 +40,6 @@ export const TextInput = forwardRef<NativeTextInput, TextInputProps>((props, inp
40
40
  autoAdjustSelection,
41
41
  selectionStart,
42
42
  forceError,
43
- onChangeText,
44
43
  multiline,
45
44
  ...textInputProps
46
45
  } = others
@@ -130,12 +129,13 @@ export const TextInput = forwardRef<NativeTextInput, TextInputProps>((props, inp
130
129
  {...buttonModeProps}
131
130
  selection={autoAdjustSelection ? currentSelection : undefined}
132
131
  placeholderTextColor={partialStyles?.placeholder?.color}
133
- value={fieldHandle?.value}
134
132
  selectionColor={partialStyles?.selection?.color}
135
133
  secureTextEntry={secure && secureTextEntry}
136
134
  textAlignVertical={multiline ? 'top' : undefined}
137
135
  multiline={multiline}
138
136
  {...textInputProps}
137
+ value={fieldHandle?.value}
138
+ onChangeText={fieldHandle?.setValue}
139
139
  onBlur={handleBlur}
140
140
  onFocus={handleFocus}
141
141
  style={[
@@ -0,0 +1 @@
1
+ export * as Permissions from './permissions'
@@ -1,10 +1,10 @@
1
1
  import React, { useContext, useState } from 'react'
2
- import { useModalContext } from '../ModalManager/context'
2
+ import { useModalContext } from '../../utils/ModalManager/context'
3
3
  import { onMount, onUpdate, useDebounce, usePrevious } from '@codeleap/hooks'
4
4
  import { deepEqual } from '@codeleap/utils'
5
5
  import { AppState, Linking } from 'react-native'
6
6
  import { PermissionConfig, PermissionModalsConfig } from './types'
7
- import { PermissionManager, PermissionTypes } from '../MobilePermissionManager'
7
+ import { PermissionManager, PermissionTypes } from './package'
8
8
 
9
9
  type TPermissionContext = {
10
10
  state: Record<string, PermissionTypes.PermissionStatus>
@@ -26,7 +26,7 @@ function getStatuses(state: PermissionsRecord) {
26
26
  return Object.fromEntries(statuses)
27
27
  }
28
28
 
29
- export function Provider({ children, AppPermissions, modalConfig }:PermissionProviderProps) {
29
+ export function Provider({ children, AppPermissions, modalConfig }: PermissionProviderProps) {
30
30
 
31
31
  const [state, setState] = useState(() => getStatuses(AppPermissions.values))
32
32
 
@@ -50,7 +50,7 @@ export function Provider({ children, AppPermissions, modalConfig }:PermissionPro
50
50
  ...state,
51
51
  [forPermission]: status
52
52
  })
53
- }
53
+ }
54
54
 
55
55
 
56
56
  return <PermissionContext.Provider value={{
@@ -63,29 +63,29 @@ export function Provider({ children, AppPermissions, modalConfig }:PermissionPro
63
63
  </PermissionContext.Provider>
64
64
  }
65
65
 
66
- type TAskManyResults<T extends string> =Record<T, PermissionTypes.PermissionStatus> & {
66
+ type TAskManyResults<T extends string> = Record<T, PermissionTypes.PermissionStatus> & {
67
67
  overall
68
68
  : PermissionTypes.PermissionStatus
69
69
  }
70
70
 
71
- type AskManyOpts<T extends string|number|symbol > = {
71
+ type AskManyOpts<T extends string | number | symbol> = {
72
72
  breakOnDenied?: T[]
73
73
  }
74
74
 
75
75
  export type UsePermissions<
76
76
  _PermissionNames extends string,
77
77
  PermissionNames extends string = `${_PermissionNames}?` | _PermissionNames> = () => TPermissionContext & {
78
- askPermission: (name: PermissionNames, onResolve?: (status: PermissionTypes.PermissionStatus) => any) => Promise<PermissionTypes.PermissionStatus>
79
- askMany<T extends PermissionNames, R = TAskManyResults<T>>(
80
- perms: T[],
81
- onResolve?: (res:R) => any,
82
- options?: AskManyOpts<T>
83
- ):Promise<
84
- R
85
- >
86
- }
78
+ askPermission: (name: PermissionNames, onResolve?: (status: PermissionTypes.PermissionStatus) => any) => Promise<PermissionTypes.PermissionStatus>
79
+ askMany<T extends PermissionNames, R = TAskManyResults<T>>(
80
+ perms: T[],
81
+ onResolve?: (res: R) => any,
82
+ options?: AskManyOpts<T>
83
+ ): Promise<
84
+ R
85
+ >
86
+ }
87
87
 
88
- export const usePermissions:UsePermissions<any> = () => {
88
+ export const usePermissions: UsePermissions<any> = () => {
89
89
  const modalCtx = useModalContext()
90
90
  const permissionCtx = useContext(PermissionContext)
91
91
 
@@ -122,7 +122,7 @@ export const usePermissions:UsePermissions<any> = () => {
122
122
 
123
123
  const askMany = async (
124
124
  perms: any[],
125
- onResolve?: (res:any) => any,
125
+ onResolve?: (res: any) => any,
126
126
  options?: AskManyOpts<any>,
127
127
  ) => {
128
128
 
@@ -186,7 +186,7 @@ export const usePermissions:UsePermissions<any> = () => {
186
186
  modalCtx.toggleModal(prevModal, false, {})
187
187
  })
188
188
  }
189
- const res:Parameters<typeof onResolve>[0] = {
189
+ const res: Parameters<typeof onResolve>[0] = {
190
190
  ...results,
191
191
  overall: Object.values(results).every(x => x === 'granted') ? 'granted' : 'denied',
192
192
  }
@@ -313,4 +313,4 @@ export function createTypedPermissionHooks<
313
313
  usePermissionModal: _usePermissionModal,
314
314
 
315
315
  }
316
- }
316
+ }
@@ -1,20 +1,16 @@
1
- import { usePermissions, Provider, createTypedPermissionHooks, usePermissionModal } from './context'
2
- import {
1
+ import { usePermissions, Provider, createTypedPermissionHooks, usePermissionModal } from './Context'
2
+ import { PermissionConfig, PermissionModalsConfig } from './types'
3
3
 
4
- PermissionConfig,
5
- PermissionModalsConfig,
4
+ export * from './package'
6
5
 
7
- } from './types'
8
6
  export {
9
7
  usePermissions,
10
8
  Provider,
11
9
  usePermissionModal,
12
10
  createTypedPermissionHooks,
13
-
14
11
  }
15
12
 
16
13
  export type {
17
-
18
14
  PermissionConfig,
19
15
  PermissionModalsConfig,
20
- }
16
+ }
@@ -3,12 +3,12 @@ import { Permission } from './Permission'
3
3
  import * as PermissionTypes from './types'
4
4
 
5
5
  export class PermissionManager<
6
- T extends PermissionTypes.PermissionActionRecord,
7
- I extends PermissionTypes.IPermissionManager<T> = PermissionTypes.IPermissionManager<T>
6
+ T extends PermissionTypes.PermissionActionRecord,
7
+ I extends PermissionTypes.IPermissionManager<T> = PermissionTypes.IPermissionManager<T>
8
8
  > implements PermissionTypes.IPermissionManager<T> {
9
- private _permissions:Record<keyof T, Permission>
9
+ private _permissions: Record<keyof T, Permission>
10
10
 
11
- subscriberArgs:Parameters<PermissionTypes.ChangeListener<T>>
11
+ subscriberArgs: Parameters<PermissionTypes.ChangeListener<T>>
12
12
 
13
13
  private subscribers: PermissionTypes.ChangeListener<T>[]
14
14
 
@@ -21,8 +21,8 @@ export class PermissionManager<
21
21
  private params: T
22
22
 
23
23
  public permissions: {
24
- [Property in keyof T as Uppercase<string & Property>] : Property
25
- }
24
+ [Property in keyof T as Uppercase<string & Property>]: Property
25
+ }
26
26
 
27
27
  logger: Logger
28
28
 
@@ -65,7 +65,7 @@ export class PermissionManager<
65
65
  return this._permissions[name]
66
66
  }
67
67
 
68
- getMany:I['getMany'] = async (perms, options) => {
68
+ getMany: I['getMany'] = async (perms, options) => {
69
69
 
70
70
  const results = []
71
71
 
@@ -81,11 +81,11 @@ export class PermissionManager<
81
81
  }
82
82
 
83
83
  // @ts-ignore
84
- get:I['get'] = async (name, options) => {
84
+ get: I['get'] = async (name, options) => {
85
85
  return await this.check(name, options)
86
86
  }
87
87
 
88
- onPermissionChange(name: keyof T, callback:PermissionTypes.PermissionSubscriber) {
88
+ onPermissionChange(name: keyof T, callback: PermissionTypes.PermissionSubscriber) {
89
89
  const subIdx = this.permSubscribers[name].push(callback) - 1
90
90
 
91
91
  return () => {
@@ -93,7 +93,7 @@ export class PermissionManager<
93
93
  }
94
94
  }
95
95
 
96
- onChange(callback:PermissionTypes.ChangeListener<T>) {
96
+ onChange(callback: PermissionTypes.ChangeListener<T>) {
97
97
  const subIdx = this.subscribers.push(callback) - 1
98
98
 
99
99
  return () => {
@@ -121,4 +121,4 @@ export class PermissionManager<
121
121
  return res
122
122
  }
123
123
 
124
- }
124
+ }
@@ -8,7 +8,7 @@ export class Permission implements PermissionTypes.IPermission {
8
8
 
9
9
  shouldAsk: boolean
10
10
 
11
- constructor(private actions:PermissionTypes.PermissionActions & {log?: AnyFunction}, public name = '') {
11
+ constructor(private actions: PermissionTypes.PermissionActions & { log?: AnyFunction }, public name = '') {
12
12
  this.actions = actions
13
13
  this.shouldAsk = true
14
14
  this.status = 'pending'
@@ -25,8 +25,8 @@ export class Permission implements PermissionTypes.IPermission {
25
25
  }
26
26
  }
27
27
 
28
- async check(options?:PermissionTypes.CheckOptions): Promise<void> {
29
- const _options:PermissionTypes.CheckOptions = {
28
+ async check(options?: PermissionTypes.CheckOptions): Promise<void> {
29
+ const _options: PermissionTypes.CheckOptions = {
30
30
  askOnPending: true,
31
31
  askOnDenied: false,
32
32
  ask: true,
@@ -76,4 +76,4 @@ export class Permission implements PermissionTypes.IPermission {
76
76
  return this.status === 'limited'
77
77
 
78
78
  }
79
- }
79
+ }
@@ -1,3 +1,3 @@
1
1
  export * as PermissionTypes from './types'
2
2
  export * from './Permission'
3
- export * from './PermissionManager'
3
+ export * from './Manager'
@@ -5,33 +5,33 @@ export const permissionStatuses = ['unavailable', 'pending', 'denied', 'limited'
5
5
  export type PermissionStatus = typeof permissionStatuses[number]
6
6
 
7
7
  export type PermissionState = {
8
- status: PermissionStatus
9
- shouldAsk: boolean
8
+ status: PermissionStatus
9
+ shouldAsk: boolean
10
10
 
11
11
  } & Record<`is${Capitalize<PermissionStatus>}`, boolean>
12
12
 
13
13
  export type CheckOptions = {
14
- askOnPending?:boolean
15
- askOnDenied?:boolean
16
- ask?: boolean
14
+ askOnPending?: boolean
15
+ askOnDenied?: boolean
16
+ ask?: boolean
17
17
 
18
18
  }
19
19
 
20
20
  export type IPermission = {
21
- ask():Promise<void>
22
- check(options?:CheckOptions):Promise<void>
21
+ ask(): Promise<void>
22
+ check(options?: CheckOptions): Promise<void>
23
23
 
24
24
  } & PermissionState
25
25
 
26
26
  export type PermFunction = FunctionType<[], Promise<PermissionStatus>>
27
27
 
28
- export type PermissionActions = Record<'onAsk'|'onCheck', PermFunction> & { init?: 'check' | PermissionState }
28
+ export type PermissionActions = Record<'onAsk' | 'onCheck', PermFunction> & { init?: 'check' | PermissionState }
29
29
 
30
30
  export type PermissionActionRecord = Record<string, PermissionActions>
31
31
 
32
32
  export interface IPermissionManager<T extends PermissionActionRecord> {
33
- getMany(perms: PermissionArray<T>, options?: CheckOptions): Promise<PermissionState[]>
34
- get(name: keyof T, options?: CheckOptions): Promise<PermissionState>
33
+ getMany(perms: PermissionArray<T>, options?: CheckOptions): Promise<PermissionState[]>
34
+ get(name: keyof T, options?: CheckOptions): Promise<PermissionState>
35
35
  }
36
36
 
37
37
  export type ChangeListener<T> = FunctionType<[keyof T, PermissionState], any>
@@ -40,5 +40,5 @@ export type PermissionSubscriber = FunctionType<[PermissionState], any>
40
40
  export type PermissionArray<T> = ([name: keyof T, options: CheckOptions])[] | (keyof T)[]
41
41
 
42
42
  export type PermissionManagerOptions = {
43
- logger?: Logger
44
- }
43
+ logger?: Logger
44
+ }
@@ -0,0 +1,27 @@
1
+ import { ImageProps } from '../../components/Image'
2
+ import { PermissionTypes } from './package'
3
+ type NonGrantedPermissionTypes = Exclude<PermissionTypes.PermissionStatus, 'granted'>
4
+
5
+ export type BasePermissionConfig = {
6
+ fullscreenModal?: boolean
7
+ dismissable?: boolean
8
+ title: string
9
+ onAllow: 'openSettings' | 'ask'
10
+
11
+ description: string[]
12
+ icon?: string
13
+ image?: ImageProps['source']
14
+ imageProps?: Omit<ImageProps, 'source'>
15
+ }
16
+
17
+ export type PermissionConfig = BasePermissionConfig &
18
+ Partial<
19
+ Record<
20
+ NonGrantedPermissionTypes,
21
+ Partial<BasePermissionConfig>
22
+ >
23
+ >
24
+
25
+ export type PermissionModalsConfig<PermissionNames extends string | number | symbol> = Partial<
26
+ Record<PermissionNames, PermissionConfig>
27
+ >
@@ -1,3 +1,4 @@
1
1
  export * from './useStylesFor'
2
2
  export * from './useStatusBar'
3
- export * from './useKeyboardController'
3
+ export * from './useKeyboardController'
4
+ export * from './useAppState'
@@ -0,0 +1,23 @@
1
+ import { DependencyList, useEffect, useState } from 'react'
2
+ import { AppState, AppStateStatus } from 'react-native'
3
+
4
+ export function useAppState(
5
+ callbackFn: (state: AppStateStatus) => void,
6
+ deps: DependencyList = []
7
+ ) {
8
+ useEffect(() => {
9
+ const listener = AppState.addEventListener('change', callbackFn)
10
+
11
+ return () => {
12
+ listener.remove()
13
+ }
14
+ }, deps)
15
+ }
16
+
17
+ export function useAppStateStatus() {
18
+ const [status, setStatus] = useState<AppStateStatus>(AppState.currentState)
19
+
20
+ useAppState((newStatus) => setStatus(newStatus))
21
+
22
+ return status
23
+ }
package/src/index.ts CHANGED
@@ -2,6 +2,7 @@ export * from './components/components'
2
2
  export * from './utils'
3
3
  export * from './hooks'
4
4
  export * from './modules'
5
+ export * from './deprecated'
5
6
 
6
7
  export { Linking } from 'react-native'
7
8
  import uuid from 'react-native-uuid'
@@ -1,7 +1,7 @@
1
- import { onMount, onUpdate, usePrevious, useRef, useState } from '@codeleap/hooks'
1
+ import { onUpdate, usePrevious, useRef, useState } from '@codeleap/hooks'
2
2
  import { shadeColor } from '@codeleap/utils'
3
3
  import { TypeGuards } from '@codeleap/types'
4
- import { Animated, AppState, AppStateStatus, Platform, BackHandler, ViewStyle, ImageStyle, TextStyle, StyleSheet, StyleProp } from 'react-native'
4
+ import { Animated, Platform, BackHandler, ViewStyle, ImageStyle, TextStyle, StyleSheet, StyleProp } from 'react-native'
5
5
  import { AnimatedStyleProp, Easing, EasingFn, useAnimatedStyle, withTiming } from 'react-native-reanimated'
6
6
  import { PressableRippleProps } from '../modules/PressableRipple/type'
7
7
  import { useMemo } from 'react'
@@ -41,22 +41,6 @@ export function useAnimateColor(value: string, opts?: Partial<Animated.TimingAni
41
41
 
42
42
  }
43
43
 
44
- export function useAppState(filter?: AppStateStatus[]) {
45
- const [appState, setAppState] = useState(() => AppState.currentState)
46
-
47
- onMount(() => {
48
- AppState.addEventListener('change', s => {
49
- if (!filter || filter.includes(s)) {
50
- setAppState(s)
51
- }
52
- })
53
- })
54
-
55
- return {
56
- appState,
57
- }
58
- }
59
-
60
44
  type SelectProperties<T extends Record<string|number|symbol, any>, K extends keyof T> = {
61
45
  [P in K] : T[K]
62
46
  }