@codeleap/mobile 3.25.0 → 3.25.2
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.
- package/package.json +4 -6
- package/src/components/ActionIcon/index.tsx +37 -55
- package/src/components/ActionIcon/styles.ts +4 -2
- package/src/components/ActivityIndicator/index.tsx +64 -42
- package/src/components/ActivityIndicator/styles.ts +10 -1
- package/src/components/Autocomplete/index.tsx +54 -46
- package/src/components/Autocomplete/styles.ts +5 -2
- package/src/components/Autocomplete/types.ts +23 -13
- package/src/components/Avatar/index.tsx +71 -59
- package/src/components/Avatar/styles.ts +9 -1
- package/src/components/AvatarGroup/index.tsx +44 -30
- package/src/components/AvatarGroup/styles.ts +6 -0
- package/src/components/Backdrop/index.tsx +34 -51
- package/src/components/Backdrop/styles.ts +10 -5
- package/src/components/Badge/index.tsx +62 -36
- package/src/components/Badge/styles.ts +11 -3
- package/src/components/Button/index.tsx +82 -55
- package/src/components/Button/styles.ts +14 -13
- package/src/components/Calendar/index.tsx +29 -35
- package/src/components/Calendar/style.ts +6 -0
- package/src/components/Checkbox/index.tsx +64 -43
- package/src/components/Checkbox/styles.ts +6 -1
- package/src/components/ContentView/index.tsx +63 -0
- package/src/components/ContentView/styles.ts +8 -0
- package/src/components/DatePickerModal/index.tsx +65 -50
- package/src/components/DatePickerModal/styles.ts +10 -9
- package/src/components/DatePickerModal/types.ts +54 -36
- package/src/components/Drawer/index.tsx +28 -0
- package/src/components/Drawer/styles.ts +8 -0
- package/src/components/EmptyPlaceholder/index.tsx +63 -40
- package/src/components/EmptyPlaceholder/styles.ts +5 -0
- package/src/components/FileInput/index.tsx +49 -11
- package/src/components/FileInput/styles.ts +8 -0
- package/src/components/Grid/index.tsx +116 -84
- package/src/components/Grid/styles.ts +5 -0
- package/src/components/Icon/index.tsx +79 -44
- package/src/components/Icon/styles.ts +6 -0
- package/src/components/Image/index.tsx +78 -58
- package/src/components/Image/styles.ts +6 -1
- package/src/components/ImageView/Spotlight.tsx +4 -1
- package/src/components/ImageView/component.tsx +2 -1
- package/src/components/InputBase/index.tsx +24 -33
- package/src/components/InputBase/styles.ts +75 -66
- package/src/components/InputBase/types.ts +4 -3
- package/src/components/InputBase/utils.ts +4 -6
- package/src/components/InputLabel/index.tsx +38 -0
- package/src/components/InputLabel/styles.ts +7 -0
- package/src/components/List/PaginationIndicator.tsx +54 -0
- package/src/components/List/index.tsx +151 -99
- package/src/components/List/styles.ts +6 -0
- package/src/components/LoadingOverlay/index.tsx +29 -42
- package/src/components/LoadingOverlay/styles.ts +7 -7
- package/src/components/Modal/index.tsx +127 -80
- package/src/components/Modal/styles.ts +8 -0
- package/src/components/Navigation/Navigation.tsx +0 -1
- package/src/components/Navigation/types.ts +9 -2
- package/src/components/NumberIncrement/index.tsx +60 -50
- package/src/components/NumberIncrement/styles.ts +5 -0
- package/src/components/NumberIncrement/types.ts +39 -32
- package/src/components/Pager/index.tsx +94 -42
- package/src/components/Pager/styles.ts +13 -1
- package/src/components/RadioInput/index.tsx +57 -32
- package/src/components/RadioInput/styles.ts +7 -5
- package/src/components/RefreshControl/index.tsx +19 -39
- package/src/components/RefreshControl/styles.ts +6 -1
- package/src/components/Scroll/index.tsx +105 -89
- package/src/components/Scroll/styles.ts +5 -0
- package/src/components/Sections/index.tsx +161 -111
- package/src/components/Sections/styles.ts +5 -0
- package/src/components/SegmentedControl/Option.tsx +31 -46
- package/src/components/SegmentedControl/index.tsx +121 -86
- package/src/components/SegmentedControl/styles.ts +22 -15
- package/src/components/Select/index.tsx +82 -71
- package/src/components/Select/styles.ts +5 -3
- package/src/components/Select/types.ts +25 -20
- package/src/components/Slider/index.tsx +43 -58
- package/src/components/Slider/styles.ts +6 -15
- package/src/components/Slider/types.ts +14 -9
- package/src/components/Switch/index.tsx +56 -43
- package/src/components/Switch/styles.ts +7 -1
- package/src/components/Text/index.tsx +52 -56
- package/src/components/Text/styles.ts +7 -1
- package/src/components/TextInput/index.tsx +162 -49
- package/src/components/TextInput/styles.ts +8 -2
- package/src/components/Touchable/index.tsx +87 -44
- package/src/components/Touchable/styles.ts +9 -0
- package/src/components/View/index.tsx +92 -23
- package/src/components/View/styles.ts +6 -0
- package/src/components/components.ts +6 -2
- package/src/components/defaultStyles.ts +77 -0
- package/src/index.ts +0 -2
- package/src/modules/PressableRipple/type.ts +0 -1
- package/src/utils/KeyboardAware/context.tsx +2 -0
- package/src/utils/KeyboardAware/keyboardHooks.ts +2 -1
- package/src/utils/ModalManager/components.tsx +30 -1
- package/src/utils/ModalManager/context.tsx +4 -4
- package/src/utils/ModalManager/index.ts +4 -1
- package/src/utils/hooks.ts +1 -12
- package/src/Registry.ts +0 -52
- package/src/components/ActionIcon/types.ts +0 -15
- package/src/components/ActivityIndicator/types.ts +0 -9
- package/src/components/Avatar/types.ts +0 -23
- package/src/components/AvatarGroup/types.ts +0 -10
- package/src/components/Backdrop/types.ts +0 -14
- package/src/components/Badge/types.ts +0 -27
- package/src/components/Button/types.ts +0 -20
- package/src/components/Checkbox/types.ts +0 -13
- package/src/components/EmptyPlaceholder/types.ts +0 -21
- package/src/components/FileInput/types.ts +0 -27
- package/src/components/Grid/types.ts +0 -20
- package/src/components/Icon/types.ts +0 -15
- package/src/components/Image/types.ts +0 -18
- package/src/components/List/types.ts +0 -41
- package/src/components/LoadingOverlay/types.ts +0 -9
- package/src/components/Modal/types.ts +0 -41
- package/src/components/Pager/types.ts +0 -37
- package/src/components/PaginationIndicator/index.tsx +0 -51
- package/src/components/PaginationIndicator/styles.ts +0 -3
- package/src/components/PaginationIndicator/types.ts +0 -10
- package/src/components/RadioInput/types.ts +0 -31
- package/src/components/RefreshControl/types.ts +0 -9
- package/src/components/Scroll/types.ts +0 -21
- package/src/components/SearchInput/index.tsx +0 -90
- package/src/components/Sections/types.ts +0 -39
- package/src/components/SegmentedControl/types.ts +0 -31
- package/src/components/Switch/types.ts +0 -12
- package/src/components/Text/types.ts +0 -18
- package/src/components/TextInput/types.ts +0 -23
- package/src/components/Touchable/types.ts +0 -27
- package/src/components/View/types.ts +0 -13
- package/src/hooks/index.ts +0 -13
|
@@ -1,27 +1,86 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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 {
|
|
8
|
-
import { useStylesFor } from '../../hooks'
|
|
9
|
-
|
|
20
|
+
import { PagerPresets, PagerComposition } from './styles'
|
|
10
21
|
export * from './styles'
|
|
11
|
-
|
|
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
|
-
...
|
|
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
|
|
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.
|
|
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 {
|
|
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 {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
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
|
-
|
|
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
|
|
131
|
+
{separator && <View style={styles.optionSeparator} />}
|
|
99
132
|
</>
|
|
100
133
|
}
|
|
101
134
|
|
|
102
|
-
export const RadioGroup = <T extends string
|
|
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
|
|
154
|
+
const variantStyles = useDefaultComponentStyle<'u:RadioInput', typeof RadioInputPresets>('u:RadioInput', {
|
|
155
|
+
variants,
|
|
156
|
+
styles,
|
|
157
|
+
transform: StyleSheet.flatten,
|
|
158
|
+
})
|
|
122
159
|
|
|
123
|
-
|
|
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
|
-
|
|
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={
|
|
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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
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
|
|
10
|
-
|
|
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
|
-
|
|
24
|
-
const
|
|
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
|
-
{...
|
|
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
|
-
|
|
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
|
-
|
|
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' |
|
|
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
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
-
|
|
31
|
-
const [refreshingState, setRefreshing] = useState(false)
|
|
32
|
-
const refreshingDisplay = props.refreshing !== undefined ? props.refreshing : refreshingState
|
|
30
|
+
export type ScrollRef = KeyboardAwareScrollView
|
|
33
31
|
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
const defaultProps: Partial<ScrollProps> = {
|
|
33
|
+
keyboardShouldPersistTaps: 'handled',
|
|
34
|
+
}
|
|
36
35
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
-
|
|
58
|
+
const timer = React.useRef(null)
|
|
59
|
+
const previousData = usePrevious(changeData)
|
|
43
60
|
|
|
44
|
-
|
|
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
|
-
|
|
66
|
+
setRefreshing(true)
|
|
61
67
|
|
|
62
|
-
|
|
68
|
+
props.onRefresh()
|
|
63
69
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
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
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
})
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
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
|
-
|
|
120
|
+
export * from './styles'
|