@codeleap/mobile 2.3.19 → 2.3.21

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 (87) hide show
  1. package/dist/components/AutoComplete/index.d.ts +1 -0
  2. package/dist/components/AutoComplete/index.js +2 -1
  3. package/dist/components/AutoComplete/index.js.map +1 -1
  4. package/dist/components/AutoComplete/styles.js +67 -3
  5. package/dist/components/AutoComplete/styles.js.map +1 -1
  6. package/dist/components/Checkbox/index.d.ts +1 -1
  7. package/dist/components/EmptyPlaceholder/index.d.ts +5 -2
  8. package/dist/components/EmptyPlaceholder/index.js +19 -5
  9. package/dist/components/EmptyPlaceholder/index.js.map +1 -1
  10. package/dist/components/EmptyPlaceholder/styles.d.ts +1 -1
  11. package/dist/components/EmptyPlaceholder/styles.js +5 -7
  12. package/dist/components/EmptyPlaceholder/styles.js.map +1 -1
  13. package/dist/components/Grid/styles.d.ts +49 -0
  14. package/dist/components/Image/index.d.ts +1 -0
  15. package/dist/components/Image/index.js +21 -3
  16. package/dist/components/Image/index.js.map +1 -1
  17. package/dist/components/List/styles.d.ts +49 -0
  18. package/dist/components/List/styles.js +5 -4
  19. package/dist/components/List/styles.js.map +1 -1
  20. package/dist/components/Modal/index.d.ts +2 -0
  21. package/dist/components/Modal/index.js +11 -9
  22. package/dist/components/Modal/index.js.map +1 -1
  23. package/dist/components/Modal/styles.d.ts +2 -2
  24. package/dist/components/Modal/styles.js +18 -19
  25. package/dist/components/Modal/styles.js.map +1 -1
  26. package/dist/components/MultiSelect/index.js +7 -5
  27. package/dist/components/MultiSelect/index.js.map +1 -1
  28. package/dist/components/MultiSelect/styles.d.ts +0 -51
  29. package/dist/components/MultiSelect/styles.js +67 -5
  30. package/dist/components/MultiSelect/styles.js.map +1 -1
  31. package/dist/components/MultiSelect/types.d.ts +8 -1
  32. package/dist/components/Scroll/styles.d.ts +49 -0
  33. package/dist/components/Scroll/styles.js +3 -4
  34. package/dist/components/Scroll/styles.js.map +1 -1
  35. package/dist/components/SegmentedControl/index.js +5 -4
  36. package/dist/components/SegmentedControl/index.js.map +1 -1
  37. package/dist/components/SegmentedControl/styles.d.ts +1 -1
  38. package/dist/components/SegmentedControl/styles.js +9 -9
  39. package/dist/components/SegmentedControl/styles.js.map +1 -1
  40. package/dist/components/Select/index.d.ts +4 -1
  41. package/dist/components/Select/index.js +16 -21
  42. package/dist/components/Select/index.js.map +1 -1
  43. package/dist/components/Select/styles.d.ts +54 -53
  44. package/dist/components/Select/styles.js +61 -10
  45. package/dist/components/Select/styles.js.map +1 -1
  46. package/dist/components/Select/types.d.ts +8 -1
  47. package/dist/components/TextInput/index.js +4 -1
  48. package/dist/components/TextInput/index.js.map +1 -1
  49. package/dist/components/Touchable/index.js +5 -1
  50. package/dist/components/Touchable/index.js.map +1 -1
  51. package/dist/components/View/index.js +19 -13
  52. package/dist/components/View/index.js.map +1 -1
  53. package/dist/components/defaultStyles.d.ts +147 -51
  54. package/dist/utils/KeyboardAware/context.js +1 -6
  55. package/dist/utils/KeyboardAware/context.js.map +1 -1
  56. package/dist/utils/PermissionManager/context.js +3 -2
  57. package/dist/utils/PermissionManager/context.js.map +1 -1
  58. package/dist/utils/hooks.d.ts +2 -0
  59. package/dist/utils/hooks.js +44 -1
  60. package/dist/utils/hooks.js.map +1 -1
  61. package/dist/utils/theme.js +3 -3
  62. package/dist/utils/theme.js.map +1 -1
  63. package/package.json +3 -2
  64. package/src/components/AutoComplete/index.tsx +5 -1
  65. package/src/components/AutoComplete/styles.ts +112 -6
  66. package/src/components/EmptyPlaceholder/index.tsx +32 -8
  67. package/src/components/EmptyPlaceholder/styles.ts +18 -15
  68. package/src/components/Image/index.tsx +33 -3
  69. package/src/components/List/styles.ts +7 -1
  70. package/src/components/Modal/index.tsx +12 -7
  71. package/src/components/Modal/styles.ts +36 -46
  72. package/src/components/MultiSelect/index.tsx +10 -4
  73. package/src/components/MultiSelect/styles.ts +117 -4
  74. package/src/components/MultiSelect/types.ts +8 -0
  75. package/src/components/Scroll/styles.ts +4 -1
  76. package/src/components/SegmentedControl/index.tsx +5 -4
  77. package/src/components/SegmentedControl/styles.ts +13 -10
  78. package/src/components/Select/index.tsx +50 -27
  79. package/src/components/Select/styles.ts +103 -25
  80. package/src/components/Select/types.ts +11 -1
  81. package/src/components/TextInput/index.tsx +3 -1
  82. package/src/components/Touchable/index.tsx +5 -3
  83. package/src/components/View/index.tsx +25 -13
  84. package/src/utils/KeyboardAware/context.tsx +2 -7
  85. package/src/utils/PermissionManager/context.tsx +1 -1
  86. package/src/utils/hooks.ts +50 -0
  87. package/src/utils/theme.ts +1 -1
@@ -7,6 +7,7 @@ import {
7
7
  ViewStyles,
8
8
  BaseViewProps,
9
9
  useCodeleapContext,
10
+ useMemo,
10
11
  } from '@codeleap/common'
11
12
  import { View as NativeView } from 'react-native'
12
13
  import { MotiView, MotiProps } from 'moti'
@@ -73,26 +74,37 @@ type GapProps = ViewProps & {
73
74
 
74
75
  export const Gap:React.FC<GapProps> = ({ children, value, defaultProps = {}, ...props }) => {
75
76
  const { Theme } = useCodeleapContext()
77
+ const childArr = React.Children.toArray(children)
78
+
76
79
  const horizontal = props.variants?.includes('row')
80
+ const spacings = useMemo(() => {
81
+ return childArr.map((_, idx) => {
82
+ let spacingFunction = horizontal ? 'marginHorizontal' : 'marginVertical'
83
+
84
+ switch (idx) {
85
+ case 0:
86
+ spacingFunction = horizontal ? 'marginRight' : 'marginBottom'
87
+ break
88
+ case childArr.length - 1:
89
+ spacingFunction = horizontal ? 'marginLeft' : 'marginTop'
90
+ break
91
+ default:
92
+ break
93
+ }
94
+
95
+ return Theme.spacing[spacingFunction](value / 2)
96
+ })
97
+
98
+ }, [childArr.length, horizontal])
99
+
77
100
  return (
78
101
  <View {...props}>
79
102
  {
80
- React.Children.toArray(children).map((Element, idx, childArr) => {
103
+ childArr.map((Element, idx, childArr) => {
81
104
  if (React.isValidElement(Element)) {
82
105
  const props = { ...Element.props, ...defaultProps }
83
106
 
84
- let spacingFunction = horizontal ? 'marginHorizontal' : 'marginVertical'
85
- switch (idx) {
86
- case 0:
87
- spacingFunction = horizontal ? 'marginRight' : 'marginBottom'
88
- break
89
- case childArr.length - 1:
90
- spacingFunction = horizontal ? 'marginLeft' : 'marginTop'
91
- break
92
- default:
93
- break
94
- }
95
- props.style = [props.style, Theme.spacing[spacingFunction](value / 2)]
107
+ props.style = [props.style, spacings[idx]]
96
108
  return React.cloneElement(Element, props)
97
109
  }
98
110
  return Element
@@ -21,7 +21,7 @@ export const KeyboardCtx = React.createContext({} as TKeyboardCtx)
21
21
  export const KeyboardProvider = ({ children }) => {
22
22
  const [keyboardEvent, setKeyboardEvent] = useState<KeyboardEvent>(null)
23
23
  const [keyboardVisible, setKeyboardVisible] = useState(false)
24
- const { Theme } = useCodeleapContext()
24
+
25
25
  useEffect(() => {
26
26
  const eventNames = Platform.select<KeyboardVisibilityEvents>({
27
27
  ios: {
@@ -50,17 +50,12 @@ export const KeyboardProvider = ({ children }) => {
50
50
  }
51
51
  }, [])
52
52
 
53
- let adjustKeyboard = 0
54
-
55
- if (Platform.OS === 'android') {
56
- adjustKeyboard = Theme.values.safeAreaTop
57
- }
58
53
  const height = keyboardEvent?.endCoordinates?.height ?? 0
59
54
 
60
55
  const _return = {
61
56
  event: keyboardEvent,
62
57
  isVisible: keyboardVisible,
63
- height: (!!height && keyboardVisible) ? height + adjustKeyboard : 0,
58
+ height: (!!height && keyboardVisible) ? height : 0,
64
59
  ...Keyboard,
65
60
  }
66
61
 
@@ -193,7 +193,7 @@ export function usePermissionModal(permissionName: string) {
193
193
  const permissionCtx = usePermissions()
194
194
  const modalState = modals.state[modalId]
195
195
 
196
- const currentState = permissionCtx.state[permissionName]
196
+ const currentState = permissionCtx?.state?.[permissionName]
197
197
  const status = currentState
198
198
  const [debouncedStatus, reset] = useDebounce(status, modals.transitionDuration * 0.5)
199
199
 
@@ -1,5 +1,7 @@
1
1
  import { onMount, onUpdate, shadeColor, TypeGuards, usePrevious, useRef, useState } from '@codeleap/common'
2
2
  import { Animated, AppState, AppStateStatus, Platform, PressableAndroidRippleConfig, BackHandler } from 'react-native'
3
+ // @ts-ignore
4
+ import AsyncStorage from '@react-native-community/async-storage'
3
5
 
4
6
  export function useAnimateColor(value: string, opts?: Partial<Animated.TimingAnimationConfig>) {
5
7
  const iters = useRef(0)
@@ -161,3 +163,51 @@ export function useBackButton(cb: () => boolean|void, deps = []) {
161
163
  }
162
164
  }, deps)
163
165
  }
166
+ type StateSetter<T> = T | ((prev:T) => T)
167
+
168
+ export function useAsyncStorageState<T>(key:string, defaultValue?: T) {
169
+ const [value, _setValue] = useState<T>(undefined)
170
+
171
+ onMount(() => {
172
+ AsyncStorage.getItem(key).then(val => {
173
+ let storedValue = defaultValue
174
+
175
+ if (val) {
176
+ storedValue = JSON.parse(val)
177
+ }
178
+
179
+ _setValue(storedValue)
180
+ })
181
+ })
182
+
183
+ const setValue = (to: StateSetter<T>) => {
184
+ return new Promise<void>((resolve, reject) => {
185
+ _setValue((prev) => {
186
+ let newValue = prev
187
+ try {
188
+
189
+ if (typeof to !== 'function') {
190
+ newValue = to
191
+ } else {
192
+ const fn = to as ((prev:T) => T)
193
+ newValue = fn(value)
194
+ }
195
+
196
+ const jsonVal = JSON.stringify(newValue)
197
+
198
+ AsyncStorage.setItem(key, jsonVal).then(resolve).catch(reject)
199
+ resolve()
200
+ return newValue
201
+ } catch (e) {
202
+ reject(e)
203
+ return newValue
204
+ }
205
+
206
+ })
207
+ })
208
+
209
+ }
210
+
211
+ return [value, setValue] as [T, typeof setValue]
212
+ }
213
+
@@ -9,7 +9,7 @@ type AppValues = {
9
9
  export function getMobileThemeValues(initialWindowMetrics, values: AppValues) {
10
10
  const screenDimensions = Dimensions.get('screen')
11
11
 
12
- const hasNotch = Platform.OS === 'ios' ? (Dimensions.get('window').height >= 812) : (initialWindowMetrics?.insets?.top > 24 || StatusBar.currentHeight > 24)
12
+ const hasNotch = DeviceInfo.hasNotch()
13
13
  const hasIsland = DeviceInfo.hasDynamicIsland()
14
14
  const bottomNavHeight = Platform.OS === 'android' ? initialWindowMetrics?.insets?.bottom : 0
15
15