@codeleap/mobile 2.3.16 → 2.3.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.
Files changed (89) 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/Calendar/types.ts +71 -71
  67. package/src/components/EmptyPlaceholder/index.tsx +32 -8
  68. package/src/components/EmptyPlaceholder/styles.ts +18 -15
  69. package/src/components/Image/index.tsx +33 -3
  70. package/src/components/List/styles.ts +7 -1
  71. package/src/components/Modal/index.tsx +12 -7
  72. package/src/components/Modal/styles.ts +36 -46
  73. package/src/components/MultiSelect/index.tsx +10 -4
  74. package/src/components/MultiSelect/styles.ts +117 -4
  75. package/src/components/MultiSelect/types.ts +8 -0
  76. package/src/components/Scroll/styles.ts +4 -1
  77. package/src/components/SegmentedControl/index.tsx +5 -4
  78. package/src/components/SegmentedControl/styles.ts +13 -10
  79. package/src/components/Select/index.tsx +50 -27
  80. package/src/components/Select/styles.ts +103 -25
  81. package/src/components/Select/types.ts +11 -1
  82. package/src/components/TextInput/index.tsx +3 -1
  83. package/src/components/Touchable/index.tsx +5 -3
  84. package/src/components/View/index.tsx +25 -13
  85. package/src/utils/KeyboardAware/context.tsx +2 -7
  86. package/src/utils/KeyboardAware/lib/KeyboardAwareInterface.ts +3 -3
  87. package/src/utils/PermissionManager/context.tsx +1 -1
  88. package/src/utils/hooks.ts +50 -0
  89. package/src/utils/theme.ts +1 -1
@@ -1,15 +1,15 @@
1
- import { createDefaultVariantFactory, TextInputComposition } from '@codeleap/common'
1
+ import { assignTextStyle, createDefaultVariantFactory, TextInputComposition } from '@codeleap/common'
2
2
  import { DrawerComposition, DrawerStyles } from '../Drawer'
3
+ import { ListComposition } from '../List'
4
+ import { ModalComposition } from '../Modal'
3
5
  type ItemStates = '' | ':selected'
4
6
  export type SelectComposition =
5
- DrawerComposition |
7
+ ModalComposition |
6
8
  `input${TextInputComposition}` |
7
- 'list' |
9
+ `list${Capitalize<ListComposition>}` |
8
10
  'listContent' |
9
11
  `itemWrapper${ItemStates}` |
10
12
  `itemText${ItemStates}` |
11
- 'scroll' |
12
- 'scrollContent' |
13
13
  `itemIcon${ItemStates}`
14
14
 
15
15
  const createSelectStyle = createDefaultVariantFactory<SelectComposition>()
@@ -17,46 +17,124 @@ const createSelectStyle = createDefaultVariantFactory<SelectComposition>()
17
17
  export const SelectStyles = {
18
18
  ...DrawerStyles,
19
19
  default: createSelectStyle((theme) => {
20
- const defaultStyle = DrawerStyles.default(theme)
21
20
 
22
21
  return {
23
- ...defaultStyle,
22
+ wrapper: {
23
+ ...theme.presets.absolute,
24
+ // ...theme.presets.whole,
25
+ ...theme.presets.fullHeight,
26
+ ...theme.presets.fullWidth,
27
+ },
28
+ 'box:transition': {
29
+ scale: {
30
+ duration: theme.values.transitions.modal.duration,
31
+ type: 'timing',
32
+ },
33
+ opacity: {
34
+ duration: theme.values.transitions.modal.duration,
35
+ type: 'timing',
36
+ },
37
+ },
38
+ 'backdrop:transition': {
39
+ opacity: {
40
+ duration: theme.values.transitions.modal.duration,
41
+ type: 'timing',
42
+ },
43
+ },
44
+ backdrop: {
45
+ ...theme.presets.absolute,
46
+ ...theme.presets.whole,
47
+
48
+ backgroundColor: theme.colors.black,
49
+
50
+ },
51
+ backdropTouchable: {
52
+ // height: '100%',
53
+ ...theme.presets.absolute,
54
+ ...theme.presets.whole,
55
+
56
+ },
57
+ 'backdrop:visible': {
58
+ opacity: 0.5,
59
+ },
60
+ 'backdrop:hidden': {
61
+ opacity: 0,
62
+ },
63
+ innerWrapper: {
64
+
65
+ },
66
+ scroll: {
67
+ flex: 1,
68
+ // maxHeight: theme.values.height,
69
+ },
70
+ scrollContent: {
71
+ ...theme.presets.alignCenter,
72
+ ...theme.presets.justifyCenter,
73
+ minHeight: '100%',
74
+ ...theme.presets.safeAreaTop(theme.values.innerSpacing.Y),
75
+ ...theme.presets.safeAreaBottom(theme.values.innerSpacing.Y),
76
+ },
24
77
  box: {
25
- ...theme.spacing.paddingHorizontal(0),
78
+ backgroundColor: theme.colors.background,
79
+ width: theme.values.width - theme.spacing.value(theme.values.innerSpacing.X * 2),
80
+ borderRadius: theme.borderRadius.modalOuter,
81
+ ...theme.spacing.paddingHorizontal(theme.values.innerSpacing.X),
82
+ ...theme.spacing.paddingVertical(theme.values.innerSpacing.Y),
83
+ },
84
+
85
+ 'box:hidden': {
86
+ opacity: 0,
87
+ scale: 0.8,
26
88
 
27
89
  },
90
+ 'box:visible': {
91
+ opacity: 1,
92
+ scale: 1,
93
+ },
94
+ header: {
95
+ flexDirection: 'row',
96
+ ...theme.presets.justifySpaceBetween,
97
+ ...theme.presets.alignCenter,
98
+ },
99
+ closeButtonTouchableWrapper: {
100
+ alignSelf: 'center',
101
+ ...theme.spacing.marginLeft('auto'),
102
+ },
103
+ closeButtonIcon: {
104
+ color: theme.colors.text,
105
+ },
106
+ title: {
107
+ ...assignTextStyle('h3')(theme).text,
108
+ },
109
+ listWrapper: {
110
+ height: 'auto',
111
+ },
112
+
28
113
  itemWrapper: {
29
114
  ...theme.presets.row,
30
115
  ...theme.presets.justifySpaceBetween,
31
116
  ...theme.presets.alignCenter,
32
- ...theme.spacing.padding(1.4),
33
- height: 50,
117
+ borderRadius: theme.borderRadius.medium,
118
+ ...theme.spacing.padding(1),
119
+ backgroundColor: theme.colors.backgroundSecondary,
34
120
  },
35
121
  'itemWrapper:selected': {
36
122
  backgroundColor: theme.colors.primary,
37
123
  },
38
- 'itemText:selected': {
39
- color: theme.colors.white,
124
+ 'itemIcon:selected': {
125
+ color: theme.colors.backgroundSecondary,
126
+ ...theme.sized(2),
40
127
 
41
128
  },
42
- 'itemIcon:selected': {
43
- color: theme.colors.white,
44
- ...theme.sized(3),
129
+ 'itemText:selected': {
130
+ color: theme.colors.backgroundSecondary,
131
+
45
132
  },
46
133
  itemIcon: {
47
- width: 0,
48
134
  height: 0,
49
- },
50
- list: {
51
- height: 'auto',
52
-
53
- maxHeight: theme.values.window.height * 0.75,
135
+ width: 0,
54
136
 
55
137
  },
56
- // listContent: {
57
- // paddingBottom: theme.values.safeAreaTop,
58
- // },
59
-
60
138
  }
61
139
  }),
62
140
  }
@@ -2,19 +2,26 @@ import {
2
2
  ComponentVariants,
3
3
  FormTypes,
4
4
  IconPlaceholder,
5
+ PropsOf,
5
6
  } from '@codeleap/common'
6
7
  import { StylesOf } from '../../types/utility'
7
8
  import { GetKeyboardAwarePropsOptions } from '../../utils'
8
9
  import { DrawerProps } from '../Drawer'
10
+ import { Icon } from '../Icon'
9
11
  import { FlatListProps } from '../List'
12
+ import { Text } from '../Text'
10
13
  import { TextInputProps } from '../TextInput'
14
+ import { Touchable } from '../Touchable'
11
15
  import { SelectComposition, SelectStyles } from './styles'
12
16
 
13
- export type SelectRenderFNProps<T> = & {
17
+ export type SelectRenderFNProps<T> = {
14
18
  styles: StylesOf<SelectComposition>
15
19
  onPress: () => void
16
20
  isSelected?: boolean
17
21
  item: FormTypes.Options<T>[number]
22
+ touchableProps?: Partial<PropsOf<typeof Touchable>>
23
+ textProps?: Partial<PropsOf<typeof Text>>
24
+ iconProps?: Partial<PropsOf<typeof Icon>>
18
25
  }
19
26
 
20
27
  export type SelectRenderFN<T> = (props: SelectRenderFNProps<T>) => JSX.Element
@@ -39,5 +46,8 @@ export type CustomSelectProps<T> = SelectDrawerProps & {
39
46
  clearable?: boolean
40
47
  clearIconName?: IconPlaceholder
41
48
  keyboardAware?: GetKeyboardAwarePropsOptions
49
+ itemProps?: Partial<
50
+ Pick<SelectRenderFNProps<any>, 'iconProps'|'textProps'|'touchableProps'
51
+ >>
42
52
  } & ComponentVariants<typeof SelectStyles>
43
53
 
@@ -211,7 +211,9 @@ export const TextInput = forwardRef<NativeTextInput, TextInputProps>((rawprops,
211
211
  styles={leftIconStyles}
212
212
  commonStyles={commonIconStyles}
213
213
  debugName={`${debugName} left icon`}
214
- onPress={() => {}}
214
+ onPress={() => {
215
+ input?.current?.focus?.()
216
+ }}
215
217
  noFeedback={!leftIcon?.onPress}
216
218
  {...leftIcon}
217
219
  />
@@ -44,7 +44,7 @@ export const Touchable: React.FC<TouchableProps> = forwardRef<
44
44
  style,
45
45
  debugName,
46
46
  debugComponent,
47
- debounce = 1000,
47
+ debounce = 500,
48
48
  noFeedback = false,
49
49
  styles,
50
50
  ...props
@@ -119,7 +119,6 @@ export const Touchable: React.FC<TouchableProps> = forwardRef<
119
119
  'height!',
120
120
  'flex!',
121
121
  'backgroundColor!',
122
-
123
122
  ]
124
123
 
125
124
  const wrapperStyle = {} as any
@@ -144,7 +143,10 @@ export const Touchable: React.FC<TouchableProps> = forwardRef<
144
143
  pressableStyle[key] = value
145
144
  }
146
145
  })
147
-
146
+ if (wrapperStyle.position === 'absolute') {
147
+ pressableStyle.width = '100%'
148
+ pressableStyle.height = '100%'
149
+ }
148
150
  wrapperStyle.overflow = 'hidden'
149
151
  // wrapperStyle.flexDirection = 'row'
150
152
  // wrapperStyle.alignItems = 'stretch'
@@ -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
 
@@ -1,10 +1,10 @@
1
1
  /* @flow */
2
2
 
3
3
  export interface KeyboardAwareInterface {
4
- getScrollResponder: () => void,
4
+ getScrollResponder: () => void
5
5
  scrollToPosition: (x: number, y: number, animated?: boolean) => void,
6
- scrollToEnd: (animated?: boolean) => void,
7
- scrollForExtraHeightOnAndroid: (extraHeight: number) => void,
6
+ scrollToEnd: (animated?: boolean) => void
7
+ scrollForExtraHeightOnAndroid: (extraHeight: number) => void
8
8
  scrollToFocusedInput: (
9
9
  reactNode: Object,
10
10
  extraHeight: number,
@@ -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