@codeleap/mobile 3.13.3 → 3.14.0
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
CHANGED
|
@@ -7,9 +7,12 @@ import { Icon, IconProps } from '../Icon'
|
|
|
7
7
|
import { Touchable, TouchableProps } from '../Touchable'
|
|
8
8
|
import { ActionIconComposition, ActionIconPresets } from './styles'
|
|
9
9
|
|
|
10
|
+
/** * IconButton */
|
|
10
11
|
export type ActionIconProps= {
|
|
11
12
|
iconProps?: Partial<IconProps>
|
|
13
|
+
/** prop */
|
|
12
14
|
icon?: IconProps['name']
|
|
15
|
+
/** prop */
|
|
13
16
|
name?: IconProps['name']
|
|
14
17
|
styles?: StylesOf<ActionIconComposition> | StylesOf<ActionIconComposition>[]
|
|
15
18
|
} & Omit<TouchableProps, 'styles' | 'variants'> & ComponentVariants<typeof ActionIconPresets> & BadgeComponentProps
|
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
TypeGuards,
|
|
11
11
|
useDefaultComponentStyle,
|
|
12
12
|
useRef,
|
|
13
|
+
useCodeleapContext,
|
|
13
14
|
} from '@codeleap/common'
|
|
14
15
|
import {
|
|
15
16
|
ModalComposition,
|
|
@@ -24,6 +25,7 @@ import { useAnimatedVariantStyles, useBackButton } from '../../utils/hooks'
|
|
|
24
25
|
import { Text, TextProps } from '../Text'
|
|
25
26
|
import { Touchable } from '../Touchable'
|
|
26
27
|
import { ActionIcon } from '../ActionIcon'
|
|
28
|
+
import { useState } from 'react'
|
|
27
29
|
|
|
28
30
|
export * from './styles'
|
|
29
31
|
|
|
@@ -101,7 +103,7 @@ const DefaultHeader = (props: ModalHeaderProps) => {
|
|
|
101
103
|
)}</>
|
|
102
104
|
}
|
|
103
105
|
|
|
104
|
-
export const Modal = (modalProps:ModalProps) => {
|
|
106
|
+
export const Modal = (modalProps: ModalProps) => {
|
|
105
107
|
const {
|
|
106
108
|
variants = [],
|
|
107
109
|
styles = {},
|
|
@@ -125,6 +127,9 @@ export const Modal = (modalProps:ModalProps) => {
|
|
|
125
127
|
...Modal.defaultProps,
|
|
126
128
|
...modalProps,
|
|
127
129
|
}
|
|
130
|
+
const [modalHeight, setModalHeight] = useState(0)
|
|
131
|
+
const { Theme } = useCodeleapContext()
|
|
132
|
+
|
|
128
133
|
const variantStyles = useDefaultComponentStyle('u:Modal', {
|
|
129
134
|
variants: variants as any,
|
|
130
135
|
transform: StyleSheet.flatten,
|
|
@@ -157,7 +162,10 @@ export const Modal = (modalProps:ModalProps) => {
|
|
|
157
162
|
const ScrollComponent = scroll ? Scroll : View
|
|
158
163
|
const scrollStyle = scroll ? getStyles('scroll') : getStyles('innerWrapper')
|
|
159
164
|
|
|
160
|
-
const
|
|
165
|
+
const heightThreshold = Theme.values.height * 0.75
|
|
166
|
+
const topSpacing = modalHeight > heightThreshold ? variantStyles.topSpacing : Theme.spacing.paddingTop(0)
|
|
167
|
+
|
|
168
|
+
const headerProps: ModalHeaderProps = {
|
|
161
169
|
|
|
162
170
|
...modalProps,
|
|
163
171
|
closable,
|
|
@@ -178,9 +186,17 @@ export const Modal = (modalProps:ModalProps) => {
|
|
|
178
186
|
}
|
|
179
187
|
}, [visible, toggle, closeOnHardwareBackPress])
|
|
180
188
|
|
|
189
|
+
const onModalLayout = (event) => {
|
|
190
|
+
const { height } = event.nativeEvent.layout
|
|
191
|
+
setModalHeight(height)
|
|
192
|
+
props?.onLayout?.(event)
|
|
193
|
+
}
|
|
194
|
+
|
|
181
195
|
return (
|
|
182
196
|
<View
|
|
183
|
-
style={[wrapperStyle, {
|
|
197
|
+
style={[wrapperStyle, {
|
|
198
|
+
zIndex: TypeGuards.isNumber(zIndex) ? zIndex : wrapperStyle?.zIndex, ...topSpacing,
|
|
199
|
+
}]}
|
|
184
200
|
pointerEvents={visible ? 'auto' : 'none'}
|
|
185
201
|
>
|
|
186
202
|
|
|
@@ -189,9 +205,9 @@ export const Modal = (modalProps:ModalProps) => {
|
|
|
189
205
|
'wrapper:visible': variantStyles['backdrop:visible'],
|
|
190
206
|
wrapper: variantStyles.backdrop,
|
|
191
207
|
}}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
208
|
+
wrapperProps={{
|
|
209
|
+
transition: { ...variantStyles['backdrop:transition'] },
|
|
210
|
+
}}
|
|
195
211
|
/>
|
|
196
212
|
<ScrollComponent
|
|
197
213
|
style={scrollStyle}
|
|
@@ -200,11 +216,11 @@ export const Modal = (modalProps:ModalProps) => {
|
|
|
200
216
|
keyboardAware
|
|
201
217
|
animated
|
|
202
218
|
|
|
203
|
-
{
|
|
219
|
+
{...scrollProps}
|
|
204
220
|
>
|
|
205
221
|
{dismissOnBackdrop &&
|
|
206
222
|
<Touchable
|
|
207
|
-
onPress={closable && visible ? toggle : (() => {})}
|
|
223
|
+
onPress={closable && visible ? toggle : (() => { })}
|
|
208
224
|
debounce={400}
|
|
209
225
|
debugName={'Modal backdrop touchable'}
|
|
210
226
|
style={variantStyles.backdropTouchable}
|
|
@@ -215,11 +231,11 @@ export const Modal = (modalProps:ModalProps) => {
|
|
|
215
231
|
<View
|
|
216
232
|
animated
|
|
217
233
|
style={[getStyles('box'), boxAnimationStyles]}
|
|
218
|
-
|
|
219
234
|
{...props}
|
|
235
|
+
onLayout={onModalLayout}
|
|
220
236
|
>
|
|
221
237
|
|
|
222
|
-
{header ? header : <Header {...headerProps}/>}
|
|
238
|
+
{header ? header : <Header {...headerProps} />}
|
|
223
239
|
|
|
224
240
|
<View style={getStyles('body')}>{children}</View>
|
|
225
241
|
{footer && (
|
|
@@ -230,7 +246,7 @@ export const Modal = (modalProps:ModalProps) => {
|
|
|
230
246
|
</View>
|
|
231
247
|
|
|
232
248
|
</ScrollComponent>
|
|
233
|
-
</View>
|
|
249
|
+
</View >
|
|
234
250
|
|
|
235
251
|
)
|
|
236
252
|
}
|
|
@@ -36,10 +36,21 @@ export type TouchableProps =
|
|
|
36
36
|
rippleDisabled?: boolean
|
|
37
37
|
children?: React.ReactNode
|
|
38
38
|
style?: StyleProp<ViewStyle>
|
|
39
|
+
analyticsEnabled?: boolean
|
|
40
|
+
analyticsName?: string
|
|
41
|
+
analyticsData?: Record<string, any>
|
|
39
42
|
}
|
|
40
43
|
|
|
41
44
|
export * from './styles'
|
|
42
|
-
|
|
45
|
+
const defaultProps: Partial<TouchableProps> = {
|
|
46
|
+
variants: [],
|
|
47
|
+
debounce: 500,
|
|
48
|
+
noFeedback: false,
|
|
49
|
+
rippleDisabled: false,
|
|
50
|
+
analyticsEnabled: false,
|
|
51
|
+
analyticsName: null,
|
|
52
|
+
analyticsData: {},
|
|
53
|
+
}
|
|
43
54
|
const _Touchable = forwardRef<
|
|
44
55
|
RNView,
|
|
45
56
|
TouchableProps
|
|
@@ -51,14 +62,20 @@ const _Touchable = forwardRef<
|
|
|
51
62
|
style,
|
|
52
63
|
debugName,
|
|
53
64
|
debugComponent,
|
|
54
|
-
debounce
|
|
65
|
+
debounce,
|
|
55
66
|
leadingDebounce,
|
|
56
|
-
noFeedback
|
|
67
|
+
noFeedback,
|
|
57
68
|
styles,
|
|
58
69
|
setPressed,
|
|
59
|
-
rippleDisabled
|
|
70
|
+
rippleDisabled,
|
|
71
|
+
analyticsEnabled,
|
|
72
|
+
analyticsName,
|
|
73
|
+
analyticsData = {},
|
|
60
74
|
...props
|
|
61
|
-
} =
|
|
75
|
+
} = {
|
|
76
|
+
...defaultProps,
|
|
77
|
+
...touchableProps,
|
|
78
|
+
}
|
|
62
79
|
|
|
63
80
|
const pressed = React.useRef(!!leadingDebounce)
|
|
64
81
|
|
|
@@ -92,6 +109,12 @@ const _Touchable = forwardRef<
|
|
|
92
109
|
debugName || variants,
|
|
93
110
|
'User interaction',
|
|
94
111
|
)
|
|
112
|
+
if (analyticsEnabled) {
|
|
113
|
+
const name = analyticsName || debugName
|
|
114
|
+
if (!!name?.trim?.()) {
|
|
115
|
+
logger.analytics?.interaction(name, analyticsData)
|
|
116
|
+
}
|
|
117
|
+
}
|
|
95
118
|
onPress && onPress()
|
|
96
119
|
}
|
|
97
120
|
if (TypeGuards.isNumber(debounce)) {
|
|
@@ -240,4 +263,8 @@ const _Touchable = forwardRef<
|
|
|
240
263
|
)
|
|
241
264
|
})
|
|
242
265
|
|
|
243
|
-
export const Touchable = _Touchable as ((props: TouchableProps) => JSX.Element)
|
|
266
|
+
export const Touchable = _Touchable as ((props: TouchableProps) => JSX.Element) & {
|
|
267
|
+
defaultProps: Partial<TouchableProps>
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
Touchable.defaultProps = defaultProps
|