@codeleap/mobile 2.3.19 → 2.3.20
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/dist/components/AutoComplete/index.d.ts +1 -0
- package/dist/components/AutoComplete/index.js +2 -1
- package/dist/components/AutoComplete/index.js.map +1 -1
- package/dist/components/AutoComplete/styles.js +67 -3
- package/dist/components/AutoComplete/styles.js.map +1 -1
- package/dist/components/Checkbox/index.d.ts +1 -1
- package/dist/components/EmptyPlaceholder/index.d.ts +5 -2
- package/dist/components/EmptyPlaceholder/index.js +19 -5
- package/dist/components/EmptyPlaceholder/index.js.map +1 -1
- package/dist/components/EmptyPlaceholder/styles.d.ts +1 -1
- package/dist/components/EmptyPlaceholder/styles.js +5 -7
- package/dist/components/EmptyPlaceholder/styles.js.map +1 -1
- package/dist/components/Grid/styles.d.ts +49 -0
- package/dist/components/Image/index.d.ts +1 -0
- package/dist/components/Image/index.js +21 -3
- package/dist/components/Image/index.js.map +1 -1
- package/dist/components/List/styles.d.ts +49 -0
- package/dist/components/List/styles.js +5 -4
- package/dist/components/List/styles.js.map +1 -1
- package/dist/components/Modal/index.d.ts +2 -0
- package/dist/components/Modal/index.js +11 -9
- package/dist/components/Modal/index.js.map +1 -1
- package/dist/components/Modal/styles.d.ts +2 -2
- package/dist/components/Modal/styles.js +18 -19
- package/dist/components/Modal/styles.js.map +1 -1
- package/dist/components/MultiSelect/index.js +7 -5
- package/dist/components/MultiSelect/index.js.map +1 -1
- package/dist/components/MultiSelect/styles.d.ts +0 -51
- package/dist/components/MultiSelect/styles.js +67 -5
- package/dist/components/MultiSelect/styles.js.map +1 -1
- package/dist/components/MultiSelect/types.d.ts +8 -1
- package/dist/components/Scroll/styles.d.ts +49 -0
- package/dist/components/Scroll/styles.js +3 -4
- package/dist/components/Scroll/styles.js.map +1 -1
- package/dist/components/SegmentedControl/index.js +5 -4
- package/dist/components/SegmentedControl/index.js.map +1 -1
- package/dist/components/SegmentedControl/styles.d.ts +1 -1
- package/dist/components/SegmentedControl/styles.js +9 -9
- package/dist/components/SegmentedControl/styles.js.map +1 -1
- package/dist/components/Select/index.d.ts +4 -1
- package/dist/components/Select/index.js +16 -21
- package/dist/components/Select/index.js.map +1 -1
- package/dist/components/Select/styles.d.ts +54 -53
- package/dist/components/Select/styles.js +61 -10
- package/dist/components/Select/styles.js.map +1 -1
- package/dist/components/Select/types.d.ts +8 -1
- package/dist/components/TextInput/index.js +4 -1
- package/dist/components/TextInput/index.js.map +1 -1
- package/dist/components/Touchable/index.js +5 -1
- package/dist/components/Touchable/index.js.map +1 -1
- package/dist/components/View/index.js +19 -13
- package/dist/components/View/index.js.map +1 -1
- package/dist/components/defaultStyles.d.ts +147 -51
- package/dist/utils/KeyboardAware/context.js +1 -6
- package/dist/utils/KeyboardAware/context.js.map +1 -1
- package/dist/utils/PermissionManager/context.js +3 -2
- package/dist/utils/PermissionManager/context.js.map +1 -1
- package/dist/utils/hooks.d.ts +2 -0
- package/dist/utils/hooks.js +44 -1
- package/dist/utils/hooks.js.map +1 -1
- package/dist/utils/theme.js +3 -3
- package/dist/utils/theme.js.map +1 -1
- package/package.json +3 -2
- package/src/components/AutoComplete/index.tsx +5 -1
- package/src/components/AutoComplete/styles.ts +112 -6
- package/src/components/EmptyPlaceholder/index.tsx +32 -8
- package/src/components/EmptyPlaceholder/styles.ts +18 -15
- package/src/components/Image/index.tsx +33 -3
- package/src/components/List/styles.ts +7 -1
- package/src/components/Modal/index.tsx +12 -7
- package/src/components/Modal/styles.ts +36 -46
- package/src/components/MultiSelect/index.tsx +10 -4
- package/src/components/MultiSelect/styles.ts +117 -4
- package/src/components/MultiSelect/types.ts +8 -0
- package/src/components/Scroll/styles.ts +4 -1
- package/src/components/SegmentedControl/index.tsx +5 -4
- package/src/components/SegmentedControl/styles.ts +13 -10
- package/src/components/Select/index.tsx +50 -27
- package/src/components/Select/styles.ts +103 -25
- package/src/components/Select/types.ts +11 -1
- package/src/components/TextInput/index.tsx +3 -1
- package/src/components/Touchable/index.tsx +5 -3
- package/src/components/View/index.tsx +25 -13
- package/src/utils/KeyboardAware/context.tsx +2 -7
- package/src/utils/PermissionManager/context.tsx +1 -1
- package/src/utils/hooks.ts +50 -0
- package/src/utils/theme.ts +1 -1
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
ViewStyles,
|
|
8
8
|
BaseViewProps,
|
|
9
9
|
useCodeleapContext,
|
|
10
|
+
useMemo,
|
|
10
11
|
} from '@codeleap/common'
|
|
11
12
|
import { View as NativeView } from 'react-native'
|
|
12
13
|
import { MotiView, MotiProps } from 'moti'
|
|
@@ -73,26 +74,37 @@ type GapProps = ViewProps & {
|
|
|
73
74
|
|
|
74
75
|
export const Gap:React.FC<GapProps> = ({ children, value, defaultProps = {}, ...props }) => {
|
|
75
76
|
const { Theme } = useCodeleapContext()
|
|
77
|
+
const childArr = React.Children.toArray(children)
|
|
78
|
+
|
|
76
79
|
const horizontal = props.variants?.includes('row')
|
|
80
|
+
const spacings = useMemo(() => {
|
|
81
|
+
return childArr.map((_, idx) => {
|
|
82
|
+
let spacingFunction = horizontal ? 'marginHorizontal' : 'marginVertical'
|
|
83
|
+
|
|
84
|
+
switch (idx) {
|
|
85
|
+
case 0:
|
|
86
|
+
spacingFunction = horizontal ? 'marginRight' : 'marginBottom'
|
|
87
|
+
break
|
|
88
|
+
case childArr.length - 1:
|
|
89
|
+
spacingFunction = horizontal ? 'marginLeft' : 'marginTop'
|
|
90
|
+
break
|
|
91
|
+
default:
|
|
92
|
+
break
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return Theme.spacing[spacingFunction](value / 2)
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
}, [childArr.length, horizontal])
|
|
99
|
+
|
|
77
100
|
return (
|
|
78
101
|
<View {...props}>
|
|
79
102
|
{
|
|
80
|
-
|
|
103
|
+
childArr.map((Element, idx, childArr) => {
|
|
81
104
|
if (React.isValidElement(Element)) {
|
|
82
105
|
const props = { ...Element.props, ...defaultProps }
|
|
83
106
|
|
|
84
|
-
|
|
85
|
-
switch (idx) {
|
|
86
|
-
case 0:
|
|
87
|
-
spacingFunction = horizontal ? 'marginRight' : 'marginBottom'
|
|
88
|
-
break
|
|
89
|
-
case childArr.length - 1:
|
|
90
|
-
spacingFunction = horizontal ? 'marginLeft' : 'marginTop'
|
|
91
|
-
break
|
|
92
|
-
default:
|
|
93
|
-
break
|
|
94
|
-
}
|
|
95
|
-
props.style = [props.style, Theme.spacing[spacingFunction](value / 2)]
|
|
107
|
+
props.style = [props.style, spacings[idx]]
|
|
96
108
|
return React.cloneElement(Element, props)
|
|
97
109
|
}
|
|
98
110
|
return Element
|
|
@@ -21,7 +21,7 @@ export const KeyboardCtx = React.createContext({} as TKeyboardCtx)
|
|
|
21
21
|
export const KeyboardProvider = ({ children }) => {
|
|
22
22
|
const [keyboardEvent, setKeyboardEvent] = useState<KeyboardEvent>(null)
|
|
23
23
|
const [keyboardVisible, setKeyboardVisible] = useState(false)
|
|
24
|
-
|
|
24
|
+
|
|
25
25
|
useEffect(() => {
|
|
26
26
|
const eventNames = Platform.select<KeyboardVisibilityEvents>({
|
|
27
27
|
ios: {
|
|
@@ -50,17 +50,12 @@ export const KeyboardProvider = ({ children }) => {
|
|
|
50
50
|
}
|
|
51
51
|
}, [])
|
|
52
52
|
|
|
53
|
-
let adjustKeyboard = 0
|
|
54
|
-
|
|
55
|
-
if (Platform.OS === 'android') {
|
|
56
|
-
adjustKeyboard = Theme.values.safeAreaTop
|
|
57
|
-
}
|
|
58
53
|
const height = keyboardEvent?.endCoordinates?.height ?? 0
|
|
59
54
|
|
|
60
55
|
const _return = {
|
|
61
56
|
event: keyboardEvent,
|
|
62
57
|
isVisible: keyboardVisible,
|
|
63
|
-
height: (!!height && keyboardVisible) ? height
|
|
58
|
+
height: (!!height && keyboardVisible) ? height : 0,
|
|
64
59
|
...Keyboard,
|
|
65
60
|
}
|
|
66
61
|
|
|
@@ -193,7 +193,7 @@ export function usePermissionModal(permissionName: string) {
|
|
|
193
193
|
const permissionCtx = usePermissions()
|
|
194
194
|
const modalState = modals.state[modalId]
|
|
195
195
|
|
|
196
|
-
const currentState = permissionCtx
|
|
196
|
+
const currentState = permissionCtx?.state?.[permissionName]
|
|
197
197
|
const status = currentState
|
|
198
198
|
const [debouncedStatus, reset] = useDebounce(status, modals.transitionDuration * 0.5)
|
|
199
199
|
|
package/src/utils/hooks.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { onMount, onUpdate, shadeColor, TypeGuards, usePrevious, useRef, useState } from '@codeleap/common'
|
|
2
2
|
import { Animated, AppState, AppStateStatus, Platform, PressableAndroidRippleConfig, BackHandler } from 'react-native'
|
|
3
|
+
// @ts-ignore
|
|
4
|
+
import AsyncStorage from '@react-native-community/async-storage'
|
|
3
5
|
|
|
4
6
|
export function useAnimateColor(value: string, opts?: Partial<Animated.TimingAnimationConfig>) {
|
|
5
7
|
const iters = useRef(0)
|
|
@@ -161,3 +163,51 @@ export function useBackButton(cb: () => boolean|void, deps = []) {
|
|
|
161
163
|
}
|
|
162
164
|
}, deps)
|
|
163
165
|
}
|
|
166
|
+
type StateSetter<T> = T | ((prev:T) => T)
|
|
167
|
+
|
|
168
|
+
export function useAsyncStorageState<T>(key:string, defaultValue?: T) {
|
|
169
|
+
const [value, _setValue] = useState<T>(undefined)
|
|
170
|
+
|
|
171
|
+
onMount(() => {
|
|
172
|
+
AsyncStorage.getItem(key).then(val => {
|
|
173
|
+
let storedValue = defaultValue
|
|
174
|
+
|
|
175
|
+
if (val) {
|
|
176
|
+
storedValue = JSON.parse(val)
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
_setValue(storedValue)
|
|
180
|
+
})
|
|
181
|
+
})
|
|
182
|
+
|
|
183
|
+
const setValue = (to: StateSetter<T>) => {
|
|
184
|
+
return new Promise<void>((resolve, reject) => {
|
|
185
|
+
_setValue((prev) => {
|
|
186
|
+
let newValue = prev
|
|
187
|
+
try {
|
|
188
|
+
|
|
189
|
+
if (typeof to !== 'function') {
|
|
190
|
+
newValue = to
|
|
191
|
+
} else {
|
|
192
|
+
const fn = to as ((prev:T) => T)
|
|
193
|
+
newValue = fn(value)
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
const jsonVal = JSON.stringify(newValue)
|
|
197
|
+
|
|
198
|
+
AsyncStorage.setItem(key, jsonVal).then(resolve).catch(reject)
|
|
199
|
+
resolve()
|
|
200
|
+
return newValue
|
|
201
|
+
} catch (e) {
|
|
202
|
+
reject(e)
|
|
203
|
+
return newValue
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
})
|
|
207
|
+
})
|
|
208
|
+
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
return [value, setValue] as [T, typeof setValue]
|
|
212
|
+
}
|
|
213
|
+
|
package/src/utils/theme.ts
CHANGED
|
@@ -9,7 +9,7 @@ type AppValues = {
|
|
|
9
9
|
export function getMobileThemeValues(initialWindowMetrics, values: AppValues) {
|
|
10
10
|
const screenDimensions = Dimensions.get('screen')
|
|
11
11
|
|
|
12
|
-
const hasNotch =
|
|
12
|
+
const hasNotch = DeviceInfo.hasNotch()
|
|
13
13
|
const hasIsland = DeviceInfo.hasDynamicIsland()
|
|
14
14
|
const bottomNavHeight = Platform.OS === 'android' ? initialWindowMetrics?.insets?.bottom : 0
|
|
15
15
|
|