@chem-po/react-native 0.0.19 → 0.0.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/lib/commonjs/components/button/ActionButton.js +97 -0
- package/lib/commonjs/components/button/ActionButton.js.map +1 -0
- package/lib/commonjs/components/button/index.js +11 -0
- package/lib/commonjs/components/button/index.js.map +1 -1
- package/lib/commonjs/components/feed/MediaFeed.js +3 -4
- package/lib/commonjs/components/feed/MediaFeed.js.map +1 -1
- package/lib/commonjs/components/form/input/Editable.js +3 -3
- package/lib/commonjs/components/form/input/Editable.js.map +1 -1
- package/lib/commonjs/components/loading/Loading.js +1 -55
- package/lib/commonjs/components/loading/Loading.js.map +1 -1
- package/lib/commonjs/components/loading/LoadingOverlay.js +66 -0
- package/lib/commonjs/components/loading/LoadingOverlay.js.map +1 -0
- package/lib/commonjs/components/loading/index.js +11 -0
- package/lib/commonjs/components/loading/index.js.map +1 -1
- package/lib/commonjs/hooks/useFadeIn.js +45 -0
- package/lib/commonjs/hooks/useFadeIn.js.map +1 -0
- package/lib/module/components/button/ActionButton.js +88 -0
- package/lib/module/components/button/ActionButton.js.map +1 -0
- package/lib/module/components/button/index.js +1 -0
- package/lib/module/components/button/index.js.map +1 -1
- package/lib/module/components/feed/MediaFeed.js +2 -3
- package/lib/module/components/feed/MediaFeed.js.map +1 -1
- package/lib/module/components/form/input/Editable.js +2 -2
- package/lib/module/components/form/input/Editable.js.map +1 -1
- package/lib/module/components/loading/Loading.js +2 -55
- package/lib/module/components/loading/Loading.js.map +1 -1
- package/lib/module/components/loading/LoadingOverlay.js +57 -0
- package/lib/module/components/loading/LoadingOverlay.js.map +1 -0
- package/lib/module/components/loading/index.js +1 -0
- package/lib/module/components/loading/index.js.map +1 -1
- package/lib/module/hooks/useFadeIn.js +38 -0
- package/lib/module/hooks/useFadeIn.js.map +1 -0
- package/lib/typescript/components/button/ActionButton.d.ts +15 -0
- package/lib/typescript/components/button/ActionButton.d.ts.map +1 -0
- package/lib/typescript/components/button/index.d.ts +1 -0
- package/lib/typescript/components/button/index.d.ts.map +1 -1
- package/lib/typescript/components/loading/Loading.d.ts +0 -6
- package/lib/typescript/components/loading/Loading.d.ts.map +1 -1
- package/lib/typescript/components/loading/LoadingOverlay.d.ts +17 -0
- package/lib/typescript/components/loading/LoadingOverlay.d.ts.map +1 -0
- package/lib/typescript/components/loading/index.d.ts +1 -0
- package/lib/typescript/components/loading/index.d.ts.map +1 -1
- package/lib/typescript/hooks/useFadeIn.d.ts +10 -0
- package/lib/typescript/hooks/useFadeIn.d.ts.map +1 -0
- package/package.json +3 -3
- package/src/components/button/ActionButton.tsx +108 -0
- package/src/components/button/index.ts +1 -0
- package/src/components/feed/MediaFeed.tsx +2 -2
- package/src/components/form/input/Editable.tsx +2 -2
- package/src/components/loading/Loading.tsx +2 -67
- package/src/components/loading/LoadingOverlay.tsx +64 -0
- package/src/components/loading/index.ts +1 -0
- package/src/hooks/useFadeIn.ts +48 -0
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
import { Ionicons } from '@expo/vector-icons'
|
|
10
10
|
import React, { useCallback, useEffect, useMemo } from 'react'
|
|
11
11
|
import { StyleSheet, TouchableOpacity, View, ViewStyle } from 'react-native'
|
|
12
|
-
import { LoadingOverlay } from '../../loading/
|
|
12
|
+
import { LoadingOverlay } from '../../loading/LoadingOverlay'
|
|
13
13
|
import { UploadProgress } from '../UploadProgress'
|
|
14
14
|
import { FieldView } from '../view'
|
|
15
15
|
import { StandaloneInput } from './StandaloneInput'
|
|
@@ -203,7 +203,7 @@ export const Editable = <T extends Field>({
|
|
|
203
203
|
</View>
|
|
204
204
|
</View>
|
|
205
205
|
)}
|
|
206
|
-
<LoadingOverlay
|
|
206
|
+
<LoadingOverlay loading={isLoading} />
|
|
207
207
|
</View>
|
|
208
208
|
<UploadProgress uploads={uploads} />
|
|
209
209
|
</View>
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ThemedAsset, useAppAssets, useTheme } from '@chem-po/react'
|
|
2
2
|
import LottieView from 'lottie-react-native'
|
|
3
|
-
import React, {
|
|
4
|
-
import {
|
|
3
|
+
import React, { useMemo } from 'react'
|
|
4
|
+
import { Image, StyleSheet, Text, View, ViewStyle } from 'react-native'
|
|
5
5
|
|
|
6
6
|
export const LottieLoadingLogo = ({
|
|
7
7
|
size = 30,
|
|
@@ -124,62 +124,6 @@ export const Loading = ({
|
|
|
124
124
|
return inBox ? <View style={styles.boxContainer}>{body}</View> : body
|
|
125
125
|
}
|
|
126
126
|
|
|
127
|
-
export const LoadingOverlay = ({
|
|
128
|
-
isLoading,
|
|
129
|
-
text,
|
|
130
|
-
inFeed,
|
|
131
|
-
style,
|
|
132
|
-
}: {
|
|
133
|
-
isLoading: boolean
|
|
134
|
-
text?: string
|
|
135
|
-
inFeed?: boolean
|
|
136
|
-
style?: ViewStyle
|
|
137
|
-
}) => {
|
|
138
|
-
const { colorMode } = useTheme()
|
|
139
|
-
const bgColor = colorMode === 'dark' ? 'rgba(0, 0, 0, 0.53)' : 'rgba(255, 255, 255, 0.67)'
|
|
140
|
-
const opacity = useMemo(() => new Animated.Value(0), [])
|
|
141
|
-
const [isAnimating, setIsAnimating] = useState(false)
|
|
142
|
-
|
|
143
|
-
useEffect(() => {
|
|
144
|
-
if (isLoading) {
|
|
145
|
-
setIsAnimating(true)
|
|
146
|
-
Animated.timing(opacity, {
|
|
147
|
-
toValue: 1,
|
|
148
|
-
duration: 200,
|
|
149
|
-
useNativeDriver: true,
|
|
150
|
-
}).start()
|
|
151
|
-
} else {
|
|
152
|
-
Animated.timing(opacity, {
|
|
153
|
-
toValue: 0,
|
|
154
|
-
duration: 200,
|
|
155
|
-
useNativeDriver: true,
|
|
156
|
-
}).start(() => {
|
|
157
|
-
setIsAnimating(false)
|
|
158
|
-
})
|
|
159
|
-
}
|
|
160
|
-
}, [isLoading, opacity])
|
|
161
|
-
|
|
162
|
-
if (!isLoading && !isAnimating) return null
|
|
163
|
-
|
|
164
|
-
return (
|
|
165
|
-
<Animated.View
|
|
166
|
-
style={[
|
|
167
|
-
styles.overlay,
|
|
168
|
-
{
|
|
169
|
-
backgroundColor: bgColor,
|
|
170
|
-
opacity,
|
|
171
|
-
},
|
|
172
|
-
style,
|
|
173
|
-
]}>
|
|
174
|
-
{!text ? (
|
|
175
|
-
<LoadingLogo inFeed={inFeed} size={100} isLoading={isLoading} />
|
|
176
|
-
) : (
|
|
177
|
-
<Loading text={text} />
|
|
178
|
-
)}
|
|
179
|
-
</Animated.View>
|
|
180
|
-
)
|
|
181
|
-
}
|
|
182
|
-
|
|
183
127
|
const styles = StyleSheet.create({
|
|
184
128
|
loadingContainer: {
|
|
185
129
|
flexDirection: 'row',
|
|
@@ -196,15 +140,6 @@ const styles = StyleSheet.create({
|
|
|
196
140
|
borderRadius: 8,
|
|
197
141
|
backgroundColor: 'rgba(0, 0, 0, 0.05)',
|
|
198
142
|
},
|
|
199
|
-
overlay: {
|
|
200
|
-
position: 'absolute',
|
|
201
|
-
top: 0,
|
|
202
|
-
left: 0,
|
|
203
|
-
right: 0,
|
|
204
|
-
bottom: 0,
|
|
205
|
-
justifyContent: 'center',
|
|
206
|
-
alignItems: 'center',
|
|
207
|
-
},
|
|
208
143
|
errorText: {
|
|
209
144
|
color: 'red',
|
|
210
145
|
},
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import React, { useMemo } from 'react'
|
|
2
|
+
import { Animated, StyleProp, StyleSheet, ViewStyle } from 'react-native'
|
|
3
|
+
import { FadeInOptions, useFadeIn } from '../../hooks/useFadeIn'
|
|
4
|
+
import { CircularProgress } from './CircularProgress'
|
|
5
|
+
|
|
6
|
+
const loadingFadeInProps: FadeInOptions = {
|
|
7
|
+
activeOpacity: 0.5,
|
|
8
|
+
duration: 100,
|
|
9
|
+
}
|
|
10
|
+
interface LoadingOverlayProps {
|
|
11
|
+
loading: boolean
|
|
12
|
+
fadeOptions?: FadeInOptions
|
|
13
|
+
style?: StyleProp<ViewStyle>
|
|
14
|
+
}
|
|
15
|
+
export const LoadingOverlay = ({ loading, fadeOptions, style }: LoadingOverlayProps) => {
|
|
16
|
+
const opts = useMemo(() => ({ ...loadingFadeInProps, ...fadeOptions }), [fadeOptions])
|
|
17
|
+
const opacity = useFadeIn(loading, opts)
|
|
18
|
+
|
|
19
|
+
return (
|
|
20
|
+
<Animated.View
|
|
21
|
+
style={[styles.overlay, style, { opacity, pointerEvents: loading ? 'auto' : 'none' }]}>
|
|
22
|
+
<CircularProgress />
|
|
23
|
+
</Animated.View>
|
|
24
|
+
)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const withOverlayLoadingFadeIn: FadeInOptions = {
|
|
28
|
+
enterDelay: 250,
|
|
29
|
+
}
|
|
30
|
+
export const WithLoadingOverlay = ({
|
|
31
|
+
loading,
|
|
32
|
+
children,
|
|
33
|
+
style,
|
|
34
|
+
overlayStyle,
|
|
35
|
+
}: {
|
|
36
|
+
loading: boolean
|
|
37
|
+
children: React.ReactNode
|
|
38
|
+
style?: StyleProp<ViewStyle>
|
|
39
|
+
overlayStyle?: StyleProp<ViewStyle>
|
|
40
|
+
}) => {
|
|
41
|
+
const bodyOpacity = useFadeIn(!loading, withOverlayLoadingFadeIn)
|
|
42
|
+
return (
|
|
43
|
+
<>
|
|
44
|
+
<Animated.View style={[style, { opacity: bodyOpacity }]}>{children}</Animated.View>
|
|
45
|
+
<LoadingOverlay
|
|
46
|
+
fadeOptions={withOverlayLoadingFadeIn}
|
|
47
|
+
loading={loading}
|
|
48
|
+
style={overlayStyle}
|
|
49
|
+
/>
|
|
50
|
+
</>
|
|
51
|
+
)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const styles = StyleSheet.create({
|
|
55
|
+
overlay: {
|
|
56
|
+
position: 'absolute',
|
|
57
|
+
justifyContent: 'center',
|
|
58
|
+
alignItems: 'center',
|
|
59
|
+
left: 0,
|
|
60
|
+
right: 0,
|
|
61
|
+
top: 0,
|
|
62
|
+
bottom: 0,
|
|
63
|
+
},
|
|
64
|
+
})
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { useEffect, useRef } from 'react'
|
|
2
|
+
import { Animated } from 'react-native'
|
|
3
|
+
|
|
4
|
+
export interface FadeInOptions {
|
|
5
|
+
activeOpacity?: number
|
|
6
|
+
inactiveOpacity?: number
|
|
7
|
+
duration?: number
|
|
8
|
+
enterDelay?: number
|
|
9
|
+
exitDelay?: number
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const defaultFadeInOptions: FadeInOptions = {
|
|
13
|
+
activeOpacity: 1,
|
|
14
|
+
inactiveOpacity: 0,
|
|
15
|
+
duration: 250,
|
|
16
|
+
enterDelay: 0,
|
|
17
|
+
exitDelay: 0,
|
|
18
|
+
}
|
|
19
|
+
export const useFadeIn = (active: boolean, opts?: FadeInOptions) => {
|
|
20
|
+
const {
|
|
21
|
+
activeOpacity = 1,
|
|
22
|
+
inactiveOpacity = 0,
|
|
23
|
+
duration = 300,
|
|
24
|
+
enterDelay = 0,
|
|
25
|
+
exitDelay = 0,
|
|
26
|
+
} = opts ?? defaultFadeInOptions
|
|
27
|
+
const opacity = useRef(new Animated.Value(0))
|
|
28
|
+
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
if (active) {
|
|
31
|
+
Animated.timing(opacity.current, {
|
|
32
|
+
toValue: activeOpacity,
|
|
33
|
+
duration,
|
|
34
|
+
useNativeDriver: true,
|
|
35
|
+
delay: enterDelay,
|
|
36
|
+
}).start()
|
|
37
|
+
} else {
|
|
38
|
+
Animated.timing(opacity.current, {
|
|
39
|
+
toValue: inactiveOpacity,
|
|
40
|
+
duration,
|
|
41
|
+
useNativeDriver: true,
|
|
42
|
+
delay: exitDelay,
|
|
43
|
+
}).start()
|
|
44
|
+
}
|
|
45
|
+
}, [active, activeOpacity, inactiveOpacity, duration, enterDelay, exitDelay])
|
|
46
|
+
|
|
47
|
+
return opacity.current
|
|
48
|
+
}
|