@codeleap/mobile 2.2.2 → 2.2.5

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.
Files changed (109) hide show
  1. package/dist/components/ActionIcon/styles.d.ts +11 -10
  2. package/dist/components/ActionIcon/styles.js +5 -1
  3. package/dist/components/ActionIcon/styles.js.map +1 -1
  4. package/dist/components/ActivityIndicator/styles.d.ts +10 -10
  5. package/dist/components/Animated.d.ts +1 -0
  6. package/dist/components/AutoComplete/index.d.ts +3 -3
  7. package/dist/components/AutoComplete/index.js +3 -3
  8. package/dist/components/AutoComplete/index.js.map +1 -1
  9. package/dist/components/AutoComplete/styles.d.ts +10 -10
  10. package/dist/components/AutoComplete/styles.js +1 -3
  11. package/dist/components/AutoComplete/styles.js.map +1 -1
  12. package/dist/components/Backdrop/styles.d.ts +10 -10
  13. package/dist/components/Button/index.d.ts +24 -24
  14. package/dist/components/Button/styles.d.ts +10 -10
  15. package/dist/components/Checkbox/index.d.ts +1 -1
  16. package/dist/components/Checkbox/styles.d.ts +10 -10
  17. package/dist/components/ContentView/styles.d.ts +10 -10
  18. package/dist/components/Drawer/index.js +1 -1
  19. package/dist/components/Drawer/index.js.map +1 -1
  20. package/dist/components/Drawer/styles.d.ts +10 -10
  21. package/dist/components/Drawer/styles.js +6 -2
  22. package/dist/components/Drawer/styles.js.map +1 -1
  23. package/dist/components/EmptyPlaceholder/styles.d.ts +9 -9
  24. package/dist/components/FileInput/styles.d.ts +10 -10
  25. package/dist/components/Icon/index.js +7 -3
  26. package/dist/components/Icon/index.js.map +1 -1
  27. package/dist/components/Icon/styles.d.ts +11 -10
  28. package/dist/components/Icon/styles.js +4 -0
  29. package/dist/components/Icon/styles.js.map +1 -1
  30. package/dist/components/Image/styles.d.ts +10 -10
  31. package/dist/components/List/PaginationIndicator.d.ts +10 -10
  32. package/dist/components/Modal/index.d.ts +2 -0
  33. package/dist/components/Modal/index.js +8 -2
  34. package/dist/components/Modal/index.js.map +1 -1
  35. package/dist/components/Modal/styles.d.ts +10 -10
  36. package/dist/components/Modal/styles.js +9 -5
  37. package/dist/components/Modal/styles.js.map +1 -1
  38. package/dist/components/MultiSelect/styles.d.ts +10 -10
  39. package/dist/components/Pager/styles.d.ts +10 -10
  40. package/dist/components/RadioInput/styles.d.ts +10 -10
  41. package/dist/components/Scroll/index.d.ts +1 -1
  42. package/dist/components/Scroll/index.js +7 -5
  43. package/dist/components/Scroll/index.js.map +1 -1
  44. package/dist/components/Sections/index.d.ts +1 -1
  45. package/dist/components/SegmentedControl/styles.d.ts +10 -10
  46. package/dist/components/Select/index.js +12 -14
  47. package/dist/components/Select/index.js.map +1 -1
  48. package/dist/components/Select/styles.d.ts +10 -10
  49. package/dist/components/Select/styles.js +1 -4
  50. package/dist/components/Select/styles.js.map +1 -1
  51. package/dist/components/Slider/styles.d.ts +10 -10
  52. package/dist/components/Switch/styles.d.ts +10 -10
  53. package/dist/components/Text/styles.d.ts +10 -10
  54. package/dist/components/TextInput/index.d.ts +20 -20
  55. package/dist/components/TextInput/index.js +18 -10
  56. package/dist/components/TextInput/index.js.map +1 -1
  57. package/dist/components/TextInput/styles.d.ts +10 -10
  58. package/dist/components/Touchable/index.d.ts +1 -0
  59. package/dist/components/Touchable/index.js +21 -35
  60. package/dist/components/Touchable/index.js.map +1 -1
  61. package/dist/components/Touchable/styles.d.ts +10 -10
  62. package/dist/components/View/index.d.ts +3 -0
  63. package/dist/components/View/index.js +5 -2
  64. package/dist/components/View/index.js.map +1 -1
  65. package/dist/components/View/styles.d.ts +10 -10
  66. package/dist/components/defaultStyles.d.ts +251 -249
  67. package/dist/components/legacy/Modal/styles.d.ts +10 -10
  68. package/dist/components/legacy/Pager/styles.d.ts +10 -10
  69. package/dist/types/utility.d.ts +6 -0
  70. package/dist/utils/KeyboardAware/context.d.ts +13 -0
  71. package/dist/utils/KeyboardAware/context.js +65 -0
  72. package/dist/utils/KeyboardAware/context.js.map +1 -0
  73. package/dist/utils/KeyboardAware/index.d.ts +1 -0
  74. package/dist/utils/KeyboardAware/index.js +1 -0
  75. package/dist/utils/KeyboardAware/index.js.map +1 -1
  76. package/dist/utils/KeyboardAware/keyboardHooks.d.ts +9 -13
  77. package/dist/utils/KeyboardAware/keyboardHooks.js +17 -40
  78. package/dist/utils/KeyboardAware/keyboardHooks.js.map +1 -1
  79. package/dist/utils/ModalManager/context.js +8 -5
  80. package/dist/utils/ModalManager/context.js.map +1 -1
  81. package/dist/utils/index.d.ts +1 -0
  82. package/dist/utils/index.js +1 -0
  83. package/dist/utils/index.js.map +1 -1
  84. package/dist/utils/theme.d.ts +36 -0
  85. package/dist/utils/theme.js +48 -0
  86. package/dist/utils/theme.js.map +1 -0
  87. package/package.json +1 -1
  88. package/src/components/ActionIcon/styles.ts +5 -0
  89. package/src/components/AutoComplete/index.tsx +10 -5
  90. package/src/components/AutoComplete/styles.ts +2 -6
  91. package/src/components/Drawer/index.tsx +1 -2
  92. package/src/components/Drawer/styles.ts +7 -2
  93. package/src/components/Icon/index.tsx +14 -8
  94. package/src/components/Icon/styles.ts +5 -0
  95. package/src/components/Modal/index.tsx +14 -1
  96. package/src/components/Modal/styles.ts +13 -6
  97. package/src/components/Scroll/index.tsx +7 -2
  98. package/src/components/Select/index.tsx +25 -12
  99. package/src/components/Select/styles.ts +6 -5
  100. package/src/components/TextInput/index.tsx +30 -10
  101. package/src/components/Touchable/index.tsx +22 -39
  102. package/src/components/View/index.tsx +16 -2
  103. package/src/types/utility.ts +6 -0
  104. package/src/utils/KeyboardAware/context.tsx +73 -0
  105. package/src/utils/KeyboardAware/index.ts +1 -0
  106. package/src/utils/KeyboardAware/keyboardHooks.ts +30 -61
  107. package/src/utils/ModalManager/context.tsx +21 -18
  108. package/src/utils/index.ts +1 -0
  109. package/src/utils/theme.ts +50 -0
@@ -0,0 +1,73 @@
1
+ import React from 'react'
2
+ import { useCodeleapContext, useEffect, useState, useContext } from '@codeleap/common'
3
+ import {
4
+ Keyboard,
5
+ Platform,
6
+ KeyboardEvent,
7
+ KeyboardEventName,
8
+ } from 'react-native'
9
+
10
+ type KeyboardVisibilityEvents = {
11
+ show: KeyboardEventName
12
+ hide: KeyboardEventName
13
+ }
14
+ type TKeyboardCtx = {
15
+ event: KeyboardEvent
16
+ isVisible: boolean
17
+ height: number
18
+ }
19
+ export const KeyboardCtx = React.createContext({} as TKeyboardCtx)
20
+
21
+ export const KeyboardProvider = ({ children }) => {
22
+ const [keyboardEvent, setKeyboardEvent] = useState<KeyboardEvent>(null)
23
+
24
+ const { Theme } = useCodeleapContext()
25
+ useEffect(() => {
26
+ const eventNames = Platform.select<KeyboardVisibilityEvents>({
27
+ ios: {
28
+ show: 'keyboardWillShow',
29
+ hide: 'keyboardWillHide',
30
+ },
31
+ android: {
32
+ show: 'keyboardDidShow',
33
+ hide: 'keyboardDidHide',
34
+ },
35
+ })
36
+ const events = [
37
+ Keyboard.addListener(eventNames.show, (e) => {
38
+
39
+ setKeyboardEvent(e)
40
+ }),
41
+ Keyboard.addListener(eventNames.hide, (e) => {
42
+
43
+ setKeyboardEvent(e)
44
+ }),
45
+ ]
46
+ return () => {
47
+ events.forEach(e => e.remove())
48
+ }
49
+ }, [])
50
+
51
+ let adjustKeyboard = 0
52
+
53
+ if (Platform.OS === 'android') {
54
+ adjustKeyboard = Theme.values.safeAreaTop
55
+ }
56
+ const height = keyboardEvent?.endCoordinates?.height ?? 0
57
+
58
+ const _return = {
59
+ event: keyboardEvent,
60
+ isVisible: height > 0,
61
+ height: height ? height + adjustKeyboard : 0,
62
+ ...Keyboard,
63
+ }
64
+
65
+ return <KeyboardCtx.Provider value={_return}>
66
+ {children}
67
+ </KeyboardCtx.Provider >
68
+
69
+ }
70
+
71
+ export const useKeyboard = () => {
72
+ return useContext(KeyboardCtx)
73
+ }
@@ -5,6 +5,7 @@ import KeyboardAwareScrollView from './lib/KeyboardAwareScrollView'
5
5
  import KeyboardAwareFlatList from './lib/KeyboardAwareFlatList'
6
6
  import KeyboardAwareSectionList from './lib/KeyboardAwareSectionList'
7
7
  export * from './keyboardHooks'
8
+ export * from './context'
8
9
 
9
10
  export {
10
11
  listenToKeyboardEvents,
@@ -1,70 +1,22 @@
1
- import { PropsOf, TypeGuards, useCodeleapContext } from '@codeleap/common'
2
- import { useEffect, useState } from 'react'
3
- import {
4
- Keyboard,
5
- Platform,
6
- KeyboardEvent,
7
- KeyboardEventName,
8
- Dimensions,
9
- ScrollView,
10
- StyleSheet,
11
- } from 'react-native'
12
-
13
- type KeyboardVisibilityEvents = {
14
- show: KeyboardEventName
15
- hide: KeyboardEventName
16
- }
17
-
18
- export const useKeyboard = () => {
19
- const [keyboardEvent, setKeyboardEvent] = useState<KeyboardEvent>(null)
20
- const [keyboardVisible, setKeyboardVisible] = useState(false)
21
-
22
- useEffect(() => {
23
- const eventNames = Platform.select<KeyboardVisibilityEvents>({
24
- ios: {
25
- show: 'keyboardWillShow',
26
- hide: 'keyboardWillHide',
27
- },
28
- android: {
29
- show: 'keyboardDidShow',
30
- hide: 'keyboardDidHide',
31
- },
32
- })
33
- const events = [
34
- Keyboard.addListener(eventNames.show, (e) => {
35
- setKeyboardVisible(true)
36
- setKeyboardEvent(e)
37
- }),
38
- Keyboard.addListener(eventNames.hide, (e) => {
39
- setKeyboardVisible(false)
40
- setKeyboardEvent(e)
41
- }),
42
- ]
43
- return () => {
44
- events.forEach(e => e.remove())
45
- }
46
- }, [])
47
-
48
- const _return = {
49
- event: keyboardEvent,
50
- isVisible: keyboardVisible,
51
- height: keyboardEvent?.endCoordinates?.height || 0,
52
- ...Keyboard,
53
- }
54
-
55
- return _return
56
- }
1
+ import { PropsOf, useCodeleapContext, TypeGuards } from '@codeleap/common'
2
+ import { ScrollView, Platform, StyleSheet, Dimensions, EasingFunction, Easing } from 'react-native'
3
+ import { TransitionConfig } from '../../types'
4
+ import { useKeyboard } from './context'
57
5
  type ScrollViewProps = Partial<
58
6
  Pick<
59
7
  PropsOf<typeof ScrollView>,
60
8
  'horizontal' | 'contentContainerStyle' | 'style'
61
9
  >
62
- >
10
+ > & {
11
+ transition?: TransitionConfig
12
+ }
63
13
 
64
14
  export type GetKeyboardAwarePropsOptions = {
65
15
  baseStyleProp?: 'style' | 'contentContainerStyle'
66
16
  adapt?: 'height' | 'maxHeight' | 'paddingBottom' | 'marginBottom' | 'bottom'
67
17
  enabled?: boolean
18
+ animated?: boolean
19
+ transition?: TransitionConfig
68
20
  enableOnAndroid?: boolean
69
21
  }
70
22
  type UseKeyboardAwareViewParams = {
@@ -77,12 +29,19 @@ export const useKeyboardAwareView = (params?: UseKeyboardAwareViewParams) => {
77
29
  props?:T,
78
30
  options?: GetKeyboardAwarePropsOptions,
79
31
  ): T {
32
+
80
33
  const _options:GetKeyboardAwarePropsOptions = {
81
34
  adapt: 'maxHeight',
82
35
  baseStyleProp: 'style',
83
36
  enabled: true,
84
- enableOnAndroid: true,
37
+ enableOnAndroid: false,
38
+ animated: false,
85
39
  ...options,
40
+ transition: {
41
+ easing: Easing.linear,
42
+ duration: 200,
43
+ type: 'timing',
44
+ },
86
45
  }
87
46
 
88
47
  if (!_options.enabled || props?.horizontal || (Platform.OS === 'android' && !_options.enableOnAndroid)) return props
@@ -106,7 +65,9 @@ export const useKeyboardAwareView = (params?: UseKeyboardAwareViewParams) => {
106
65
  }
107
66
  }
108
67
 
109
- const newStyleProp = {
68
+ const newStyleProp = _options.animated ? {
69
+
70
+ } : {
110
71
  ...baseStyle,
111
72
  }
112
73
 
@@ -143,10 +104,18 @@ export const useKeyboardAwareView = (params?: UseKeyboardAwareViewParams) => {
143
104
 
144
105
  if (!valid) return props
145
106
 
146
- return {
107
+ const _return = {
147
108
  ...props,
148
- [_options.baseStyleProp]: newStyleProp,
109
+ [_options?.animated ? 'animate' : _options.baseStyleProp]: newStyleProp,
110
+ }
111
+
112
+ if (_options.animated && !!_options?.transition) {
113
+ _return.transition = JSON.parse(JSON.stringify({
114
+ [_options.adapt]: _options.transition,
115
+ }))
149
116
  }
117
+
118
+ return _return
150
119
  }
151
120
  return {
152
121
  keyboard,
@@ -1,7 +1,7 @@
1
1
  import * as React from 'react'
2
2
  import { AnyFunction, onUpdate, TypeGuards, useCodeleapContext, useState } from '@codeleap/common'
3
3
  import { PortalProvider } from '@gorhom/portal'
4
- import { ModalProps } from '../../components/Modal'
4
+ import { KeyboardProvider } from '../KeyboardAware'
5
5
 
6
6
  export type AppModalProps = {
7
7
  visible: boolean
@@ -136,23 +136,26 @@ export function Provider({ children }) {
136
136
  setModals(newModals)
137
137
  }
138
138
 
139
- return <ModalContext.Provider value={{
140
- state: modals,
141
- toggleModal,
142
- setModal,
143
- currentModal,
144
- attach,
145
- isVisible,
146
- remove,
147
- transition,
148
- transitionDuration: defaultDuration,
149
-
150
- }}>
151
- <PortalProvider>
152
-
153
- {children}
154
- </PortalProvider>
155
- </ModalContext.Provider>
139
+ return <KeyboardProvider>
140
+ <ModalContext.Provider value={{
141
+ state: modals,
142
+ toggleModal,
143
+ setModal,
144
+ currentModal,
145
+ attach,
146
+ isVisible,
147
+ remove,
148
+ transition,
149
+ transitionDuration: defaultDuration,
150
+
151
+ }}>
152
+ <PortalProvider>
153
+
154
+ {children}
155
+ </PortalProvider>
156
+ </ModalContext.Provider>
157
+ </KeyboardProvider>
158
+
156
159
  }
157
160
 
158
161
  export function useModalContext() {
@@ -8,3 +8,4 @@ import * as Permissions from './PermissionManager'
8
8
  export { Permissions }
9
9
  export * from './KeyboardAware'
10
10
  export * from './input'
11
+ export * from './theme'
@@ -0,0 +1,50 @@
1
+ import { Platform, Dimensions, StatusBar, StyleSheet } from 'react-native'
2
+
3
+ export function getMobileThemeValues(initialWindowMetrics) {
4
+ const screenDimensions = Dimensions.get('screen')
5
+
6
+ const hasNotch = Platform.OS === 'ios' ? (Dimensions.get('window').height >= 812) : (initialWindowMetrics?.insets?.top > 24 || StatusBar.currentHeight > 24)
7
+ const bottomNavHeight = Platform.OS === 'android' ? initialWindowMetrics?.insets?.bottom : 0
8
+
9
+ const prefersConstantNavigationBar = bottomNavHeight > 0
10
+
11
+ const safeAreaTop = Platform.OS === 'ios' ? (hasNotch ? 34 : 20) : StatusBar.currentHeight
12
+
13
+ const safeAreaBottom = (hasNotch && !prefersConstantNavigationBar ? 20 : 0)
14
+ return {
15
+ ...screenDimensions,
16
+
17
+ pixel: StyleSheet.hairlineWidth,
18
+ hasNotch,
19
+ prefersConstantNavigationBar,
20
+ safeAreaTop,
21
+ safeAreaBottom,
22
+ keyboardVerticalOffset: Platform.OS === 'ios' ? 57 : 47,
23
+ get headerHeight() { return 48 },
24
+ get tabBarHeight() { return 63 + (prefersConstantNavigationBar ? 0 : this.safeAreaBottom) },
25
+ bottomNavHeight,
26
+ get window() {
27
+ return {
28
+ height: screenDimensions.height - (bottomNavHeight + safeAreaTop),
29
+ width: screenDimensions.width,
30
+ }
31
+ },
32
+ transitions: {
33
+ modal: {
34
+ duration: 100,
35
+ type: 'timing',
36
+ },
37
+ },
38
+ buttons: {
39
+ small: {
40
+ height: 40,
41
+ },
42
+ default: {
43
+ height: 50,
44
+ },
45
+ large: {
46
+ height: 60,
47
+ },
48
+ },
49
+ } as const
50
+ }