@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
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import {
|
|
3
|
+
ComponentVariants,
|
|
4
|
+
createDefaultVariantFactory,
|
|
5
|
+
getNestedStylesByKey,
|
|
6
|
+
includePresets,
|
|
7
|
+
TypeGuards,
|
|
8
|
+
useDefaultComponentStyle,
|
|
9
|
+
} from '@codeleap/common'
|
|
10
|
+
import { StyleSheet, ViewStyle } from 'react-native'
|
|
11
|
+
import { StylesOf } from '../../types'
|
|
12
|
+
import { ActivityIndicator, ActivityIndicatorComposition } from '../ActivityIndicator'
|
|
13
|
+
import { Text } from '../Text'
|
|
14
|
+
|
|
15
|
+
export type PaginationIndicatorComposition = 'text' | `loader${Capitalize<ActivityIndicatorComposition>}`
|
|
16
|
+
|
|
17
|
+
const createPaginationIndicatorStyle = createDefaultVariantFactory<PaginationIndicatorComposition>()
|
|
18
|
+
|
|
19
|
+
export const PaginationIndicatorPresets = includePresets((style) => createPaginationIndicatorStyle(() => ({ loaderWrapper: style, text: style })))
|
|
20
|
+
|
|
21
|
+
export type PaginationIndicatorProps = {
|
|
22
|
+
isFetching?: boolean
|
|
23
|
+
noMoreItemsText: React.ReactChild
|
|
24
|
+
hasMore?: boolean
|
|
25
|
+
activityIndicator?: JSX.Element
|
|
26
|
+
styles?: StylesOf<PaginationIndicatorComposition>
|
|
27
|
+
style?: ViewStyle
|
|
28
|
+
} & ComponentVariants<typeof PaginationIndicatorPresets>
|
|
29
|
+
|
|
30
|
+
export const PaginationIndicator = (props: PaginationIndicatorProps) => {
|
|
31
|
+
const { hasMore, isFetching, noMoreItemsText, style, activityIndicator, styles = {}, variants = [] } = props
|
|
32
|
+
|
|
33
|
+
const variantStyles = useDefaultComponentStyle<
|
|
34
|
+
'u:PaginationIndicator',
|
|
35
|
+
typeof PaginationIndicatorPresets
|
|
36
|
+
>('u:PaginationIndicator', {
|
|
37
|
+
variants,
|
|
38
|
+
styles,
|
|
39
|
+
transform: StyleSheet.flatten,
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
const loaderStyles = getNestedStylesByKey('loader', variantStyles)
|
|
43
|
+
|
|
44
|
+
if (isFetching) {
|
|
45
|
+
return activityIndicator || <ActivityIndicator style={style} styles={loaderStyles}/>
|
|
46
|
+
}
|
|
47
|
+
if (!hasMore) {
|
|
48
|
+
if (TypeGuards.isString(noMoreItemsText) || TypeGuards.isNumber(noMoreItemsText)) {
|
|
49
|
+
return <Text style={[variantStyles.text, style]} text={noMoreItemsText.toString()}/>
|
|
50
|
+
}
|
|
51
|
+
return noMoreItemsText
|
|
52
|
+
}
|
|
53
|
+
return null
|
|
54
|
+
}
|
|
@@ -1,119 +1,171 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import * as React from 'react'
|
|
2
|
+
import { forwardRef } from 'react'
|
|
3
|
+
import {
|
|
4
|
+
useDefaultComponentStyle,
|
|
5
|
+
ComponentVariants,
|
|
6
|
+
useCallback,
|
|
7
|
+
TypeGuards,
|
|
8
|
+
} from '@codeleap/common'
|
|
9
|
+
|
|
10
|
+
import { FlatListProps as RNFlatListProps, ListRenderItemInfo, StyleSheet, FlatList } from 'react-native'
|
|
4
11
|
import { View, ViewProps } from '../View'
|
|
5
|
-
import { EmptyPlaceholder } from '../EmptyPlaceholder'
|
|
6
|
-
import { RefreshControl } from '../RefreshControl'
|
|
12
|
+
import { EmptyPlaceholder, EmptyPlaceholderProps } from '../EmptyPlaceholder'
|
|
13
|
+
import { RefreshControl, RefreshControlProps } from '../RefreshControl'
|
|
14
|
+
import { ListComposition, ListPresets } from './styles'
|
|
15
|
+
import { StylesOf } from '../../types'
|
|
16
|
+
|
|
17
|
+
import { KeyboardAwareFlatList } from 'react-native-keyboard-aware-scroll-view'
|
|
7
18
|
import { useKeyboardPaddingStyle } from '../../utils'
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
19
|
+
|
|
20
|
+
export type DataboundFlatListPropsTypes = 'data' | 'renderItem' | 'keyExtractor' | 'getItemLayout'
|
|
21
|
+
|
|
22
|
+
export type AugmentedRenderItemInfo<T> = ListRenderItemInfo<T> & {
|
|
23
|
+
isFirst: boolean
|
|
24
|
+
isLast: boolean
|
|
25
|
+
isOnly: boolean
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export type ReplaceFlatlistProps<P, T> = Omit<P, DataboundFlatListPropsTypes> & {
|
|
29
|
+
data: T[]
|
|
30
|
+
keyExtractor?: (item: T, index: number) => string
|
|
31
|
+
renderItem: (data: AugmentedRenderItemInfo<T>) => React.ReactElement
|
|
32
|
+
onRefresh?: () => void
|
|
33
|
+
getItemLayout?: ((
|
|
34
|
+
data: T,
|
|
35
|
+
index: number,
|
|
36
|
+
) => { length: number; offset: number; index: number })
|
|
37
|
+
fakeEmpty?: boolean
|
|
38
|
+
loading?: boolean
|
|
39
|
+
}
|
|
12
40
|
|
|
13
41
|
export * from './styles'
|
|
14
|
-
export * from './
|
|
42
|
+
export * from './PaginationIndicator'
|
|
43
|
+
|
|
44
|
+
export type FlatListProps<
|
|
45
|
+
T = any[],
|
|
46
|
+
Data = T extends Array<infer D> ? D : never
|
|
47
|
+
> = ReplaceFlatlistProps<RNFlatListProps<Data>, Data> &
|
|
48
|
+
Omit<ViewProps, 'variants'> & {
|
|
49
|
+
separators?: boolean
|
|
50
|
+
placeholder?: EmptyPlaceholderProps
|
|
51
|
+
styles?: StylesOf<ListComposition>
|
|
52
|
+
refreshControlProps?: Partial<RefreshControlProps>
|
|
53
|
+
fakeEmpty?: boolean
|
|
54
|
+
loading?: boolean
|
|
55
|
+
keyboardAware?: boolean
|
|
56
|
+
} & ComponentVariants<typeof ListPresets>
|
|
15
57
|
|
|
16
58
|
const RenderSeparator = (props: { separatorStyles: ViewProps['style'] }) => {
|
|
17
|
-
return
|
|
59
|
+
return (
|
|
60
|
+
<View style={props.separatorStyles}></View>
|
|
61
|
+
)
|
|
18
62
|
}
|
|
19
63
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const isFirst = data.index === 0
|
|
50
|
-
const isLast = data.index === dataLength - 1
|
|
51
|
-
|
|
52
|
-
const isOnly = isFirst && isLast
|
|
53
|
-
|
|
54
|
-
const itemProps = {
|
|
55
|
-
...data,
|
|
56
|
-
isFirst,
|
|
57
|
-
isLast,
|
|
58
|
-
isOnly,
|
|
64
|
+
const defaultProps: Partial<FlatListProps> = {
|
|
65
|
+
keyboardShouldPersistTaps: 'handled',
|
|
66
|
+
styles: {},
|
|
67
|
+
variants: [],
|
|
68
|
+
refreshControlProps: {},
|
|
69
|
+
fakeEmpty: false,
|
|
70
|
+
loading: false,
|
|
71
|
+
keyboardAware: true,
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const ListCP = forwardRef<FlatList, FlatListProps>(
|
|
75
|
+
(flatListProps, ref) => {
|
|
76
|
+
const {
|
|
77
|
+
variants,
|
|
78
|
+
style,
|
|
79
|
+
styles,
|
|
80
|
+
onRefresh,
|
|
81
|
+
component,
|
|
82
|
+
refreshing,
|
|
83
|
+
placeholder,
|
|
84
|
+
refreshControlProps,
|
|
85
|
+
loading,
|
|
86
|
+
keyboardAware,
|
|
87
|
+
fakeEmpty = loading,
|
|
88
|
+
contentContainerStyle,
|
|
89
|
+
...props
|
|
90
|
+
} = {
|
|
91
|
+
...defaultProps,
|
|
92
|
+
...flatListProps,
|
|
59
93
|
}
|
|
60
94
|
|
|
61
|
-
|
|
62
|
-
|
|
95
|
+
const variantStyles = useDefaultComponentStyle<'u:List', typeof ListPresets>('u:List', {
|
|
96
|
+
variants,
|
|
97
|
+
styles,
|
|
98
|
+
transform: StyleSheet.flatten,
|
|
63
99
|
|
|
64
|
-
|
|
100
|
+
})
|
|
65
101
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
loading: TypeGuards.isBoolean(placeholder?.loading) ? placeholder.loading : loading,
|
|
69
|
-
}
|
|
102
|
+
// const isEmpty = !props.data || !props.data.length
|
|
103
|
+
const separator = props?.separators && <RenderSeparator separatorStyles={variantStyles.separator} />
|
|
70
104
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
isEmpty && styles['content:empty'],
|
|
75
|
-
loading && styles['content:loading'],
|
|
76
|
-
], keyboardAware && !props.horizontal)
|
|
105
|
+
const renderItem = useCallback((data: ListRenderItemInfo<any>) => {
|
|
106
|
+
if (!props?.renderItem) return null
|
|
107
|
+
const listLength = props?.data?.length || 0
|
|
77
108
|
|
|
78
|
-
|
|
109
|
+
const isFirst = data.index === 0
|
|
110
|
+
const isLast = data.index === listLength - 1
|
|
79
111
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
)}
|
|
90
|
-
ListEmptyComponent={<EmptyPlaceholder {..._placeholder} />}
|
|
91
|
-
showsVerticalScrollIndicator={false}
|
|
92
|
-
showsHorizontalScrollIndicator={false}
|
|
93
|
-
{...props}
|
|
94
|
-
ListHeaderComponentStyle={styles.header}
|
|
95
|
-
style={wrapperStyle}
|
|
96
|
-
contentContainerStyle={keyboardStyle}
|
|
97
|
-
data={fakeEmpty ? [] : data}
|
|
98
|
-
ref={ref}
|
|
99
|
-
renderItem={renderItem}
|
|
100
|
-
/>
|
|
101
|
-
)
|
|
102
|
-
}) as StyledComponentWithProps<FlatListProps>
|
|
112
|
+
const isOnly = isFirst && isLast
|
|
113
|
+
|
|
114
|
+
return props?.renderItem({
|
|
115
|
+
...data,
|
|
116
|
+
isFirst,
|
|
117
|
+
isLast,
|
|
118
|
+
isOnly,
|
|
119
|
+
})
|
|
120
|
+
}, [props?.renderItem, props?.data?.length])
|
|
103
121
|
|
|
104
|
-
|
|
105
|
-
List.elements = ['wrapper', 'content', 'separator', 'header', 'refreshControl']
|
|
106
|
-
List.rootElement = 'wrapper'
|
|
122
|
+
const isEmpty = !props.data || !props.data.length
|
|
107
123
|
|
|
108
|
-
|
|
109
|
-
|
|
124
|
+
const _placeholder = {
|
|
125
|
+
...placeholder,
|
|
126
|
+
loading: TypeGuards.isBoolean(placeholder?.loading) ? placeholder.loading : loading,
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const keyboardStyle = useKeyboardPaddingStyle([
|
|
130
|
+
variantStyles.content,
|
|
131
|
+
contentContainerStyle,
|
|
132
|
+
isEmpty && variantStyles['content:empty'],
|
|
133
|
+
], keyboardAware && !props.horizontal)
|
|
134
|
+
|
|
135
|
+
return (
|
|
136
|
+
<FlatList
|
|
137
|
+
style={[
|
|
138
|
+
variantStyles.wrapper,
|
|
139
|
+
style,
|
|
140
|
+
isEmpty && variantStyles['wrapper:empty'],
|
|
141
|
+
]}
|
|
142
|
+
contentContainerStyle={keyboardStyle}
|
|
143
|
+
// @ts-expect-error This works
|
|
144
|
+
ItemSeparatorComponent={separator}
|
|
145
|
+
ListHeaderComponentStyle={variantStyles.header}
|
|
146
|
+
refreshControl={!!onRefresh && (
|
|
147
|
+
<RefreshControl
|
|
148
|
+
refreshing={refreshing}
|
|
149
|
+
onRefresh={onRefresh}
|
|
150
|
+
{...refreshControlProps}
|
|
151
|
+
/>
|
|
152
|
+
)}
|
|
153
|
+
|
|
154
|
+
ListEmptyComponent={<EmptyPlaceholder {..._placeholder} />}
|
|
155
|
+
{...props}
|
|
156
|
+
data={fakeEmpty ? [] : props.data}
|
|
157
|
+
ref={ref}
|
|
158
|
+
renderItem={renderItem}
|
|
159
|
+
|
|
160
|
+
/>
|
|
161
|
+
)
|
|
162
|
+
},
|
|
163
|
+
)
|
|
164
|
+
|
|
165
|
+
export type ListComponentType = (<T extends any[] = any[]>(props: FlatListProps<T>) => JSX.Element) & {
|
|
166
|
+
defaultProps: Partial<FlatListProps>
|
|
110
167
|
}
|
|
168
|
+
export const List = ListCP as unknown as ListComponentType
|
|
111
169
|
|
|
112
|
-
List.defaultProps =
|
|
113
|
-
keyboardShouldPersistTaps: 'handled',
|
|
114
|
-
fakeEmpty: false,
|
|
115
|
-
loading: false,
|
|
116
|
-
keyboardAware: true,
|
|
117
|
-
} as Partial<FlatListProps>
|
|
170
|
+
List.defaultProps = defaultProps
|
|
118
171
|
|
|
119
|
-
MobileStyleRegistry.registerComponent(List)
|
|
@@ -1,7 +1,13 @@
|
|
|
1
|
+
import { createDefaultVariantFactory, includePresets } from '@codeleap/common'
|
|
1
2
|
import { ScrollComposition } from '../Scroll/styles'
|
|
2
3
|
|
|
4
|
+
|
|
3
5
|
type ListStates = 'empty' | 'loading'
|
|
4
6
|
|
|
5
7
|
type ListParts = ScrollComposition | 'separator' | 'header' | 'refreshControl'
|
|
6
8
|
|
|
7
9
|
export type ListComposition = `${ListParts}:${ListStates}` | ListParts
|
|
10
|
+
|
|
11
|
+
const createListStyle = createDefaultVariantFactory<ListComposition>()
|
|
12
|
+
|
|
13
|
+
export const ListPresets = includePresets(style => createListStyle(() => ({ content: style })))
|
|
@@ -1,68 +1,55 @@
|
|
|
1
1
|
import React, { useRef } from 'react'
|
|
2
|
+
import { ComponentVariants, getNestedStylesByKey, onUpdate, useDefaultComponentStyle, useMemo } from '@codeleap/common'
|
|
3
|
+
import { StyleSheet } from 'react-native'
|
|
4
|
+
import { StylesOf } from '../../types'
|
|
2
5
|
import { ActivityIndicator } from '../ActivityIndicator'
|
|
3
6
|
import { View } from '../View'
|
|
7
|
+
import { LoadingOverlayComposition, LoadingOverlayPresets } from './styles'
|
|
4
8
|
import { useAnimatedVariantStyles } from '../../utils'
|
|
5
|
-
import { LoadingOverlayProps } from './types'
|
|
6
|
-
import { MobileStyleRegistry } from '../../Registry'
|
|
7
|
-
import { AnyRecord, useNestedStylesByKey, IJSX, StyledComponentProps } from '@codeleap/styles'
|
|
8
|
-
import { useStylesFor } from '../../hooks'
|
|
9
9
|
|
|
10
10
|
export * from './styles'
|
|
11
|
-
|
|
11
|
+
|
|
12
|
+
export type LoadingOverlayProps = React.PropsWithChildren<{
|
|
13
|
+
variants?: ComponentVariants<typeof LoadingOverlayPresets>['variants']
|
|
14
|
+
styles?: StylesOf<LoadingOverlayComposition>
|
|
15
|
+
visible?: boolean
|
|
16
|
+
} >
|
|
12
17
|
|
|
13
18
|
export const LoadingOverlay = (props: LoadingOverlayProps) => {
|
|
14
19
|
const {
|
|
15
20
|
children,
|
|
21
|
+
styles,
|
|
22
|
+
variants,
|
|
16
23
|
visible,
|
|
17
|
-
|
|
18
|
-
} = {
|
|
19
|
-
...LoadingOverlay.defaultProps,
|
|
20
|
-
...props
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const transition = useRef(null)
|
|
24
|
+
} = props
|
|
24
25
|
|
|
25
|
-
const
|
|
26
|
+
const variantStyles = useDefaultComponentStyle<'u:LoadingOverlay', typeof LoadingOverlayPresets>('u:LoadingOverlay', {
|
|
27
|
+
variants,
|
|
28
|
+
rootElement: 'wrapper',
|
|
29
|
+
styles,
|
|
30
|
+
transform: StyleSheet.flatten,
|
|
31
|
+
})
|
|
26
32
|
|
|
27
|
-
const loaderStyles =
|
|
33
|
+
const loaderStyles = useMemo(() => getNestedStylesByKey('loader', variantStyles), [variantStyles])
|
|
28
34
|
|
|
29
35
|
const wrapperAnimation = useAnimatedVariantStyles({
|
|
30
|
-
variantStyles
|
|
36
|
+
variantStyles,
|
|
31
37
|
animatedProperties: ['wrapper:visible', 'wrapper:hidden'],
|
|
32
38
|
updater: (s) => {
|
|
33
39
|
'worklet'
|
|
34
40
|
return visible ? s['wrapper:visible'] : s['wrapper:hidden']
|
|
35
41
|
},
|
|
36
|
-
transition:
|
|
42
|
+
transition: variantStyles.transition,
|
|
37
43
|
dependencies: [visible],
|
|
38
44
|
})
|
|
45
|
+
|
|
39
46
|
|
|
47
|
+
const transition = useRef(null)
|
|
40
48
|
if (!transition.current) {
|
|
41
|
-
transition.current = JSON.parse(JSON.stringify(
|
|
49
|
+
transition.current = JSON.parse(JSON.stringify(variantStyles['wrapper:transition']))
|
|
42
50
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
animatedStyle={wrapperAnimation}
|
|
48
|
-
style={styles.wrapper}
|
|
49
|
-
// @ts-expect-error
|
|
50
|
-
transition={transition.current}
|
|
51
|
-
>
|
|
52
|
-
<ActivityIndicator style={loaderStyles} />
|
|
53
|
-
{children}
|
|
54
|
-
</View>
|
|
55
|
-
)
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
LoadingOverlay.styleRegistryName = 'LoadingOverlay'
|
|
59
|
-
LoadingOverlay.elements = ['wrapper', 'loader', 'transition']
|
|
60
|
-
LoadingOverlay.rootElement = 'wrapper'
|
|
61
|
-
|
|
62
|
-
LoadingOverlay.defaultProps = {} as Partial<LoadingOverlayProps>
|
|
63
|
-
|
|
64
|
-
LoadingOverlay.withVariantTypes = <S extends AnyRecord>(styles: S) => {
|
|
65
|
-
return LoadingOverlay as (props: StyledComponentProps<LoadingOverlayProps, typeof styles>) => IJSX
|
|
51
|
+
return <View style={[variantStyles.wrapper, wrapperAnimation]} animated transition={transition.current}>
|
|
52
|
+
<ActivityIndicator styles={loaderStyles}/>
|
|
53
|
+
{children}
|
|
54
|
+
</View>
|
|
66
55
|
}
|
|
67
|
-
|
|
68
|
-
MobileStyleRegistry.registerComponent(LoadingOverlay)
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
import { createDefaultVariantFactory, includePresets } from '@codeleap/common'
|
|
1
2
|
import { ActivityIndicatorComposition } from '../ActivityIndicator'
|
|
2
3
|
|
|
3
|
-
type WrapperStates = 'hidden'
|
|
4
|
+
type WrapperStates = 'hidden'| 'visible'
|
|
4
5
|
|
|
5
|
-
export type LoadingOverlayComposition =
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
'transition'
|
|
6
|
+
export type LoadingOverlayComposition = 'wrapper' | `wrapper:${WrapperStates}` | 'wrapper:transition' | `loader${Capitalize<ActivityIndicatorComposition>}` | 'transition'
|
|
7
|
+
|
|
8
|
+
const createLoadingOverlayStyle = createDefaultVariantFactory<LoadingOverlayComposition>()
|
|
9
|
+
|
|
10
|
+
export const LoadingOverlayPresets = includePresets((styles) => createLoadingOverlayStyle(() => ({ wrapper: styles })))
|