@codeleap/mobile 3.25.0 → 3.25.3

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 (131) hide show
  1. package/package.json +4 -6
  2. package/src/components/ActionIcon/index.tsx +37 -55
  3. package/src/components/ActionIcon/styles.ts +4 -2
  4. package/src/components/ActivityIndicator/index.tsx +64 -42
  5. package/src/components/ActivityIndicator/styles.ts +10 -1
  6. package/src/components/Autocomplete/index.tsx +54 -46
  7. package/src/components/Autocomplete/styles.ts +5 -2
  8. package/src/components/Autocomplete/types.ts +23 -13
  9. package/src/components/Avatar/index.tsx +71 -59
  10. package/src/components/Avatar/styles.ts +9 -1
  11. package/src/components/AvatarGroup/index.tsx +44 -30
  12. package/src/components/AvatarGroup/styles.ts +6 -0
  13. package/src/components/Backdrop/index.tsx +34 -51
  14. package/src/components/Backdrop/styles.ts +10 -5
  15. package/src/components/Badge/index.tsx +62 -36
  16. package/src/components/Badge/styles.ts +11 -3
  17. package/src/components/Button/index.tsx +82 -55
  18. package/src/components/Button/styles.ts +14 -13
  19. package/src/components/Calendar/index.tsx +29 -35
  20. package/src/components/Calendar/style.ts +6 -0
  21. package/src/components/Checkbox/index.tsx +64 -43
  22. package/src/components/Checkbox/styles.ts +6 -1
  23. package/src/components/ContentView/index.tsx +63 -0
  24. package/src/components/ContentView/styles.ts +8 -0
  25. package/src/components/DatePickerModal/index.tsx +65 -50
  26. package/src/components/DatePickerModal/styles.ts +10 -9
  27. package/src/components/DatePickerModal/types.ts +54 -36
  28. package/src/components/Drawer/index.tsx +28 -0
  29. package/src/components/Drawer/styles.ts +8 -0
  30. package/src/components/EmptyPlaceholder/index.tsx +63 -40
  31. package/src/components/EmptyPlaceholder/styles.ts +5 -0
  32. package/src/components/FileInput/index.tsx +49 -11
  33. package/src/components/FileInput/styles.ts +8 -0
  34. package/src/components/Grid/index.tsx +116 -84
  35. package/src/components/Grid/styles.ts +5 -0
  36. package/src/components/Icon/index.tsx +79 -44
  37. package/src/components/Icon/styles.ts +6 -0
  38. package/src/components/Image/index.tsx +78 -58
  39. package/src/components/Image/styles.ts +6 -1
  40. package/src/components/ImageView/Spotlight.tsx +4 -1
  41. package/src/components/ImageView/component.tsx +2 -1
  42. package/src/components/InputBase/index.tsx +24 -33
  43. package/src/components/InputBase/styles.ts +75 -66
  44. package/src/components/InputBase/types.ts +4 -3
  45. package/src/components/InputBase/utils.ts +4 -6
  46. package/src/components/InputLabel/index.tsx +38 -0
  47. package/src/components/InputLabel/styles.ts +7 -0
  48. package/src/components/List/PaginationIndicator.tsx +54 -0
  49. package/src/components/List/index.tsx +151 -99
  50. package/src/components/List/styles.ts +6 -0
  51. package/src/components/LoadingOverlay/index.tsx +29 -42
  52. package/src/components/LoadingOverlay/styles.ts +7 -7
  53. package/src/components/Modal/index.tsx +127 -80
  54. package/src/components/Modal/styles.ts +8 -0
  55. package/src/components/Navigation/Navigation.tsx +0 -1
  56. package/src/components/Navigation/types.ts +9 -2
  57. package/src/components/NumberIncrement/index.tsx +60 -50
  58. package/src/components/NumberIncrement/styles.ts +5 -0
  59. package/src/components/NumberIncrement/types.ts +39 -32
  60. package/src/components/Pager/index.tsx +94 -42
  61. package/src/components/Pager/styles.ts +13 -1
  62. package/src/components/RadioInput/index.tsx +57 -32
  63. package/src/components/RadioInput/styles.ts +7 -5
  64. package/src/components/RefreshControl/index.tsx +19 -39
  65. package/src/components/RefreshControl/styles.ts +6 -1
  66. package/src/components/Scroll/index.tsx +105 -89
  67. package/src/components/Scroll/styles.ts +5 -0
  68. package/src/components/Sections/index.tsx +161 -111
  69. package/src/components/Sections/styles.ts +5 -0
  70. package/src/components/SegmentedControl/Option.tsx +31 -46
  71. package/src/components/SegmentedControl/index.tsx +121 -86
  72. package/src/components/SegmentedControl/styles.ts +22 -15
  73. package/src/components/Select/index.tsx +82 -71
  74. package/src/components/Select/styles.ts +5 -3
  75. package/src/components/Select/types.ts +25 -20
  76. package/src/components/Slider/index.tsx +43 -58
  77. package/src/components/Slider/styles.ts +6 -15
  78. package/src/components/Slider/types.ts +14 -9
  79. package/src/components/Switch/index.tsx +56 -43
  80. package/src/components/Switch/styles.ts +7 -1
  81. package/src/components/Text/index.tsx +52 -56
  82. package/src/components/Text/styles.ts +7 -1
  83. package/src/components/TextInput/index.tsx +162 -49
  84. package/src/components/TextInput/styles.ts +8 -2
  85. package/src/components/Touchable/index.tsx +87 -44
  86. package/src/components/Touchable/styles.ts +9 -0
  87. package/src/components/View/index.tsx +92 -23
  88. package/src/components/View/styles.ts +6 -0
  89. package/src/components/components.ts +6 -2
  90. package/src/components/defaultStyles.ts +77 -0
  91. package/src/index.ts +0 -2
  92. package/src/modules/PressableRipple/type.ts +0 -1
  93. package/src/utils/KeyboardAware/context.tsx +2 -0
  94. package/src/utils/KeyboardAware/keyboardHooks.ts +2 -1
  95. package/src/utils/ModalManager/components.tsx +30 -1
  96. package/src/utils/ModalManager/context.tsx +4 -4
  97. package/src/utils/ModalManager/index.ts +4 -1
  98. package/src/utils/hooks.ts +1 -12
  99. package/src/Registry.ts +0 -52
  100. package/src/components/ActionIcon/types.ts +0 -15
  101. package/src/components/ActivityIndicator/types.ts +0 -9
  102. package/src/components/Avatar/types.ts +0 -23
  103. package/src/components/AvatarGroup/types.ts +0 -10
  104. package/src/components/Backdrop/types.ts +0 -14
  105. package/src/components/Badge/types.ts +0 -27
  106. package/src/components/Button/types.ts +0 -20
  107. package/src/components/Checkbox/types.ts +0 -13
  108. package/src/components/EmptyPlaceholder/types.ts +0 -21
  109. package/src/components/FileInput/types.ts +0 -27
  110. package/src/components/Grid/types.ts +0 -20
  111. package/src/components/Icon/types.ts +0 -15
  112. package/src/components/Image/types.ts +0 -18
  113. package/src/components/List/types.ts +0 -41
  114. package/src/components/LoadingOverlay/types.ts +0 -9
  115. package/src/components/Modal/types.ts +0 -41
  116. package/src/components/Pager/types.ts +0 -37
  117. package/src/components/PaginationIndicator/index.tsx +0 -51
  118. package/src/components/PaginationIndicator/styles.ts +0 -3
  119. package/src/components/PaginationIndicator/types.ts +0 -10
  120. package/src/components/RadioInput/types.ts +0 -31
  121. package/src/components/RefreshControl/types.ts +0 -9
  122. package/src/components/Scroll/types.ts +0 -21
  123. package/src/components/SearchInput/index.tsx +0 -90
  124. package/src/components/Sections/types.ts +0 -39
  125. package/src/components/SegmentedControl/types.ts +0 -31
  126. package/src/components/Switch/types.ts +0 -12
  127. package/src/components/Text/types.ts +0 -18
  128. package/src/components/TextInput/types.ts +0 -23
  129. package/src/components/Touchable/types.ts +0 -27
  130. package/src/components/View/types.ts +0 -13
  131. package/src/hooks/index.ts +0 -13
@@ -1,27 +1,86 @@
1
- import React, { useCallback, useRef } from 'react'
2
- import { onUpdate, TypeGuards } from '@codeleap/common'
3
- import { AnyRecord, IJSX, StyledComponentProps } from '@codeleap/styles'
4
- import { Dimensions, ScrollView } from 'react-native'
5
- import { MobileStyleRegistry } from '../../Registry'
1
+ import {
2
+ AnyFunction,
3
+ ComponentVariants,
4
+ onUpdate,
5
+ TypeGuards,
6
+ useDefaultComponentStyle,
7
+ useWarning,
8
+ } from '@codeleap/common'
9
+ import React, { ReactNode, useCallback, useRef } from 'react'
10
+ import {
11
+ Dimensions,
12
+ NativeScrollEvent,
13
+ NativeSyntheticEvent,
14
+ ScrollView,
15
+ ScrollViewProps,
16
+ StyleSheet,
17
+ } from 'react-native'
18
+ import { StylesOf } from '../../types/utility'
6
19
  import { View } from '../View'
7
- import { PageProps, PagerProps, ScrollEvent } from './types'
8
- import { useStylesFor } from '../../hooks'
9
-
20
+ import { PagerPresets, PagerComposition } from './styles'
10
21
  export * from './styles'
11
- export * from './types'
22
+
23
+ export type PageProps = {
24
+ isLast: boolean
25
+ isFirst: boolean
26
+ isActive: boolean
27
+ isNext: boolean
28
+ page: number
29
+ index: number
30
+ isPrevious: boolean
31
+ }
32
+
33
+ type ScrollEvent = NativeSyntheticEvent<NativeScrollEvent>
34
+
35
+ export type PagerProps = React.PropsWithChildren<{
36
+ variants?: ComponentVariants<typeof PagerPresets>['variants']
37
+ styles?: StylesOf<PagerComposition>
38
+ children?: (((pageData: PageProps) => ReactNode) | ReactNode)[]
39
+ page?: number
40
+ style?: any
41
+ setPage?: (page: number) => void
42
+ returnEarly?: boolean
43
+ renderPageWrapper?: React.FC<PageProps>
44
+ pageWrapperProps?: any
45
+ width?: number
46
+ onScroll?: (event: ScrollEvent, args: { isLeft?: boolean; isRight?: boolean; x?: number }) => void
47
+ /** If TRUE render page, nextPage and prevPage only */
48
+ windowing?: boolean
49
+ scrollRightEnabled?: boolean
50
+ scrollLeftEnabled?: boolean
51
+ scrollDirectionThrottle?: number
52
+ onSwipeLastPage?: (event: ScrollEvent) => void
53
+ waitEventDispatchTimeout?: number
54
+ } & ScrollViewProps>
55
+
56
+ const defaultProps: Partial<PagerProps> = {
57
+ variants: [],
58
+ styles: {},
59
+ page: 0,
60
+ returnEarly: true,
61
+ windowing: false,
62
+ keyboardShouldPersistTaps: 'handled',
63
+ scrollEnabled: true,
64
+ scrollRightEnabled: true,
65
+ scrollLeftEnabled: true,
66
+ scrollDirectionThrottle: 650,
67
+ waitEventDispatchTimeout: 250,
68
+ }
12
69
 
13
70
  export const Pager = (pagerProps: PagerProps) => {
14
71
  const {
72
+ styles,
73
+ variants,
15
74
  width: widthProp,
16
75
  page,
17
- style,
18
- returnEarly,
76
+ style = {},
77
+ returnEarly = true,
19
78
  renderPageWrapper,
20
79
  pageWrapperProps = {},
21
80
  children,
22
- windowing,
81
+ windowing = false,
23
82
  setPage,
24
- scrollEnabled,
83
+ scrollEnabled = true,
25
84
  scrollLeftEnabled,
26
85
  scrollRightEnabled,
27
86
  onScroll,
@@ -29,7 +88,7 @@ export const Pager = (pagerProps: PagerProps) => {
29
88
  onSwipeLastPage,
30
89
  waitEventDispatchTimeout,
31
90
  } = {
32
- ...Pager.defaultProps,
91
+ ...defaultProps,
33
92
  ...pagerProps,
34
93
  }
35
94
 
@@ -38,14 +97,20 @@ export const Pager = (pagerProps: PagerProps) => {
38
97
  const [positionX, setPositionX] = React.useState(0)
39
98
  const [scrollPositionX, setScrollPositionX] = React.useState(0)
40
99
  const [_scrollEnabled, setScrollEnabled] = React.useState(true)
100
+
41
101
  const waitEventDispatch = useRef(false)
42
102
 
43
- const styles = useStylesFor(Pager.styleRegistryName, style)
103
+ const variantStyles = useDefaultComponentStyle<'u:Pager', typeof PagerPresets>(
104
+ 'u:Pager',
105
+ {
106
+ styles,
107
+ transform: StyleSheet.flatten,
108
+ variants,
109
+ },
110
+ )
44
111
 
45
112
  const windowWidth = Dimensions.get('window').width
46
-
47
- // @ts-expect-error
48
- let width = widthProp ?? styles?.wrapper?.width
113
+ let width = widthProp ?? variantStyles.wrapper.width
49
114
 
50
115
  const validWidth = TypeGuards.isNumber(width)
51
116
 
@@ -53,6 +118,12 @@ export const Pager = (pagerProps: PagerProps) => {
53
118
  width = windowWidth
54
119
  }
55
120
 
121
+ useWarning(
122
+ !validWidth,
123
+ 'Pager',
124
+ 'provided width is not a number, using default width',
125
+ )
126
+
56
127
  const nChildren = React.Children.count(children)
57
128
 
58
129
  const lastPage = nChildren - 1
@@ -63,7 +134,7 @@ export const Pager = (pagerProps: PagerProps) => {
63
134
 
64
135
  const handleScrollEnd = useCallback((event: ScrollEvent) => {
65
136
  if (!scrollEnabled) return null
66
-
137
+
67
138
  if (waitEventDispatch.current === true) return null
68
139
 
69
140
  waitEventDispatch.current = true
@@ -142,12 +213,13 @@ export const Pager = (pagerProps: PagerProps) => {
142
213
  onMomentumScrollEnd={handleScrollEnd}
143
214
  scrollEventThrottle={hasScrollDirectionDisabled ? 2000 : 300}
144
215
  showsHorizontalScrollIndicator={false}
216
+ style={[variantStyles.wrapper, style]}
145
217
  {...pagerProps}
146
- style={styles?.wrapper}
147
218
  onScroll={handleScroll}
148
219
  scrollEnabled={childArr.length > 1 && scrollEnabled && _scrollEnabled}
149
220
  >
150
221
  {childArr.map((child: PagerProps['children'][number], index) => {
222
+
151
223
  const isActive = index === page
152
224
  const isLast = index === lastPage
153
225
  const isFirst = index === 0
@@ -174,8 +246,8 @@ export const Pager = (pagerProps: PagerProps) => {
174
246
 
175
247
  const wrapperProps = {
176
248
  key: index,
249
+ style: [{ height: '100%', width }, variantStyles.page],
177
250
  ...pageWrapperProps,
178
- style: [{ height: '100%', width }, styles?.page],
179
251
  }
180
252
 
181
253
  return <WrapperComponent {...wrapperProps}>{content}</WrapperComponent>
@@ -184,24 +256,4 @@ export const Pager = (pagerProps: PagerProps) => {
184
256
  )
185
257
  }
186
258
 
187
- Pager.styleRegistryName = 'Pager'
188
- Pager.elements = ['page', 'wrapper']
189
- Pager.rootElement = 'wrapper'
190
-
191
- Pager.withVariantTypes = <S extends AnyRecord>(styles: S) => {
192
- return Pager as (props: StyledComponentProps<PagerProps, typeof styles>) => IJSX
193
- }
194
-
195
- Pager.defaultProps = {
196
- page: 0,
197
- returnEarly: true,
198
- windowing: false,
199
- keyboardShouldPersistTaps: 'handled',
200
- scrollEnabled: true,
201
- scrollRightEnabled: true,
202
- scrollLeftEnabled: true,
203
- scrollDirectionThrottle: 650,
204
- waitEventDispatchTimeout: 250,
205
- } as Partial<PagerProps>
206
-
207
- MobileStyleRegistry.registerComponent(Pager)
259
+ Pager.defaultProps = defaultProps
@@ -1,2 +1,14 @@
1
+ import {
2
+ createDefaultVariantFactory,
3
+ includePresets,
4
+ } from '@codeleap/common'
5
+
6
+
7
+ export type PagerComposition =
8
+ | 'page'
9
+ | 'wrapper'
10
+
11
+ const createPagerStyle = createDefaultVariantFactory<PagerComposition>()
12
+
13
+ export const PagerPresets = includePresets((style) => createPagerStyle(() => ({ wrapper: style })))
1
14
 
2
- export type PagerComposition = 'page' | 'wrapper'
@@ -1,18 +1,50 @@
1
1
  import React from 'react'
2
+ import { ReactNode, ComponentPropsWithoutRef } from 'react'
3
+
2
4
  import { Text } from '../Text'
3
5
  import { Touchable } from '../Touchable'
4
- import { TypeGuards } from '@codeleap/common'
6
+ import {
7
+ ComponentVariants,
8
+ FormTypes,
9
+ getNestedStylesByKey,
10
+ StylesOf,
11
+ TypeGuards,
12
+ useDefaultComponentStyle,
13
+ } from '@codeleap/common'
5
14
  import { View } from '../View'
6
- import { InputBase, selectInputBaseProps } from '../InputBase'
7
- import { RadioGroupProps, RadioOptionProps } from './types'
8
- import { AnyRecord, IJSX, StyledComponentProps } from '@codeleap/styles'
9
- import { MobileStyleRegistry } from '../../Registry'
10
- import { useStylesFor } from '../../hooks'
11
-
15
+ import { RadioInputComposition, RadioInputPresets } from './styles'
16
+ import { InputLabel } from '../InputLabel'
17
+ import { StyleSheet } from 'react-native'
18
+ import { InputBase, InputBaseDefaultOrder, InputBaseProps, selectInputBaseProps } from '../InputBase'
12
19
  export * from './styles'
13
- export * from './types'
14
20
 
15
- const Option = <T extends string | number>(props: RadioOptionProps<T>) => {
21
+ type WrapperProps = InputBaseProps
22
+
23
+ type RadioOption<T> = FormTypes.Options<T>[number] & {
24
+ disabled?: boolean
25
+ }
26
+ export type RadioGroupProps<T extends string|number> = WrapperProps & {
27
+ options: RadioOption<T>[]
28
+ value: T
29
+ onValueChange(value: T): void
30
+ label: ReactNode
31
+ styles?: StylesOf<RadioInputComposition>
32
+ variants?: ComponentVariants<typeof RadioInputPresets>['variants']
33
+ radioOnRight?: boolean
34
+ }
35
+
36
+ type OptionProps<T extends string|number> = {
37
+ item: RadioOption<T>
38
+ selected: boolean
39
+ onSelect(): void
40
+ styles?: StylesOf<RadioInputComposition>
41
+ debugName?: string
42
+ disabled?: boolean
43
+ separator?: boolean
44
+ reverseOrder?: boolean
45
+ }
46
+
47
+ const Option = <T extends string|number>(props: OptionProps<T>) => {
16
48
  const {
17
49
  debugName,
18
50
  item,
@@ -58,6 +90,7 @@ const Option = <T extends string | number>(props: RadioOptionProps<T>) => {
58
90
  onPress={onSelect}
59
91
  disabled={isDisabled}
60
92
  >
93
+
61
94
  {reverseOrder ? (
62
95
  <>
63
96
  {label}
@@ -95,38 +128,41 @@ const Option = <T extends string | number>(props: RadioOptionProps<T>) => {
95
128
  )}
96
129
 
97
130
  </Touchable>
98
- {separator ? <View style={styles.optionSeparator} /> : null}
131
+ {separator && <View style={styles.optionSeparator} />}
99
132
  </>
100
133
  }
101
134
 
102
- export const RadioGroup = <T extends string | number>(props: RadioGroupProps<T>) => {
135
+ export const RadioGroup = <T extends string|number>(
136
+ props: RadioGroupProps<T>,
137
+ ) => {
103
138
  const {
104
139
  inputBaseProps,
105
140
  others,
106
- } = selectInputBaseProps({
107
- ...RadioGroup.defaultProps,
108
- ...props,
109
- })
141
+ } = selectInputBaseProps(props)
110
142
 
111
143
  const {
112
144
  options,
113
145
  value,
114
146
  onValueChange,
147
+ variants,
148
+ styles,
115
149
  disabled,
116
150
  debugName,
117
151
  radioOnRight,
118
- style,
119
152
  } = others
120
153
 
121
- const styles = useStylesFor(RadioGroup.styleRegistryName, style)
154
+ const variantStyles = useDefaultComponentStyle<'u:RadioInput', typeof RadioInputPresets>('u:RadioInput', {
155
+ variants,
156
+ styles,
157
+ transform: StyleSheet.flatten,
158
+ })
122
159
 
123
- // @ts-expect-error icss type
124
- const _radioOnRight = radioOnRight ?? styles?.__props?.radioOnRight
160
+ const _radioOnRight = radioOnRight ?? variantStyles.__props?.radioOnRight
125
161
 
126
162
  return <InputBase
127
163
  {...inputBaseProps}
128
164
  disabled={disabled}
129
- style={styles}
165
+ styles={variantStyles}
130
166
  debugName={debugName}
131
167
  >
132
168
  {options?.map((item, idx) => (
@@ -135,7 +171,7 @@ export const RadioGroup = <T extends string | number>(props: RadioGroupProps<T>)
135
171
  item={item}
136
172
  key={idx}
137
173
  disabled={disabled}
138
- styles={styles}
174
+ styles={variantStyles}
139
175
  selected={value === item.value}
140
176
  onSelect={() => onValueChange(item.value)}
141
177
  separator={idx < options.length - 1}
@@ -143,16 +179,5 @@ export const RadioGroup = <T extends string | number>(props: RadioGroupProps<T>)
143
179
  />
144
180
  ))}
145
181
  </InputBase>
146
- }
147
-
148
- RadioGroup.styleRegistryName = 'RadioGroup'
149
- RadioGroup.elements = [...InputBase.elements, 'option', '__props']
150
- RadioGroup.rootElement = 'wrapper'
151
182
 
152
- RadioGroup.withVariantTypes = <S extends AnyRecord>(styles: S) => {
153
- return RadioGroup as (<T extends string | number>(props: StyledComponentProps<RadioGroupProps<T>, typeof styles>) => IJSX)
154
183
  }
155
-
156
- RadioGroup.defaultProps = {} as Partial<RadioGroupProps<string | number>>
157
-
158
- MobileStyleRegistry.registerComponent(RadioGroup)
@@ -1,3 +1,4 @@
1
+ import { createDefaultVariantFactory, includePresets } from '@codeleap/common'
1
2
  import { IconLessInputBaseParts } from '../InputBase'
2
3
 
3
4
  type OptionParts = 'wrapper' | 'label' | 'indicator' | 'indicatorInner' | 'separator'
@@ -5,8 +6,9 @@ type OptionStates = 'selected' | 'disabled' | 'selectedDisabled'
5
6
 
6
7
  type OptionComposition = `${OptionParts}:${OptionStates}` | OptionParts
7
8
 
8
- export type RadioInputComposition =
9
- IconLessInputBaseParts |
10
- `${IconLessInputBaseParts}:disabled` |
11
- `option${Capitalize<OptionComposition>}` |
12
- '__props'
9
+ export type RadioInputComposition = IconLessInputBaseParts | `${IconLessInputBaseParts}:disabled` | `option${Capitalize<OptionComposition>}` | '__props'
10
+
11
+ const createRadioStyle =
12
+ createDefaultVariantFactory<RadioInputComposition>()
13
+
14
+ export const RadioInputPresets = includePresets(style => createRadioStyle(() => ({ wrapper: style })))
@@ -1,48 +1,28 @@
1
- import React from 'react'
2
- import { AnyRecord, IJSX, StyledComponentProps } from '@codeleap/styles'
3
- import { RefreshControl as RNRefreshControl } from 'react-native'
4
- import { MobileStyleRegistry } from '../../Registry'
5
- import { RefreshControlProps } from './types'
6
- import { useStylesFor } from '../../hooks'
7
- import { ColorValue } from 'react-native'
1
+ import { ComponentVariants, StylesOf, useDefaultComponentStyle } from '@codeleap/common'
2
+ import { RefreshControl as RNRefreshControl, RefreshControlProps as RNRefreshControlProps } from 'react-native'
3
+ import { RefreshControlComposition, RefreshControlPresets } from './styles'
8
4
 
9
- export * from './styles'
10
- export * from './types'
11
-
12
- export const RefreshControl = (props: RefreshControlProps) => {
13
- const {
14
- style,
15
- ...rest
16
- } = {
17
- ...RefreshControl.defaultProps,
18
- ...props,
19
- }
20
-
21
- const styles = useStylesFor(RefreshControl.styleRegistryName, style)
5
+ export type RefreshControlProps = {
6
+ styles?: StylesOf<RefreshControlComposition>
7
+ } & RNRefreshControlProps & ComponentVariants<typeof RefreshControlPresets>
22
8
 
23
- const color: ColorValue = (styles?.loadingAnimation as AnyRecord)?.color
24
- const titleColor: ColorValue = (styles?.titleColor as AnyRecord)?.color
25
- const progressBackgroundColor: ColorValue = (styles?.progressBackgroundColor as AnyRecord)?.color
9
+ export const RefreshControl = (props:RefreshControlProps) => {
10
+ const { variants = [], styles } = props
26
11
 
12
+ const variantStyles = useDefaultComponentStyle<'u:RefreshControl', typeof RefreshControlPresets>('u:RefreshControl', {
13
+ variants,
14
+ styles,
15
+ })
27
16
  return (
28
17
  <RNRefreshControl
29
- colors={[color]}
30
- tintColor={color}
31
- progressBackgroundColor={progressBackgroundColor}
32
- titleColor={titleColor}
33
- {...rest}
18
+ colors={[variantStyles.loadingAnimation?.color]}
19
+ tintColor={variantStyles.loadingAnimation?.color}
20
+ progressBackgroundColor={variantStyles.progressBackgroundColor?.color}
21
+ titleColor={variantStyles.titleColor?.color}
22
+ {...props}
34
23
  />
35
- )
36
- }
37
24
 
38
- RefreshControl.styleRegistryName = 'RefreshControl'
39
- RefreshControl.elements = ['loadingAnimation', 'progressBackgroundColor', 'titleColor']
40
- RefreshControl.rootElement = 'wrapper'
41
-
42
- RefreshControl.withVariantTypes = <S extends AnyRecord>(styles: S) => {
43
- return RefreshControl as (props: StyledComponentProps<RefreshControlProps, typeof styles>) => IJSX
25
+ )
44
26
  }
45
27
 
46
- RefreshControl.defaultProps = {} as Partial<RefreshControlProps>
47
-
48
- MobileStyleRegistry.registerComponent(RefreshControl)
28
+ export * from './styles'
@@ -1,2 +1,7 @@
1
+ import { createDefaultVariantFactory, includePresets } from '@codeleap/common'
1
2
 
2
- export type RefreshControlComposition = 'loadingAnimation' | 'progressBackgroundColor' | 'titleColor'
3
+ export type RefreshControlComposition = 'loadingAnimation' |'progressBackgroundColor' | 'titleColor'
4
+
5
+ const createRefreshControlStyle = createDefaultVariantFactory<RefreshControlComposition>()
6
+
7
+ export const RefreshControlPresets = includePresets(style => createRefreshControlStyle(() => ({ loadingAnimation: style })))
@@ -1,104 +1,120 @@
1
- import React, { forwardRef, useState } from 'react'
2
- import { deepEqual, onUpdate, usePrevious } from '@codeleap/common'
3
- import { ScrollView } from 'react-native'
4
- import { RefreshControl } from '../RefreshControl'
5
- import { useKeyboardPaddingStyle } from '../../utils'
6
- import { ScrollProps, ScrollRef } from './types'
7
- import { AnyRecord, IJSX, StyledComponentProps, StyledComponentWithProps } from '@codeleap/styles'
8
- import { MobileStyleRegistry } from '../../Registry'
9
- import { useStylesFor } from '../../hooks'
10
-
11
- export * from './styles'
12
- export * from './types'
13
-
14
- export const Scroll = forwardRef<ScrollRef, ScrollProps>((scrollProps, ref) => {
15
- const {
16
- style,
17
- refreshTimeout,
18
- children,
19
- changeData,
20
- refreshControlProps = {},
21
- contentContainerStyle,
22
- keyboardAware,
23
- animated,
24
- ...props
25
- } = {
26
- ...Scroll.defaultProps,
27
- ...scrollProps,
1
+ import * as React from 'react'
2
+ import { forwardRef, useState } from 'react'
3
+ import {
4
+ deepEqual,
5
+ onUpdate,
6
+ useDefaultComponentStyle,
7
+ usePrevious,
8
+ } from '@codeleap/common'
9
+ import { ScrollView, StyleSheet } from 'react-native'
10
+ import { ViewProps } from '../View'
11
+ import { RefreshControl, RefreshControlProps } from '../RefreshControl'
12
+ import { ComponentWithDefaultProps, StylesOf } from '../../types'
13
+ import { ScrollComposition, ScrollPresets } from './styles'
14
+ import { GetKeyboardAwarePropsOptions, useKeyboardPaddingStyle } from '../../utils'
15
+ import { KeyboardAwareScrollView, KeyboardAwareScrollViewProps } from 'react-native-keyboard-aware-scroll-view'
16
+ import { useSoftInputState } from 'react-native-avoid-softinput'
17
+ import { useMemo } from 'react'
18
+ export type ScrollProps = KeyboardAwareScrollViewProps &
19
+ ViewProps & {
20
+ onRefresh?: () => void
21
+ refreshTimeout?: number
22
+ changeData?: any
23
+ keyboardAware?: boolean
24
+ refreshing?: boolean
25
+ styles?: StylesOf<ScrollComposition>
26
+ refreshControlProps?: Partial<RefreshControlProps>
27
+ debugName?: string
28
28
  }
29
29
 
30
- const hasRefresh = !!props.onRefresh
31
- const [refreshingState, setRefreshing] = useState(false)
32
- const refreshingDisplay = props.refreshing !== undefined ? props.refreshing : refreshingState
30
+ export type ScrollRef = KeyboardAwareScrollView
33
31
 
34
- const timer = React.useRef(null)
35
- const previousData = usePrevious(changeData)
32
+ const defaultProps: Partial<ScrollProps> = {
33
+ keyboardShouldPersistTaps: 'handled',
34
+ }
36
35
 
37
- const onRefresh = () => {
38
- if (timer.current) {
39
- clearTimeout(timer.current)
36
+ export const Scroll = forwardRef<ScrollRef, ScrollProps>(
37
+ (scrollProps, ref) => {
38
+ const {
39
+ variants = [],
40
+ style,
41
+ refreshTimeout = 3000,
42
+ children,
43
+ changeData,
44
+ styles = {},
45
+ refreshControlProps = {},
46
+ contentContainerStyle,
47
+ keyboardAware = true,
48
+ animated = true,
49
+ ...props
50
+ } = {
51
+ ...defaultProps,
52
+ ...scrollProps,
40
53
  }
54
+ const hasRefresh = !!props.onRefresh
55
+ const [refreshingState, setRefreshing] = useState(false)
56
+ const refreshingDisplay = props.refreshing !== undefined ? props.refreshing : refreshingState
41
57
 
42
- setRefreshing(true)
58
+ const timer = React.useRef(null)
59
+ const previousData = usePrevious(changeData)
43
60
 
44
- props.onRefresh()
45
-
46
- timer.current = setTimeout(() => {
47
- setRefreshing(false)
48
- }, refreshTimeout)
49
- }
50
-
51
- onUpdate(() => {
52
- if (refreshingDisplay && !deepEqual(previousData, changeData)) {
53
- setRefreshing(false)
61
+ const onRefresh = () => {
54
62
  if (timer.current) {
55
63
  clearTimeout(timer.current)
56
64
  }
57
- }
58
- }, [refreshingDisplay, changeData])
59
65
 
60
- const styles = useStylesFor(Scroll.styleRegistryName, style)
66
+ setRefreshing(true)
61
67
 
62
- const Component = ScrollView
68
+ props.onRefresh()
63
69
 
64
- const keyboardStyle = useKeyboardPaddingStyle([styles?.content, contentContainerStyle], keyboardAware)
65
-
66
- return (
67
- <Component
68
- showsVerticalScrollIndicator={false}
69
- // @ts-ignore
70
- ref={ref}
71
- refreshControl={
72
- hasRefresh && (
73
- <RefreshControl
74
- refreshing={refreshingDisplay}
75
- onRefresh={onRefresh}
76
- {...refreshControlProps}
77
- />
78
- )
70
+ timer.current = setTimeout(() => {
71
+ setRefreshing(false)
72
+ }, refreshTimeout)
73
+ }
74
+ onUpdate(() => {
75
+ if (refreshingDisplay && !deepEqual(previousData, changeData)) {
76
+ setRefreshing(false)
77
+ if (timer.current) {
78
+ clearTimeout(timer.current)
79
+ }
79
80
  }
80
- {...props}
81
- style={styles?.wrapper}
82
- contentContainerStyle={keyboardStyle}
83
- >
84
- {children}
85
- </Component>
86
- )
87
- }) as StyledComponentWithProps<ScrollProps>
88
-
89
- Scroll.styleRegistryName = 'Scroll'
90
- Scroll.elements = ['wrapper', 'content']
91
- Scroll.rootElement = 'wrapper'
92
-
93
- Scroll.withVariantTypes = <S extends AnyRecord>(styles: S) => {
94
- return Scroll as (props: StyledComponentProps<ScrollProps, typeof styles>) => IJSX
95
- }
96
-
97
- Scroll.defaultProps = {
98
- keyboardShouldPersistTaps: 'handled',
99
- refreshTimeout: 3000,
100
- keyboardAware: true,
101
- animated: true,
102
- } as Partial<ScrollProps>
81
+ }, [refreshingDisplay, changeData])
82
+
83
+ const variantStyles = useDefaultComponentStyle<'u:Scroll', typeof ScrollPresets>('u:Scroll', {
84
+ variants,
85
+ styles,
86
+ transform: StyleSheet.flatten,
87
+ rootElement: 'content',
88
+ })
89
+
90
+ const Component = ScrollView
91
+
92
+ const keyboardStyle = useKeyboardPaddingStyle([variantStyles.content, contentContainerStyle], keyboardAware)
93
+
94
+ return (
95
+ <Component
96
+ style={[variantStyles.wrapper, style]}
97
+ contentContainerStyle={keyboardStyle}
98
+ showsVerticalScrollIndicator={false}
99
+ // @ts-ignore
100
+ ref={ref}
101
+ refreshControl={
102
+ hasRefresh && (
103
+ <RefreshControl
104
+ refreshing={refreshingDisplay}
105
+ onRefresh={onRefresh}
106
+ {...refreshControlProps}
107
+ />
108
+ )
109
+ }
110
+ {...props}
111
+ >
112
+ {children}
113
+ </Component>
114
+ )
115
+ },
116
+ ) as unknown as ComponentWithDefaultProps<ScrollProps>
117
+
118
+ Scroll.defaultProps = defaultProps
103
119
 
104
- MobileStyleRegistry.registerComponent(Scroll)
120
+ export * from './styles'