@codeleap/mobile 3.13.5 → 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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codeleap/mobile",
3
- "version": "3.13.5",
3
+ "version": "3.14.0",
4
4
  "main": "src/index.ts",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {
@@ -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 headerProps:ModalHeaderProps = {
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, { zIndex: TypeGuards.isNumber(zIndex) ? zIndex : wrapperStyle?.zIndex }]}
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
- wrapperProps={{
193
- transition: { ...variantStyles['backdrop:transition'] },
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
- { ...scrollProps}
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
  }
@@ -20,6 +20,7 @@ export type ModalParts =
20
20
  | 'description'
21
21
  | 'titleWrapper'
22
22
  | `closeButton${Capitalize<ActionIconComposition>}`
23
+ | 'topSpacing'
23
24
 
24
25
  export type ModalComposition =
25
26
  | ModalParts