@codeleap/mobile 1.5.3 → 1.8.1

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 (192) hide show
  1. package/CodeLeap-Mobile-Packages.code-workspace +7 -7
  2. package/dist/components/ActivityIndicator.d.ts +13 -13
  3. package/dist/components/ActivityIndicator.js +54 -50
  4. package/dist/components/ActivityIndicator.js.map +1 -1
  5. package/dist/components/Animated.d.ts +15 -15
  6. package/dist/components/Animated.js +58 -54
  7. package/dist/components/Animated.js.map +1 -1
  8. package/dist/components/Button.d.ts +125 -119
  9. package/dist/components/Button.js +82 -77
  10. package/dist/components/Button.js.map +1 -1
  11. package/dist/components/Checkbox/index.d.ts +14 -14
  12. package/dist/components/Checkbox/index.js +77 -73
  13. package/dist/components/Checkbox/index.js.map +1 -1
  14. package/dist/components/Checkbox/styles.d.ts +55 -52
  15. package/dist/components/Checkbox/styles.js +48 -48
  16. package/dist/components/Checkbox/styles.js.map +0 -0
  17. package/dist/components/ContentView.d.ts +10 -10
  18. package/dist/components/ContentView.js +50 -50
  19. package/dist/components/ContentView.js.map +0 -0
  20. package/dist/components/FileInput.d.ts +26 -26
  21. package/dist/components/FileInput.js +178 -174
  22. package/dist/components/FileInput.js.map +1 -1
  23. package/dist/components/Icon.d.ts +12 -12
  24. package/dist/components/Icon.js +70 -66
  25. package/dist/components/Icon.js.map +1 -1
  26. package/dist/components/Icon.js3278065646 +71 -0
  27. package/dist/components/Image.d.ts +18 -18
  28. package/dist/components/Image.js +59 -53
  29. package/dist/components/Image.js.map +1 -1
  30. package/dist/components/List.d.ts +12 -11
  31. package/dist/components/List.js +82 -76
  32. package/dist/components/List.js.map +1 -1
  33. package/dist/components/Modal/index.d.ts +26 -25
  34. package/dist/components/Modal/index.js +112 -108
  35. package/dist/components/Modal/index.js.map +1 -1
  36. package/dist/components/Modal/styles.d.ts +69 -66
  37. package/dist/components/Modal/styles.js +64 -64
  38. package/dist/components/Modal/styles.js.map +0 -0
  39. package/dist/components/Navigation/Navigation.d.ts +2 -3
  40. package/dist/components/Navigation/Navigation.js +87 -83
  41. package/dist/components/Navigation/Navigation.js.map +1 -1
  42. package/dist/components/Navigation/constants.d.ts +5 -5
  43. package/dist/components/Navigation/constants.js +10 -10
  44. package/dist/components/Navigation/constants.js.map +0 -0
  45. package/dist/components/Navigation/index.d.ts +3 -3
  46. package/dist/components/Navigation/index.js +19 -15
  47. package/dist/components/Navigation/index.js.map +1 -1
  48. package/dist/components/Navigation/types.d.ts +26 -26
  49. package/dist/components/Navigation/types.js +7 -7
  50. package/dist/components/Navigation/types.js.map +0 -0
  51. package/dist/components/Navigation/utils.d.ts +3 -3
  52. package/dist/components/Navigation/utils.js +69 -69
  53. package/dist/components/Navigation/utils.js.map +0 -0
  54. package/dist/components/Overlay.d.ts +16 -16
  55. package/dist/components/Overlay.js +69 -65
  56. package/dist/components/Overlay.js.map +1 -1
  57. package/dist/components/Pager/index.d.ts +20 -19
  58. package/dist/components/Pager/index.js +167 -163
  59. package/dist/components/Pager/index.js.map +1 -1
  60. package/dist/components/Pager/styles.d.ts +54 -51
  61. package/dist/components/Pager/styles.js +43 -43
  62. package/dist/components/Pager/styles.js.map +0 -0
  63. package/dist/components/RadioInput/index.d.ts +26 -26
  64. package/dist/components/RadioInput/index.js +72 -68
  65. package/dist/components/RadioInput/index.js.map +1 -1
  66. package/dist/components/RadioInput/styles.d.ts +57 -54
  67. package/dist/components/RadioInput/styles.js +44 -44
  68. package/dist/components/RadioInput/styles.js.map +0 -0
  69. package/dist/components/Scroll.d.ts +12 -11
  70. package/dist/components/Scroll.js +80 -75
  71. package/dist/components/Scroll.js.map +1 -1
  72. package/dist/components/Sections.d.ts +11 -11
  73. package/dist/components/Sections.js +80 -76
  74. package/dist/components/Sections.js.map +1 -1
  75. package/dist/components/Select/index.d.ts +4 -5
  76. package/dist/components/Select/index.js +150 -144
  77. package/dist/components/Select/index.js.map +1 -1
  78. package/dist/components/Select/styles.d.ts +9 -9
  79. package/dist/components/Select/styles.js +56 -56
  80. package/dist/components/Select/styles.js.map +0 -0
  81. package/dist/components/Select/types.d.ts +39 -33
  82. package/dist/components/Select/types.js +2 -2
  83. package/dist/components/Select/types.js.map +0 -0
  84. package/dist/components/Slider/Mark.d.ts +3 -3
  85. package/dist/components/Slider/Mark.js +31 -31
  86. package/dist/components/Slider/Mark.js.map +0 -0
  87. package/dist/components/Slider/Thumb.d.ts +6 -7
  88. package/dist/components/Slider/Thumb.js +29 -29
  89. package/dist/components/Slider/Thumb.js.map +0 -0
  90. package/dist/components/Slider/index.d.ts +3 -3
  91. package/dist/components/Slider/index.js +97 -93
  92. package/dist/components/Slider/index.js.map +1 -1
  93. package/dist/components/Slider/types.d.ts +25 -25
  94. package/dist/components/Slider/types.js +2 -2
  95. package/dist/components/Slider/types.js.map +0 -0
  96. package/dist/components/Switch.d.ts +13 -13
  97. package/dist/components/Switch.js +75 -71
  98. package/dist/components/Switch.js.map +1 -1
  99. package/dist/components/Text.d.ts +12 -12
  100. package/dist/components/Text.js +52 -48
  101. package/dist/components/Text.js.map +1 -1
  102. package/dist/components/TextInput.d.ts +171 -162
  103. package/dist/components/TextInput.js +161 -149
  104. package/dist/components/TextInput.js.map +1 -1
  105. package/dist/components/Touchable.d.ts +14 -14
  106. package/dist/components/Touchable.js +61 -57
  107. package/dist/components/Touchable.js.map +1 -1
  108. package/dist/components/View.d.ts +120 -114
  109. package/dist/components/View.js +54 -50
  110. package/dist/components/View.js.map +1 -1
  111. package/dist/components/components.d.ts +25 -24
  112. package/dist/components/components.js +41 -36
  113. package/dist/components/components.js.map +1 -1
  114. package/dist/index.d.ts +5 -5
  115. package/dist/index.js +28 -24
  116. package/dist/index.js.map +1 -1
  117. package/dist/modules/documentPicker.d.ts +3 -3
  118. package/dist/modules/documentPicker.js +11 -11
  119. package/dist/modules/documentPicker.js.map +0 -0
  120. package/dist/modules/fastImage.d.ts +1 -1
  121. package/dist/modules/fastImage.js +9 -9
  122. package/dist/modules/fastImage.js.map +0 -0
  123. package/dist/modules/reactNavigation.d.ts +3 -3
  124. package/dist/modules/reactNavigation.js +10 -10
  125. package/dist/modules/reactNavigation.js.map +0 -0
  126. package/dist/modules/types/fileTypes.d.ts +138 -138
  127. package/dist/modules/types/fileTypes.js +2 -2
  128. package/dist/modules/types/fileTypes.js.map +0 -0
  129. package/dist/types/utility.d.ts +2 -2
  130. package/dist/types/utility.js +2 -2
  131. package/dist/types/utility.js.map +0 -0
  132. package/dist/utils/OSAlert.d.ts +31 -31
  133. package/dist/utils/OSAlert.js +141 -141
  134. package/dist/utils/OSAlert.js.map +1 -1
  135. package/dist/utils/misc.d.ts +2 -2
  136. package/dist/utils/misc.js +25 -25
  137. package/dist/utils/misc.js.map +0 -0
  138. package/dist/utils/styles.d.ts +1 -1
  139. package/dist/utils/styles.js +12 -12
  140. package/dist/utils/styles.js.map +0 -0
  141. package/package.json +38 -40
  142. package/src/components/ActivityIndicator.tsx +46 -46
  143. package/src/components/Animated.tsx +34 -34
  144. package/src/components/Button.tsx +95 -95
  145. package/src/components/Checkbox/index.tsx +81 -81
  146. package/src/components/Checkbox/styles.ts +72 -72
  147. package/src/components/ContentView.tsx +58 -58
  148. package/src/components/FileInput.tsx +179 -179
  149. package/src/components/Icon.tsx +58 -58
  150. package/src/components/Image.tsx +61 -61
  151. package/src/components/List.tsx +109 -104
  152. package/src/components/Modal/index.tsx +161 -161
  153. package/src/components/Modal/styles.ts +133 -133
  154. package/src/components/Navigation/Navigation.tsx +58 -58
  155. package/src/components/Navigation/constants.ts +8 -8
  156. package/src/components/Navigation/index.tsx +3 -3
  157. package/src/components/Navigation/types.ts +35 -35
  158. package/src/components/Navigation/utils.tsx +59 -59
  159. package/src/components/Overlay.tsx +77 -77
  160. package/src/components/Pager/index.tsx +242 -240
  161. package/src/components/Pager/styles.ts +51 -51
  162. package/src/components/RadioInput/index.tsx +101 -101
  163. package/src/components/RadioInput/styles.ts +67 -67
  164. package/src/components/Scroll.tsx +104 -102
  165. package/src/components/Sections.tsx +101 -100
  166. package/src/components/Select/index.tsx +195 -184
  167. package/src/components/Select/styles.ts +81 -81
  168. package/src/components/Select/types.ts +45 -41
  169. package/src/components/Slider/Mark.tsx +46 -46
  170. package/src/components/Slider/Thumb.tsx +29 -29
  171. package/src/components/Slider/index.tsx +123 -123
  172. package/src/components/Slider/types.ts +25 -25
  173. package/src/components/Switch.tsx +81 -81
  174. package/src/components/Text.tsx +30 -30
  175. package/src/components/TextInput.tsx +216 -211
  176. package/src/components/Touchable.tsx +64 -64
  177. package/src/components/View.tsx +46 -46
  178. package/src/components/components.ts +26 -26
  179. package/src/index.ts +6 -6
  180. package/src/modules/documentPicker.ts +7 -7
  181. package/src/modules/fastImage.ts +2 -2
  182. package/src/modules/index.d.ts +496 -496
  183. package/src/modules/reactNavigation.ts +4 -4
  184. package/src/modules/types/documentPicker.d.ts +215 -215
  185. package/src/modules/types/fileTypes.ts +138 -138
  186. package/src/types/utility.ts +3 -3
  187. package/src/utils/OSAlert.ts +180 -180
  188. package/src/utils/misc.ts +24 -24
  189. package/src/utils/styles.ts +14 -14
  190. package/.eslintignore +0 -2
  191. package/.eslintrc.js +0 -3
  192. package/.vscode/settings.json +0 -11
@@ -1,100 +1,101 @@
1
- import * as React from 'react'
2
- import { forwardRef, useState } from 'react'
3
- import {
4
- deepEqual,
5
- onUpdate,
6
- useDefaultComponentStyle,
7
- usePrevious,
8
- useCodeleapContext,
9
- } from '@codeleap/common'
10
- import {
11
- KeyboardAwareSectionListProps,
12
- KeyboardAwareSectionList as KBDView,
13
- } from 'react-native-keyboard-aware-scroll-view'
14
- import { RefreshControl, SectionList } from 'react-native'
15
- import { View, ViewProps } from './View'
16
-
17
- export type SectionListProps = KeyboardAwareSectionListProps<any> &
18
- ViewProps & {
19
- onRefresh?: () => void
20
- refreshTimeout?: number
21
- changeData?: any
22
- separators?: boolean
23
- }
24
-
25
- const KeyboardAwareSectionList =
26
- KBDView as unknown as React.ForwardRefExoticComponent<
27
- ViewProps & {
28
- refreshControl?: JSX.Element
29
- ref?: SectionList
30
- }
31
- >
32
-
33
- export const Sections = forwardRef<SectionList, SectionListProps>(
34
- (flatListProps, ref) => {
35
- const {
36
- variants = [],
37
- style,
38
- refreshTimeout = 3000,
39
- changeData,
40
- ...props
41
- } = flatListProps
42
- const hasRefresh = !!props.onRefresh
43
- const [refreshing, setRefreshing] = useState(false)
44
-
45
- const timer = React.useRef(null)
46
- const previousData = usePrevious(changeData)
47
-
48
- const onRefresh = () => {
49
- if (timer.current) {
50
- clearTimeout(timer.current)
51
- }
52
-
53
- setRefreshing(true)
54
-
55
- props.onRefresh()
56
-
57
- timer.current = setTimeout(() => {
58
- setRefreshing(false)
59
- }, refreshTimeout)
60
- }
61
- onUpdate(() => {
62
- if (refreshing && !deepEqual(previousData, changeData)) {
63
- setRefreshing(false)
64
- if (timer.current) {
65
- clearTimeout(timer.current)
66
- }
67
- }
68
- }, [refreshing, changeData])
69
- const { Theme } = useCodeleapContext()
70
-
71
- const variantStyles = useDefaultComponentStyle('View', {
72
- variants,
73
- })
74
-
75
- const renderSeparator = () => {
76
- return (
77
- <View variants={['separator']}></View>
78
- )
79
- }
80
-
81
- const separatorProp = props.separators
82
- const isEmpty = !props.data || !props.data.length
83
- const separator = !isEmpty && separatorProp == true && renderSeparator
84
-
85
- return (
86
- <KeyboardAwareSectionList
87
- style={[Theme.presets.full, style]}
88
- contentContainerStyle={[variantStyles.wrapper]}
89
- ref={ref as unknown as SectionList}
90
- ItemSeparatorComponent={separator}
91
- {...props}
92
- refreshControl={
93
- hasRefresh && (
94
- <RefreshControl refreshing={refreshing} onRefresh={onRefresh} />
95
- )
96
- }
97
- />
98
- )
99
- },
100
- )
1
+ import * as React from 'react'
2
+ import { forwardRef, useState } from 'react'
3
+ import {
4
+ deepEqual,
5
+ onUpdate,
6
+ useDefaultComponentStyle,
7
+ usePrevious,
8
+ useCodeleapContext,
9
+ } from '@codeleap/common'
10
+ import {
11
+ KeyboardAwareSectionListProps,
12
+ KeyboardAwareSectionList as KBDView,
13
+ // @ts-ignore
14
+ } from 'react-native-keyboard-aware-scroll-view'
15
+ import { RefreshControl, SectionList } from 'react-native'
16
+ import { View, ViewProps } from './View'
17
+
18
+ export type SectionListProps = KeyboardAwareSectionListProps<any> &
19
+ ViewProps & {
20
+ onRefresh?: () => void
21
+ refreshTimeout?: number
22
+ changeData?: any
23
+ separators?: boolean
24
+ }
25
+
26
+ const KeyboardAwareSectionList =
27
+ KBDView as unknown as React.ForwardRefExoticComponent<
28
+ ViewProps & {
29
+ refreshControl?: JSX.Element
30
+ ref?: SectionList
31
+ }
32
+ >
33
+
34
+ export const Sections = forwardRef<SectionList, SectionListProps>(
35
+ (flatListProps, ref) => {
36
+ const {
37
+ variants = [],
38
+ style,
39
+ refreshTimeout = 3000,
40
+ changeData,
41
+ ...props
42
+ } = flatListProps
43
+ const hasRefresh = !!props.onRefresh
44
+ const [refreshing, setRefreshing] = useState(false)
45
+
46
+ const timer = React.useRef(null)
47
+ const previousData = usePrevious(changeData)
48
+
49
+ const onRefresh = () => {
50
+ if (timer.current) {
51
+ clearTimeout(timer.current)
52
+ }
53
+
54
+ setRefreshing(true)
55
+
56
+ props.onRefresh()
57
+
58
+ timer.current = setTimeout(() => {
59
+ setRefreshing(false)
60
+ }, refreshTimeout)
61
+ }
62
+ onUpdate(() => {
63
+ if (refreshing && !deepEqual(previousData, changeData)) {
64
+ setRefreshing(false)
65
+ if (timer.current) {
66
+ clearTimeout(timer.current)
67
+ }
68
+ }
69
+ }, [refreshing, changeData])
70
+ const { Theme } = useCodeleapContext()
71
+
72
+ const variantStyles = useDefaultComponentStyle('View', {
73
+ variants,
74
+ })
75
+
76
+ const renderSeparator = () => {
77
+ return (
78
+ <View variants={['separator']}></View>
79
+ )
80
+ }
81
+
82
+ const separatorProp = props.separators
83
+ const isEmpty = !props.data || !props.data.length
84
+ const separator = !isEmpty && separatorProp == true && renderSeparator
85
+
86
+ return (
87
+ <KeyboardAwareSectionList
88
+ style={[Theme.presets.full, style]}
89
+ contentContainerStyle={[variantStyles.wrapper]}
90
+ ref={ref as unknown as SectionList}
91
+ ItemSeparatorComponent={separator}
92
+ {...props}
93
+ refreshControl={
94
+ hasRefresh && (
95
+ <RefreshControl refreshing={refreshing} onRefresh={onRefresh} />
96
+ )
97
+ }
98
+ />
99
+ )
100
+ },
101
+ )
@@ -1,184 +1,195 @@
1
- import { IconPlaceholder, useBooleanToggle, getNestedStylesByKey, useDefaultComponentStyle, TypeGuards } from '@codeleap/common'
2
- import React, { useMemo } from 'react'
3
- import { Modal, StyleSheet } from 'react-native'
4
- import { Button } from '../Button'
5
- import { Scroll } from '../Scroll'
6
-
7
- import { InputLabel, TextInput } from '../TextInput'
8
- import { Touchable } from '../Touchable'
9
- import { AnimatedView, View } from '../View'
10
- import { MobileSelectStyles } from './styles'
11
- import { CustomSelectProps } from './types'
12
-
13
- export const Select = <T extends string|number = string>(selectProps:CustomSelectProps<T>) => {
14
- const {
15
- value,
16
- onValueChange,
17
- label,
18
- styles = {},
19
- options,
20
- style,
21
- variants,
22
- renderItem,
23
- closeOnSelect = true,
24
- scroll = false,
25
- showClose = true,
26
- showLabelOnModal = true,
27
- placeholder = 'Select',
28
- arrowIconName = 'selectArrow',
29
- footer,
30
- modalCloseIconName = 'close',
31
- header,
32
- closeButtonProps,
33
- modalLabel,
34
- ...props
35
- } = selectProps
36
-
37
- const [isModalVisible, setModalVisibility] = useBooleanToggle(false)
38
-
39
- const variantStyles = useDefaultComponentStyle<'u:MobileSelect', typeof MobileSelectStyles>('u:MobileSelect', {
40
- transform: StyleSheet.flatten,
41
- rootElement: 'inputWrapper',
42
- styles,
43
- variants,
44
- })
45
-
46
- const inputStyles = useMemo(
47
- () => getNestedStylesByKey('input', variantStyles),
48
- [variantStyles],
49
- )
50
-
51
- const closeButtonStyles = useMemo(
52
- () => getNestedStylesByKey('modalCloseButton', variantStyles),
53
- [variantStyles],
54
- )
55
-
56
- const ListComponent = scroll ? Scroll : View
57
-
58
- const close = () => setModalVisibility()
59
- const select = (value) => {
60
-
61
- onValueChange(value)
62
- if (closeOnSelect) {
63
- close()
64
- }
65
- }
66
-
67
- const selectedLabel:string = useMemo(() => {
68
- const current = options.find(o => o.value === value)
69
-
70
- const display = current?.label ?? placeholder
71
-
72
- return TypeGuards.isString(display) ? display : ''
73
- }, [value, placeholder, options])
74
-
75
- return <>
76
- <TextInput
77
-
78
- caretHidden
79
- value={selectedLabel}
80
- rightIcon={{
81
- name: arrowIconName as IconPlaceholder,
82
- }}
83
- editable={false}
84
- touchableWrapper
85
- innerWrapperProps={{
86
- debugName: 'Select',
87
- onPress: close,
88
- }}
89
- label={label}
90
- debugName={'Select input'}
91
- styles={inputStyles}
92
- style={style}
93
- {...props}
94
- />
95
- <AnimatedView pointerEvents={'none'} transition='opacity' style={[
96
- {
97
- position: 'absolute',
98
- top: 0,
99
- right: 0,
100
- left: 0,
101
- bottom: 0,
102
- },
103
- variantStyles.backdrop,
104
- isModalVisible ? variantStyles['backdrop:visible'] : variantStyles['backdrop:hidden'],
105
- ]} />
106
-
107
- <Modal
108
- animationType='slide'
109
- transparent={true}
110
- visible={isModalVisible}
111
- onRequestClose={() => {
112
- setModalVisibility()
113
- }}
114
- pointerEvents={isModalVisible ? 'auto' : 'none'}
115
- >
116
- <Touchable
117
- onPress={close}
118
- style={{
119
- position: 'absolute',
120
- top: 0,
121
- right: 0,
122
- left: 0,
123
- bottom: 0,
124
- }}
125
- debugName={`Close modal`}
126
- />
127
- <View style={variantStyles.modalWrapper}>
128
-
129
- <View style={variantStyles.modalBox}>
130
- {
131
- (showClose || showLabelOnModal || header) && (
132
- <View style={variantStyles.modalHeader}>
133
- {
134
- header ? header : <>
135
- {showLabelOnModal && <InputLabel label={modalLabel || label} style={variantStyles.modalLabelText}/>}
136
- {showClose && <Button
137
- icon={modalCloseIconName as IconPlaceholder}
138
- onPress={close}
139
- styles={closeButtonStyles}
140
- debugName={'Close modal'}
141
- {...closeButtonProps}
142
- />}
143
- </>
144
- }
145
- </View>
146
- )
147
- }
148
- <ListComponent style={variantStyles.modalList}>
149
- {
150
- options.map((item, idx) => {
151
- const isSelected = value === item.value
152
- if (renderItem) {
153
- return renderItem({
154
- ...item,
155
- selected: isSelected,
156
- onPress: close,
157
- styles: variantStyles,
158
-
159
- })
160
- }
161
-
162
- return <Touchable key={idx} style={[
163
- variantStyles.modalItem,
164
- isSelected && variantStyles['modalItem:selected'],
165
- ]} onPress={() => select(item.value)} debugName={`Select ${item.value}`}>
166
- <InputLabel label={item.label} style={[variantStyles.modalItemText, isSelected && variantStyles['modalItemText:selected']]}/>
167
- </Touchable>
168
- })
169
- }
170
- </ListComponent>
171
-
172
- {
173
- footer && <View style={variantStyles.modalFooter}>
174
- {footer}
175
- </View>
176
- }
177
- </View>
178
- </View>
179
- </Modal>
180
- </>
181
- }
182
-
183
- export * from './styles'
184
- export * from './types'
1
+ import { IconPlaceholder, useBooleanToggle, getNestedStylesByKey, useDefaultComponentStyle, TypeGuards } from '@codeleap/common'
2
+ import React, { useMemo } from 'react'
3
+ import { Modal, StyleSheet } from 'react-native'
4
+ import { Button } from '../Button'
5
+ import { Scroll } from '../Scroll'
6
+ import { InputLabel, TextInput } from '../TextInput'
7
+ import { Touchable } from '../Touchable'
8
+ import { AnimatedView, View } from '../View'
9
+ import { MobileSelectStyles } from './styles'
10
+ import { CustomSelectProps } from './types'
11
+
12
+ export const Select = <T extends string|number = string>(selectProps:CustomSelectProps<T>) => {
13
+ const {
14
+ value,
15
+ onValueChange,
16
+ label,
17
+ styles = {},
18
+ options,
19
+ style,
20
+ variants,
21
+ renderItem,
22
+ closeOnSelect = true,
23
+ scroll = false,
24
+ showClose = true,
25
+ showLabelOnModal = true,
26
+ placeholder = 'Select',
27
+ arrowIconName = 'selectArrow',
28
+ footer,
29
+ modalCloseIconName = 'close',
30
+ header,
31
+ closeButtonProps,
32
+ modalLabel,
33
+ textInputProps = {},
34
+ visible = null,
35
+ toggle = null,
36
+ renderList,
37
+ ...props
38
+ } = selectProps
39
+
40
+ const [_isModalVisible, _setModalVisibility] = useBooleanToggle(false)
41
+
42
+ const isModalVisible = visible ?? _isModalVisible
43
+ const setModalVisibility = toggle ?? _setModalVisibility
44
+
45
+ const variantStyles = useDefaultComponentStyle<'u:MobileSelect', typeof MobileSelectStyles>('u:MobileSelect', {
46
+ transform: StyleSheet.flatten,
47
+ rootElement: 'inputWrapper',
48
+ styles,
49
+ variants,
50
+ })
51
+
52
+ const inputStyles = useMemo(
53
+ () => getNestedStylesByKey('input', variantStyles),
54
+ [variantStyles],
55
+ )
56
+
57
+ const closeButtonStyles = useMemo(
58
+ () => getNestedStylesByKey('modalCloseButton', variantStyles),
59
+ [variantStyles],
60
+ )
61
+
62
+ const ListComponent = scroll ? Scroll : View
63
+
64
+ const close = () => setModalVisibility()
65
+ const select = (value) => {
66
+
67
+ onValueChange(value)
68
+ if (closeOnSelect) {
69
+ close()
70
+ }
71
+ }
72
+
73
+ const selectedLabel:string = useMemo(() => {
74
+ const current = options.find(o => o.value === value)
75
+
76
+ const display = current?.label ?? placeholder
77
+
78
+ return TypeGuards.isString(display) ? display : ''
79
+ }, [value, placeholder, options])
80
+
81
+ return <>
82
+ <TextInput
83
+
84
+ caretHidden
85
+ value={selectedLabel}
86
+ rightIcon={{
87
+ name: arrowIconName as IconPlaceholder,
88
+ }}
89
+ editable={false}
90
+ touchableWrapper
91
+ innerWrapperProps={{
92
+ debugName: 'Select',
93
+ onPress: close,
94
+ }}
95
+ pointerEvents={'none'}
96
+ label={label}
97
+ debugName={'Select input'}
98
+ styles={inputStyles}
99
+ style={style}
100
+ {...textInputProps}
101
+ />
102
+ <AnimatedView pointerEvents={'none'} transition='opacity' style={[
103
+ {
104
+ position: 'absolute',
105
+ top: 0,
106
+ right: 0,
107
+ left: 0,
108
+ bottom: 0,
109
+ },
110
+ variantStyles.backdrop,
111
+ isModalVisible ? variantStyles['backdrop:visible'] : variantStyles['backdrop:hidden'],
112
+ ]} />
113
+
114
+ <Modal
115
+ animationType='slide'
116
+ transparent={true}
117
+ visible={isModalVisible}
118
+ onRequestClose={() => {
119
+ setModalVisibility()
120
+ }}
121
+ pointerEvents={isModalVisible ? 'auto' : 'none'}
122
+ >
123
+ <Touchable
124
+ onPress={close}
125
+ style={{
126
+ position: 'absolute',
127
+ top: 0,
128
+ right: 0,
129
+ left: 0,
130
+ bottom: 0,
131
+ }}
132
+ debugName={`Close modal`}
133
+ />
134
+ <View style={variantStyles.modalWrapper}>
135
+
136
+ <View style={variantStyles.modalBox}>
137
+ {
138
+ (showClose || showLabelOnModal || header) && (
139
+ <View style={variantStyles.modalHeader}>
140
+ {
141
+ header ? header : <>
142
+ {showLabelOnModal && <InputLabel label={modalLabel || label} style={variantStyles.modalLabelText}/>}
143
+ {showClose && <Button
144
+ icon={modalCloseIconName as IconPlaceholder}
145
+ onPress={close}
146
+ styles={closeButtonStyles}
147
+ debugName={'Close modal'}
148
+ {...closeButtonProps}
149
+ />}
150
+ </>
151
+ }
152
+ </View>
153
+ )
154
+ }
155
+ <ListComponent style={variantStyles.modalList}>
156
+ {
157
+ renderList ? renderList({
158
+ ...selectProps,
159
+ isEmpty: !options.length,
160
+
161
+ }) : options.map((item, idx) => {
162
+ const isSelected = value === item.value
163
+ if (renderItem) {
164
+ return renderItem({
165
+ ...item,
166
+ selected: isSelected,
167
+ onPress: close,
168
+ styles: variantStyles,
169
+
170
+ })
171
+ }
172
+
173
+ return <Touchable key={idx} style={[
174
+ variantStyles.modalItem,
175
+ isSelected && variantStyles['modalItem:selected'],
176
+ ]} onPress={() => select(item.value)} debugName={`Select ${item.value}`}>
177
+ <InputLabel label={item.label} style={[variantStyles.modalItemText, isSelected && variantStyles['modalItemText:selected']]}/>
178
+ </Touchable>
179
+ })
180
+ }
181
+ </ListComponent>
182
+
183
+ {
184
+ footer && <View style={variantStyles.modalFooter}>
185
+ {footer}
186
+ </View>
187
+ }
188
+ </View>
189
+ </View>
190
+ </Modal>
191
+ </>
192
+ }
193
+
194
+ export * from './styles'
195
+ export * from './types'