@codeleap/mobile 3.2.19 → 3.3.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 +3 -2
- package/src/components/Autocomplete/index.tsx +5 -2
- package/src/components/Autocomplete/types.ts +1 -0
- package/src/components/Drawer/index.tsx +0 -5
- package/src/components/List/index.tsx +15 -13
- package/src/components/Modal/index.tsx +4 -10
- package/src/components/Scroll/index.tsx +9 -6
- package/src/components/Sections/index.tsx +13 -7
- package/src/components/Select/index.tsx +1 -0
- package/src/components/View/index.tsx +1 -1
- package/src/utils/hooks.ts +19 -8
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codeleap/mobile",
|
|
3
|
-
"version": "3.2
|
|
3
|
+
"version": "3.3.2",
|
|
4
4
|
"main": "src/index.ts",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"repository": {
|
|
@@ -36,7 +36,8 @@
|
|
|
36
36
|
"react-native-super-grid": "4.6.1",
|
|
37
37
|
"react-native-image-viewing": "0.2.2",
|
|
38
38
|
"react-native-keyboard-aware-scroll-view": "0.9.5",
|
|
39
|
-
"typescript": "5.0.4"
|
|
39
|
+
"typescript": "5.0.4",
|
|
40
|
+
"react-native-avoid-softinput": "3.1.5"
|
|
40
41
|
},
|
|
41
42
|
"dependencies": {
|
|
42
43
|
"@gorhom/portal": "1.0.14",
|
|
@@ -77,6 +77,7 @@ export const Autocomplete = <T extends string|number = string, Multi extends boo
|
|
|
77
77
|
onItemPressed = () => {},
|
|
78
78
|
listPlaceholder,
|
|
79
79
|
style,
|
|
80
|
+
loading: loadingProp = false,
|
|
80
81
|
...listProps
|
|
81
82
|
} = allProps
|
|
82
83
|
|
|
@@ -199,6 +200,8 @@ export const Autocomplete = <T extends string|number = string, Multi extends boo
|
|
|
199
200
|
|
|
200
201
|
const Search = searchComponent
|
|
201
202
|
|
|
203
|
+
const showLoading = TypeGuards.isFunction(loadingProp) ? loadingProp(loading) : (loadingProp || loading)
|
|
204
|
+
|
|
202
205
|
return <View style={[variantStyles.wrapper, style]}>
|
|
203
206
|
<Search
|
|
204
207
|
placeholder={placeholder}
|
|
@@ -222,9 +225,9 @@ export const Autocomplete = <T extends string|number = string, Multi extends boo
|
|
|
222
225
|
// @ts-ignore
|
|
223
226
|
keyExtractor={(i) => i.value}
|
|
224
227
|
renderItem={renderListItem}
|
|
225
|
-
|
|
226
|
-
loading={loading}
|
|
228
|
+
loading={showLoading}
|
|
227
229
|
placeholder={listPlaceholder}
|
|
230
|
+
keyboardAware={false}
|
|
228
231
|
{...listProps}
|
|
229
232
|
/>
|
|
230
233
|
</View>
|
|
@@ -70,6 +70,7 @@ export type AutocompleteProps<T = any, Multi extends boolean = false> = {
|
|
|
70
70
|
debugName: string
|
|
71
71
|
searchComponent?: React.ComponentType<SearchInputProps>
|
|
72
72
|
listPlaceholder?: Partial<EmptyPlaceholderProps>
|
|
73
|
+
loading: boolean | ((isLoading: boolean) => boolean)
|
|
73
74
|
}
|
|
74
75
|
& Omit<FlatListProps<T>, 'renderItem'|'styles'|'style'>
|
|
75
76
|
& ComponentVariants<typeof AutocompletePresets>
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
TypeGuards,
|
|
8
8
|
} from '@codeleap/common'
|
|
9
9
|
|
|
10
|
-
import { FlatListProps as RNFlatListProps, ListRenderItemInfo, StyleSheet } from 'react-native'
|
|
10
|
+
import { FlatListProps as RNFlatListProps, ListRenderItemInfo, StyleSheet, FlatList } from 'react-native'
|
|
11
11
|
import { View, ViewProps } from '../View'
|
|
12
12
|
import { EmptyPlaceholder, EmptyPlaceholderProps } from '../EmptyPlaceholder'
|
|
13
13
|
import { RefreshControl, RefreshControlProps } from '../RefreshControl'
|
|
@@ -15,6 +15,7 @@ import { ListComposition, ListPresets } from './styles'
|
|
|
15
15
|
import { StylesOf } from '../../types'
|
|
16
16
|
|
|
17
17
|
import { KeyboardAwareFlatList } from 'react-native-keyboard-aware-scroll-view'
|
|
18
|
+
import { useKeyboardPaddingStyle } from '../../utils'
|
|
18
19
|
|
|
19
20
|
export type DataboundFlatListPropsTypes = 'data' | 'renderItem' | 'keyExtractor' | 'getItemLayout'
|
|
20
21
|
|
|
@@ -51,6 +52,7 @@ export type FlatListProps<
|
|
|
51
52
|
refreshControlProps?: Partial<RefreshControlProps>
|
|
52
53
|
fakeEmpty?: boolean
|
|
53
54
|
loading?: boolean
|
|
55
|
+
keyboardAware?: boolean
|
|
54
56
|
} & ComponentVariants<typeof ListPresets>
|
|
55
57
|
|
|
56
58
|
const RenderSeparator = (props: { separatorStyles: ViewProps['style'] }) => {
|
|
@@ -59,7 +61,7 @@ const RenderSeparator = (props: { separatorStyles: ViewProps['style'] }) => {
|
|
|
59
61
|
)
|
|
60
62
|
}
|
|
61
63
|
|
|
62
|
-
const ListCP = forwardRef<
|
|
64
|
+
const ListCP = forwardRef<FlatList, FlatListProps>(
|
|
63
65
|
(flatListProps, ref) => {
|
|
64
66
|
const {
|
|
65
67
|
variants = [],
|
|
@@ -69,9 +71,9 @@ const ListCP = forwardRef<KeyboardAwareFlatList, FlatListProps>(
|
|
|
69
71
|
component,
|
|
70
72
|
refreshing,
|
|
71
73
|
placeholder,
|
|
72
|
-
keyboardAware,
|
|
73
74
|
refreshControlProps = {},
|
|
74
75
|
loading = false,
|
|
76
|
+
keyboardAware = true,
|
|
75
77
|
fakeEmpty = loading,
|
|
76
78
|
contentContainerStyle,
|
|
77
79
|
...props
|
|
@@ -111,23 +113,23 @@ const ListCP = forwardRef<KeyboardAwareFlatList, FlatListProps>(
|
|
|
111
113
|
loading: TypeGuards.isBoolean(placeholder?.loading) ? placeholder.loading : loading,
|
|
112
114
|
}
|
|
113
115
|
|
|
116
|
+
const keyboardStyle = useKeyboardPaddingStyle([
|
|
117
|
+
variantStyles.content,
|
|
118
|
+
contentContainerStyle,
|
|
119
|
+
isEmpty && variantStyles['content:empty'],
|
|
120
|
+
], keyboardAware && !props.horizontal)
|
|
121
|
+
|
|
114
122
|
return (
|
|
115
|
-
<
|
|
123
|
+
<FlatList
|
|
116
124
|
style={[
|
|
117
125
|
variantStyles.wrapper,
|
|
118
126
|
style,
|
|
119
127
|
isEmpty && variantStyles['wrapper:empty'],
|
|
120
|
-
|
|
121
128
|
]}
|
|
122
|
-
contentContainerStyle={
|
|
123
|
-
|
|
124
|
-
contentContainerStyle,
|
|
125
|
-
isEmpty && variantStyles['content:empty'],
|
|
126
|
-
]}
|
|
127
|
-
// @ts-expect-error React's refs suck
|
|
129
|
+
contentContainerStyle={keyboardStyle}
|
|
130
|
+
// @ts-expect-error This works
|
|
128
131
|
ItemSeparatorComponent={separator}
|
|
129
132
|
ListHeaderComponentStyle={variantStyles.header}
|
|
130
|
-
|
|
131
133
|
refreshControl={!!onRefresh && (
|
|
132
134
|
<RefreshControl
|
|
133
135
|
refreshing={refreshing}
|
|
@@ -139,7 +141,7 @@ const ListCP = forwardRef<KeyboardAwareFlatList, FlatListProps>(
|
|
|
139
141
|
ListEmptyComponent={<EmptyPlaceholder {..._placeholder}/>}
|
|
140
142
|
{...props}
|
|
141
143
|
data={fakeEmpty ? [] : props.data}
|
|
142
|
-
ref={ ref
|
|
144
|
+
ref={ ref }
|
|
143
145
|
renderItem={renderItem}
|
|
144
146
|
|
|
145
147
|
/>
|
|
@@ -22,7 +22,6 @@ import { Backdrop } from '../Backdrop'
|
|
|
22
22
|
import { useAnimatedVariantStyles, useBackButton } from '../../utils/hooks'
|
|
23
23
|
import { Text, TextProps } from '../Text'
|
|
24
24
|
import { Touchable } from '../Touchable'
|
|
25
|
-
import { GetKeyboardAwarePropsOptions } from '../../utils'
|
|
26
25
|
import { ActionIcon } from '../ActionIcon'
|
|
27
26
|
|
|
28
27
|
export * from './styles'
|
|
@@ -47,7 +46,7 @@ export type ModalProps = Omit<ViewProps, 'variants' | 'styles'> & {
|
|
|
47
46
|
header?: React.ReactElement
|
|
48
47
|
closeOnHardwareBackPress?: boolean
|
|
49
48
|
renderHeader?: (props: ModalHeaderProps) => React.ReactElement
|
|
50
|
-
keyboardAware?:
|
|
49
|
+
keyboardAware?: boolean
|
|
51
50
|
scrollProps?: PropsOf<typeof Scroll, 'ref'>
|
|
52
51
|
}
|
|
53
52
|
|
|
@@ -197,15 +196,10 @@ export const Modal = (modalProps:ModalProps) => {
|
|
|
197
196
|
style={scrollStyle}
|
|
198
197
|
contentContainerStyle={getStyles('scrollContent')}
|
|
199
198
|
showsVerticalScrollIndicator={false}
|
|
200
|
-
keyboardAware
|
|
201
|
-
adapt: 'maxHeight',
|
|
202
|
-
baseStyleProp: 'style',
|
|
203
|
-
animated: true,
|
|
204
|
-
enabled: visible,
|
|
205
|
-
// enableOnAndroid: true,
|
|
206
|
-
}}
|
|
199
|
+
keyboardAware
|
|
207
200
|
animated
|
|
208
|
-
//
|
|
201
|
+
// @ts-ignore
|
|
202
|
+
ref={scrollRef}
|
|
209
203
|
{ ...scrollProps}
|
|
210
204
|
>
|
|
211
205
|
{dismissOnBackdrop &&
|
|
@@ -11,15 +11,16 @@ import { ViewProps } from '../View'
|
|
|
11
11
|
import { RefreshControl, RefreshControlProps } from '../RefreshControl'
|
|
12
12
|
import { StylesOf } from '../../types'
|
|
13
13
|
import { ScrollComposition, ScrollPresets } from './styles'
|
|
14
|
-
import { GetKeyboardAwarePropsOptions } from '../../utils'
|
|
14
|
+
import { GetKeyboardAwarePropsOptions, useKeyboardPaddingStyle } from '../../utils'
|
|
15
15
|
import { KeyboardAwareScrollView, KeyboardAwareScrollViewProps } from 'react-native-keyboard-aware-scroll-view'
|
|
16
|
-
|
|
16
|
+
import { useSoftInputState } from 'react-native-avoid-softinput'
|
|
17
|
+
import { useMemo } from 'react'
|
|
17
18
|
export type ScrollProps = KeyboardAwareScrollViewProps &
|
|
18
19
|
ViewProps & {
|
|
19
20
|
onRefresh?: () => void
|
|
20
21
|
refreshTimeout?: number
|
|
21
22
|
changeData?: any
|
|
22
|
-
keyboardAware?:
|
|
23
|
+
keyboardAware?: boolean
|
|
23
24
|
refreshing?: boolean
|
|
24
25
|
styles?: StylesOf<ScrollComposition>
|
|
25
26
|
refreshControlProps?: Partial<RefreshControlProps>
|
|
@@ -39,7 +40,7 @@ export const Scroll = forwardRef<ScrollRef, ScrollProps>(
|
|
|
39
40
|
styles = {},
|
|
40
41
|
refreshControlProps = {},
|
|
41
42
|
contentContainerStyle,
|
|
42
|
-
keyboardAware,
|
|
43
|
+
keyboardAware = true,
|
|
43
44
|
animated = true,
|
|
44
45
|
...props
|
|
45
46
|
} = scrollProps
|
|
@@ -79,12 +80,14 @@ export const Scroll = forwardRef<ScrollRef, ScrollProps>(
|
|
|
79
80
|
rootElement: 'content',
|
|
80
81
|
})
|
|
81
82
|
|
|
82
|
-
const Component =
|
|
83
|
+
const Component = ScrollView
|
|
84
|
+
|
|
85
|
+
const keyboardStyle = useKeyboardPaddingStyle([variantStyles.content, contentContainerStyle], keyboardAware)
|
|
83
86
|
|
|
84
87
|
return (
|
|
85
88
|
<Component
|
|
86
89
|
style={[variantStyles.wrapper, style]}
|
|
87
|
-
contentContainerStyle={
|
|
90
|
+
contentContainerStyle={keyboardStyle}
|
|
88
91
|
showsVerticalScrollIndicator={false}
|
|
89
92
|
// @ts-ignore
|
|
90
93
|
ref={ref}
|
|
@@ -12,11 +12,12 @@ import {
|
|
|
12
12
|
RefreshControlProps,
|
|
13
13
|
SectionListRenderItemInfo,
|
|
14
14
|
SectionListProps as RNSectionListProps,
|
|
15
|
+
SectionList,
|
|
15
16
|
} from 'react-native'
|
|
16
17
|
import { View, ViewProps } from '../View'
|
|
17
18
|
import { EmptyPlaceholderProps } from '../EmptyPlaceholder'
|
|
18
19
|
import { StylesOf } from '../../types'
|
|
19
|
-
import {
|
|
20
|
+
import { useKeyboardPaddingStyle } from '../../utils'
|
|
20
21
|
import { SectionsComposition, SectionsPresets } from './styles'
|
|
21
22
|
export * from './styles'
|
|
22
23
|
|
|
@@ -52,9 +53,10 @@ export type SectionListProps<
|
|
|
52
53
|
styles?: StylesOf<SectionsComposition>
|
|
53
54
|
refreshControlProps?: Partial<RefreshControlProps>
|
|
54
55
|
fakeEmpty?: boolean
|
|
56
|
+
keyboardAware?: boolean
|
|
55
57
|
} & ComponentVariants<typeof SectionsPresets>
|
|
56
58
|
|
|
57
|
-
export const Sections = forwardRef<
|
|
59
|
+
export const Sections = forwardRef<SectionList, SectionListProps>(
|
|
58
60
|
(sectionsProps, ref) => {
|
|
59
61
|
const {
|
|
60
62
|
variants = [],
|
|
@@ -64,8 +66,10 @@ export const Sections = forwardRef<KeyboardAwareSectionList, SectionListProps>(
|
|
|
64
66
|
component,
|
|
65
67
|
refreshing,
|
|
66
68
|
placeholder,
|
|
67
|
-
keyboardAware,
|
|
69
|
+
keyboardAware = true,
|
|
68
70
|
refreshControlProps = {},
|
|
71
|
+
contentContainerStyle,
|
|
72
|
+
|
|
69
73
|
fakeEmpty,
|
|
70
74
|
refreshControl,
|
|
71
75
|
...props
|
|
@@ -78,11 +82,11 @@ export const Sections = forwardRef<KeyboardAwareSectionList, SectionListProps>(
|
|
|
78
82
|
|
|
79
83
|
})
|
|
80
84
|
|
|
81
|
-
const renderSeparator = () => {
|
|
85
|
+
const renderSeparator = useCallback(() => {
|
|
82
86
|
return (
|
|
83
87
|
<View style={variantStyles.separator}></View>
|
|
84
88
|
)
|
|
85
|
-
}
|
|
89
|
+
}, [variantStyles.separator])
|
|
86
90
|
|
|
87
91
|
const getItemPosition = (section, itemIdx) => {
|
|
88
92
|
const listLength = section?.length || 0
|
|
@@ -127,10 +131,12 @@ export const Sections = forwardRef<KeyboardAwareSectionList, SectionListProps>(
|
|
|
127
131
|
const isEmpty = !props.sections || !props.sections.length
|
|
128
132
|
const separator = !isEmpty && separatorProp == true && renderSeparator
|
|
129
133
|
|
|
134
|
+
const keyboardStyle = useKeyboardPaddingStyle([variantStyles.content, contentContainerStyle], keyboardAware)
|
|
135
|
+
|
|
130
136
|
return (
|
|
131
|
-
<
|
|
137
|
+
<SectionList
|
|
132
138
|
style={[variantStyles.wrapper, style]}
|
|
133
|
-
contentContainerStyle={
|
|
139
|
+
contentContainerStyle={keyboardStyle}
|
|
134
140
|
showsVerticalScrollIndicator={false}
|
|
135
141
|
// @ts-ignore
|
|
136
142
|
ref={ref}
|
|
@@ -347,6 +347,7 @@ export const Select = <T extends string|number = string, Multi extends boolean =
|
|
|
347
347
|
renderItem={renderListItem}
|
|
348
348
|
fakeEmpty={loading}
|
|
349
349
|
separators
|
|
350
|
+
keyboardAware={false}
|
|
350
351
|
{...listProps}
|
|
351
352
|
ListHeaderComponent={_ListHeaderComponent}
|
|
352
353
|
placeholder={{
|
package/src/utils/hooks.ts
CHANGED
|
@@ -4,6 +4,8 @@ import { Animated, AppState, AppStateStatus, Platform, PressableAndroidRippleCon
|
|
|
4
4
|
import AsyncStorage from '@react-native-community/async-storage'
|
|
5
5
|
import { AnimatedStyleProp, Easing, EasingFn, interpolateColor, runOnJS, useAnimatedRef, useAnimatedStyle, useSharedValue, withTiming } from 'react-native-reanimated'
|
|
6
6
|
import { PressableRippleProps } from '../modules/PressableRipple/type'
|
|
7
|
+
import { useSoftInputState } from 'react-native-avoid-softinput'
|
|
8
|
+
import { useMemo } from 'react'
|
|
7
9
|
|
|
8
10
|
export function useAnimateColor(value: string, opts?: Partial<Animated.TimingAnimationConfig>) {
|
|
9
11
|
const iters = useRef(0)
|
|
@@ -104,7 +106,7 @@ const buildAnimatedStyle = (property: AnimatableProperties, value, currentStyle,
|
|
|
104
106
|
case 'scaleY':
|
|
105
107
|
case 'translateX':
|
|
106
108
|
case 'translateY':
|
|
107
|
-
if(!newStyle.transform){
|
|
109
|
+
if (!newStyle.transform) {
|
|
108
110
|
newStyle.transform = []
|
|
109
111
|
}
|
|
110
112
|
newStyle.transform.push({
|
|
@@ -165,26 +167,22 @@ export function useAnimatedVariantStyles<T extends Record<string|number|symbol,
|
|
|
165
167
|
const _transition = useRef(null)
|
|
166
168
|
|
|
167
169
|
if (!_transition.current) {
|
|
168
|
-
_transition.current = JSON.parse(JSON.stringify(transition||{}))
|
|
170
|
+
_transition.current = JSON.parse(JSON.stringify(transition || {}))
|
|
169
171
|
}
|
|
170
172
|
|
|
171
|
-
|
|
172
|
-
|
|
173
173
|
const staticStyles = useStaticAnimationStyles(variantStyles, animatedProperties)
|
|
174
174
|
|
|
175
175
|
const animated = useAnimatedStyle(() => {
|
|
176
176
|
const nextState = updater(staticStyles)
|
|
177
177
|
|
|
178
|
-
|
|
179
178
|
const formatted = transformProperties(
|
|
180
|
-
nextState,
|
|
181
|
-
_transition.current
|
|
179
|
+
nextState,
|
|
180
|
+
_transition.current,
|
|
182
181
|
)
|
|
183
182
|
|
|
184
183
|
return formatted
|
|
185
184
|
}, dependencies)
|
|
186
185
|
|
|
187
|
-
|
|
188
186
|
return animated
|
|
189
187
|
}
|
|
190
188
|
|
|
@@ -344,3 +342,16 @@ export function useAsyncStorageState<T>(key:string, defaultValue?: T) {
|
|
|
344
342
|
return [value, setValue] as [T, typeof setValue]
|
|
345
343
|
}
|
|
346
344
|
|
|
345
|
+
export function useKeyboardPaddingStyle(styles: ViewStyle[], enabled = true) {
|
|
346
|
+
const { isSoftInputShown, softInputHeight } = useSoftInputState()
|
|
347
|
+
|
|
348
|
+
const propStyle = useMemo(() => {
|
|
349
|
+
return StyleSheet.flatten(styles)
|
|
350
|
+
}, styles)
|
|
351
|
+
|
|
352
|
+
const bottomPadding = propStyle && TypeGuards.isNumber(propStyle.paddingBottom) ? propStyle.paddingBottom : 0
|
|
353
|
+
|
|
354
|
+
const totalPadding = softInputHeight + bottomPadding
|
|
355
|
+
|
|
356
|
+
return isSoftInputShown && enabled ? [propStyle, { paddingBottom: totalPadding }] : [propStyle]
|
|
357
|
+
}
|