@chem-po/react-native 0.0.52 → 0.0.53

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 (98) hide show
  1. package/package.json +5 -20
  2. package/src/components/box/Center.tsx +0 -19
  3. package/src/components/box/CollapseHorizontal.tsx +0 -44
  4. package/src/components/box/ContentBox.tsx +0 -24
  5. package/src/components/box/DropShadow.tsx +0 -28
  6. package/src/components/box/ExpandOnMount.tsx +0 -74
  7. package/src/components/box/Expandable.tsx +0 -143
  8. package/src/components/box/FullSizeContainer.tsx +0 -64
  9. package/src/components/box/index.ts +0 -7
  10. package/src/components/button/ActionButton.tsx +0 -196
  11. package/src/components/button/ButtonText.tsx +0 -60
  12. package/src/components/button/DeleteButton.tsx +0 -288
  13. package/src/components/button/LoadingButton.tsx +0 -41
  14. package/src/components/button/Toggle.tsx +0 -109
  15. package/src/components/button/hooks.ts +0 -66
  16. package/src/components/button/index.ts +0 -5
  17. package/src/components/feed/FeedContentPane.tsx +0 -97
  18. package/src/components/feed/MediaFeed.tsx +0 -199
  19. package/src/components/feed/MediaFeedBackground.tsx +0 -136
  20. package/src/components/feed/MediaFeedRefresh.tsx +0 -113
  21. package/src/components/feed/constants.ts +0 -2
  22. package/src/components/feed/context.tsx +0 -19
  23. package/src/components/feed/hooks.ts +0 -279
  24. package/src/components/feed/index.ts +0 -2
  25. package/src/components/form/Condition.tsx +0 -27
  26. package/src/components/form/Field.tsx +0 -44
  27. package/src/components/form/Form.tsx +0 -452
  28. package/src/components/form/FormFooter.tsx +0 -164
  29. package/src/components/form/UploadProgress/index.tsx +0 -50
  30. package/src/components/form/index.ts +0 -3
  31. package/src/components/form/input/Editable.tsx +0 -206
  32. package/src/components/form/input/InputSlider.tsx +0 -71
  33. package/src/components/form/input/OptionalTag.tsx +0 -43
  34. package/src/components/form/input/StandaloneInput.tsx +0 -49
  35. package/src/components/form/input/boolean/index.tsx +0 -53
  36. package/src/components/form/input/color/index.tsx +0 -145
  37. package/src/components/form/input/common/InputClearButton.tsx +0 -57
  38. package/src/components/form/input/date/index.tsx +0 -125
  39. package/src/components/form/input/datetime/index.tsx +0 -176
  40. package/src/components/form/input/file/index.tsx +0 -310
  41. package/src/components/form/input/hooks/index.ts +0 -2
  42. package/src/components/form/input/hooks/useInputColor.ts +0 -7
  43. package/src/components/form/input/hooks/useInputImperativeHandle.ts +0 -22
  44. package/src/components/form/input/hooks/useInputStyles.ts +0 -114
  45. package/src/components/form/input/index.ts +0 -4
  46. package/src/components/form/input/input.tsx +0 -218
  47. package/src/components/form/input/multipleSelect/index.tsx +0 -221
  48. package/src/components/form/input/number/index.tsx +0 -108
  49. package/src/components/form/input/select/index.tsx +0 -152
  50. package/src/components/form/input/socialMedia/index.tsx +0 -235
  51. package/src/components/form/input/text/AutoResizeTextarea.tsx +0 -41
  52. package/src/components/form/input/text/index.tsx +0 -99
  53. package/src/components/form/input/text/textarea.tsx +0 -32
  54. package/src/components/form/input/text/useWebAutoResize.tsx +0 -73
  55. package/src/components/form/input/time/index.tsx +0 -125
  56. package/src/components/form/types.ts +0 -8
  57. package/src/components/form/view/file.tsx +0 -80
  58. package/src/components/form/view/index.tsx +0 -125
  59. package/src/components/form/view/multipleSelect.tsx +0 -85
  60. package/src/components/form/view/select.tsx +0 -83
  61. package/src/components/form/view/styles.ts +0 -12
  62. package/src/components/icons/index.tsx +0 -28
  63. package/src/components/image/ImageViewModal.tsx +0 -319
  64. package/src/components/image/index.ts +0 -1
  65. package/src/components/index.ts +0 -8
  66. package/src/components/layout/CollapseHorizontal.tsx +0 -92
  67. package/src/components/loading/CircularProgress.tsx +0 -56
  68. package/src/components/loading/Loading.tsx +0 -146
  69. package/src/components/loading/LoadingImage.tsx +0 -163
  70. package/src/components/loading/LoadingOverlay.tsx +0 -74
  71. package/src/components/loading/LoadingSwitch.tsx +0 -110
  72. package/src/components/loading/ProgressBar.tsx +0 -75
  73. package/src/components/loading/index.ts +0 -6
  74. package/src/components/text/AnimatedText.tsx +0 -68
  75. package/src/components/text/Txt.tsx +0 -12
  76. package/src/components/text/index.ts +0 -1
  77. package/src/components/theme/colorMode/DarkModeToggle.tsx +0 -47
  78. package/src/components/theme/colorMode/index.ts +0 -1
  79. package/src/components/theme/index.ts +0 -1
  80. package/src/constants/index.ts +0 -1
  81. package/src/constants/toast.ts +0 -24
  82. package/src/contexts/fonts.tsx +0 -23
  83. package/src/contexts/index.ts +0 -1
  84. package/src/contexts/root.tsx +0 -190
  85. package/src/hooks/index.ts +0 -3
  86. package/src/hooks/useFadeIn.ts +0 -48
  87. package/src/hooks/useFont.ts +0 -25
  88. package/src/hooks/useRefreshFontScale.ts +0 -39
  89. package/src/hooks/useThemeState.ts +0 -43
  90. package/src/index.ts +0 -6
  91. package/src/store/index.ts +0 -2
  92. package/src/store/useFontScale.ts +0 -8
  93. package/src/store/useScreen.ts +0 -25
  94. package/src/styles/fill.ts +0 -19
  95. package/src/types/forms.ts +0 -14
  96. package/src/types/index.ts +0 -1
  97. package/src/utils/downloadFile.ts +0 -61
  98. package/src/utils/downloadFileLegacy.ts +0 -66
@@ -1,60 +0,0 @@
1
- import { ElementSize } from '@chem-po/core'
2
- import React from 'react'
3
- import { StyleProp, StyleSheet, Text, TextStyle } from 'react-native'
4
- import { useButtonColors, useButtonFont, useButtonTextColor } from './hooks'
5
-
6
- export interface ButtonTextProps {
7
- children: string
8
- style?: StyleProp<TextStyle>
9
- variant?: 'outline' | 'solid'
10
- color?: string
11
- disabledColor?: string
12
- disabled?: boolean
13
- size?: ElementSize
14
- }
15
-
16
- export const ButtonText = ({
17
- children,
18
- style,
19
- disabled = false,
20
- size = 'md',
21
- disabledColor,
22
- color: colorProp,
23
- variant = 'solid',
24
- }: ButtonTextProps) => {
25
- const colors = useButtonColors(variant)
26
- const fontStyle = useButtonFont(size)
27
- const textColor = useButtonTextColor(colors, variant, colorProp, disabled, disabledColor)
28
-
29
- return (
30
- <Text
31
- style={[
32
- styles[size],
33
- fontStyle,
34
- variant === 'solid' ? styles.textShadow : {},
35
- { color: textColor },
36
- style,
37
- ]}>
38
- {children}
39
- </Text>
40
- )
41
- }
42
- const styles = StyleSheet.create({
43
- lg: {
44
- fontSize: 18,
45
- },
46
- md: {
47
- fontSize: 16,
48
- },
49
- sm: {
50
- fontSize: 14,
51
- },
52
- xs: {
53
- fontSize: 12,
54
- },
55
- textShadow: {
56
- textShadowColor: 'rgba(0, 0, 0, 0.25)',
57
- textShadowOffset: { width: 1, height: 1 },
58
- textShadowRadius: 3,
59
- },
60
- })
@@ -1,288 +0,0 @@
1
- import { useBackgroundColor, useColorModeValue, useToast } from '@chem-po/react'
2
- import { Ionicons } from '@expo/vector-icons'
3
- import React, { ReactNode, useCallback, useEffect, useRef, useState } from 'react'
4
- import { ActivityIndicator, StyleSheet, View } from 'react-native'
5
- import { Pressable } from 'react-native-gesture-handler'
6
- import { Modal, Portal } from 'react-native-paper'
7
- import { useFontScale } from '../../store/useFontScale'
8
- import { Txt } from '../text/Txt'
9
- import { ActionButton, ActionButtonProps } from './ActionButton'
10
- import { ButtonText } from './ButtonText'
11
-
12
- const defaultAlertBodyText = "Are you sure? You can't undo this action afterwards."
13
-
14
- export const DeleteConfirmAlert = ({
15
- confirmActive,
16
- onCancel,
17
- onConfirm,
18
- body = defaultAlertBodyText,
19
- actionName = 'Delete',
20
- actionLoading,
21
- itemName,
22
- color,
23
- cancelText = 'CANCEL',
24
- }: {
25
- confirmActive: boolean
26
- onCancel: () => void
27
- onConfirm: () => void
28
- body?: string | ReactNode
29
- actionLoading?: boolean
30
- color: string
31
- actionName?: string
32
- cancelText?: string
33
- itemName: string
34
- }) => {
35
- const backgroundColor = useBackgroundColor(100)
36
- const fontScale = useFontScale(s => s.fontScale)
37
- return (
38
- <Portal>
39
- <Modal style={styles.modal} visible={confirmActive} onDismiss={onCancel}>
40
- <View style={[styles.alertContainer, { backgroundColor, maxWidth: 300 * fontScale }]}>
41
- <Txt style={styles.alertTitle}>
42
- {actionName} {itemName}?
43
- </Txt>
44
- {typeof body === 'string' ? <Txt style={styles.alertBody}>{body}</Txt> : body}
45
- <View style={styles.buttonContainer}>
46
- <Pressable style={styles.cancelButton} onPress={onCancel}>
47
- <Txt style={styles.cancelText}>{cancelText}</Txt>
48
- </Pressable>
49
- <Pressable
50
- style={[styles.confirmButton, { backgroundColor: color }]}
51
- onPress={onConfirm}
52
- disabled={actionLoading}>
53
- {actionLoading ? (
54
- <ActivityIndicator size={20 * fontScale} color="#fff" />
55
- ) : (
56
- <Txt style={[styles.buttonText, styles.confirmButtonText]}>
57
- {actionName.toUpperCase()}
58
- </Txt>
59
- )}
60
- </Pressable>
61
- </View>
62
- </View>
63
- </Modal>
64
- </Portal>
65
- )
66
- }
67
-
68
- export interface DeleteButtonProps extends Omit<ActionButtonProps, 'onPress' | 'loading'> {
69
- onDelete: (() => Promise<any>) | (() => void)
70
- itemName: string
71
- actionName?: string
72
- noConfirm?: boolean
73
- text?: string
74
- alertBody?: string | ReactNode
75
- iconSize?: number
76
- iconProps?: React.ComponentProps<typeof Ionicons>
77
- }
78
- export const DeleteButton: React.FC<DeleteButtonProps> = ({
79
- onDelete,
80
- itemName,
81
- noConfirm,
82
- alertBody,
83
- text,
84
- actionName = 'Delete',
85
- style,
86
- color: colorProp,
87
- variant = 'outline',
88
- iconSize = 18,
89
- iconProps,
90
- ...buttonProps
91
- }) => {
92
- const { size, disabledColor, textStyle } = buttonProps
93
- const { showError } = useToast()
94
- const [deleteLoading, setDeleteLoading] = useState(false)
95
- const [confirmActive, setConfirmActive] = useState(false)
96
- const confirmTimer = useRef<ReturnType<typeof setTimeout> | null>(null)
97
- const isMounted = useRef(true)
98
- const defaultColor = useColorModeValue('#dd4444', '#ff4444')
99
- const color = colorProp ?? defaultColor
100
- const fontScale = useFontScale(s => s.fontScale)
101
- useEffect(() => {
102
- isMounted.current = true
103
-
104
- return () => {
105
- isMounted.current = false
106
- }
107
- }, [])
108
-
109
- const handleDelete = useCallback(async () => {
110
- if (confirmTimer.current) clearTimeout(confirmTimer.current)
111
- setConfirmActive(false)
112
- if (onDelete) {
113
- setDeleteLoading(true)
114
- try {
115
- await onDelete()
116
- } catch (err: any) {
117
- console.error(err)
118
- showError(err.message ?? 'An error occurred')
119
- }
120
- if (isMounted.current) {
121
- setDeleteLoading(false)
122
- }
123
- } else {
124
- console.error('No delete function')
125
- }
126
- }, [onDelete, showError])
127
-
128
- return (
129
- <>
130
- <ActionButton
131
- style={[
132
- {
133
- borderColor: color,
134
- backgroundColor: variant === 'solid' ? color : 'transparent',
135
- borderWidth: variant === 'outline' ? 1 : 0,
136
- },
137
- style,
138
- ]}
139
- variant={variant}
140
- onPress={() => {
141
- if (noConfirm) handleDelete()
142
- else setConfirmActive(true)
143
- }}
144
- loading={deleteLoading}
145
- disabled={deleteLoading}
146
- {...buttonProps}>
147
- <View style={styles.contentContainer}>
148
- <Ionicons
149
- name="trash"
150
- size={iconSize * fontScale}
151
- color={variant === 'solid' ? 'white' : color}
152
- {...iconProps}
153
- style={[variant === 'solid' ? styles.shadow : {}, iconProps?.style]}
154
- />
155
- {text ? (
156
- <ButtonText
157
- variant={variant}
158
- color={color}
159
- disabledColor={disabledColor}
160
- size={size}
161
- style={textStyle}>
162
- {text}
163
- </ButtonText>
164
- ) : null}
165
- </View>
166
- </ActionButton>
167
- {noConfirm ? null : (
168
- <DeleteConfirmAlert
169
- confirmActive={confirmActive}
170
- onCancel={() => setConfirmActive(false)}
171
- actionLoading={deleteLoading}
172
- onConfirm={() => {
173
- handleDelete()
174
- }}
175
- actionName={actionName}
176
- body={alertBody}
177
- itemName={itemName}
178
- color={color}
179
- />
180
- )}
181
- </>
182
- )
183
- }
184
-
185
- const styles = StyleSheet.create({
186
- alertContainer: {
187
- backgroundColor: 'white',
188
- borderRadius: 10,
189
- padding: 20,
190
- maxWidth: 300,
191
- alignItems: 'center',
192
- },
193
- modal: {
194
- flex: 1,
195
- justifyContent: 'center',
196
- alignItems: 'center',
197
- },
198
- alertTitle: {
199
- fontSize: 18,
200
- fontWeight: 'bold',
201
- marginBottom: 10,
202
- },
203
- alertBody: {
204
- fontSize: 16,
205
- marginBottom: 20,
206
- textAlign: 'center',
207
- },
208
- buttonContainer: {
209
- flexDirection: 'row',
210
- alignItems: 'center',
211
- justifyContent: 'space-between',
212
- width: '100%',
213
- },
214
- cancelButton: {
215
- padding: 10,
216
- borderColor: 'gray',
217
- borderWidth: 1,
218
- borderRadius: 5,
219
- flex: 1,
220
- marginRight: 5,
221
- alignItems: 'center',
222
- },
223
- cancelText: {
224
- color: 'gray',
225
- fontWeight: 'bold',
226
- },
227
- confirmButton: {
228
- padding: 10,
229
- backgroundColor: 'red',
230
- borderRadius: 5,
231
- flex: 1,
232
- marginLeft: 5,
233
- alignItems: 'center',
234
- },
235
- buttonText: {
236
- fontWeight: 'bold',
237
- },
238
- confirmButtonText: {
239
- color: 'white',
240
- textShadowColor: 'rgba(0, 0, 0, 0.5)',
241
- textShadowOffset: { width: 1, height: 1 },
242
- textShadowRadius: 3,
243
- },
244
- button: {
245
- flexDirection: 'row',
246
- alignItems: 'center',
247
- borderRadius: 4,
248
- },
249
- contentContainer: {
250
- flexDirection: 'row',
251
- alignItems: 'center',
252
- justifyContent: 'center',
253
- gap: 4,
254
- },
255
- loaderContainer: {
256
- ...StyleSheet.absoluteFillObject,
257
- alignItems: 'center',
258
- justifyContent: 'center',
259
- },
260
- shadow: {
261
- textShadowColor: 'rgba(0, 0, 0, 0.3)',
262
- textShadowOffset: { width: 1, height: 1 },
263
- textShadowRadius: 4,
264
- },
265
- iconButton: {
266
- backgroundColor: 'transparent',
267
- borderRadius: 4,
268
- width: 32,
269
- height: 32,
270
- alignItems: 'center',
271
- justifyContent: 'center',
272
- },
273
- iconButtonContent: {
274
- flexDirection: 'row',
275
- alignItems: 'center',
276
- justifyContent: 'center',
277
- gap: 3,
278
- },
279
- loading: {
280
- position: 'absolute',
281
- top: 0,
282
- left: 0,
283
- justifyContent: 'center',
284
- alignItems: 'center',
285
- height: 24,
286
- width: 24,
287
- },
288
- })
@@ -1,41 +0,0 @@
1
- import { useToast } from '@chem-po/react'
2
- import React, { useCallback, useEffect, useRef, useState } from 'react'
3
- import { ActionButton, ActionButtonProps } from './ActionButton'
4
-
5
- export interface LoadingButtonProps<ReturnType = any> extends Omit<
6
- ActionButtonProps,
7
- 'onPress' | 'loading'
8
- > {
9
- onPress: () => Promise<ReturnType>
10
- }
11
-
12
- export const LoadingButton: React.FC<LoadingButtonProps> = ({ onPress, ...props }) => {
13
- const [loading, setLoading] = useState(false)
14
- const { showError } = useToast()
15
-
16
- const isMounted = useRef(true)
17
- useEffect(() => {
18
- isMounted.current = true
19
-
20
- return () => {
21
- isMounted.current = false
22
- }
23
- }, [])
24
-
25
- const handlePress = useCallback(async () => {
26
- if (onPress) {
27
- setLoading(true)
28
- try {
29
- await onPress()
30
- } catch (err: any) {
31
- console.error(err)
32
- showError(err.message ?? 'An error occurred')
33
- }
34
- if (isMounted.current) {
35
- setLoading(false)
36
- }
37
- }
38
- }, [onPress, showError])
39
-
40
- return <ActionButton onPress={() => void handlePress()} loading={loading} {...props} />
41
- }
@@ -1,109 +0,0 @@
1
- import { useBackgroundColor, useBorderColor, useThemeValue, useToast } from '@chem-po/react'
2
- import React, { JSX, useCallback, useMemo } from 'react'
3
- import { StyleProp, StyleSheet, View, ViewStyle } from 'react-native'
4
- import { Pressable } from 'react-native-gesture-handler'
5
-
6
- export interface ToggleOption<Option extends string = string> {
7
- id: Option
8
- disabledMessage?: string
9
- Render: (selected: boolean) => JSX.Element
10
- }
11
-
12
- export interface ToggleProps<Option extends string> {
13
- options: ToggleOption<Option>[]
14
- value: Option
15
- size?: number | [number, number]
16
- onChange: (value: Option) => Promise<void> | void
17
- style?: StyleProp<ViewStyle>
18
- buttonStyle?: StyleProp<ViewStyle>
19
- }
20
-
21
- const ToggleButton = <Option extends string>({
22
- selected,
23
- option: { Render, disabledMessage },
24
- size,
25
- onPress,
26
- style,
27
- }: {
28
- option: ToggleOption<Option>
29
- size: number | [number, number]
30
- selected: boolean
31
- onPress: () => void
32
- style?: StyleProp<ViewStyle>
33
- }) => {
34
- const { showError } = useToast()
35
- const handlePress = useCallback(() => {
36
- if (!disabledMessage) {
37
- onPress()
38
- } else {
39
- showError(disabledMessage)
40
- }
41
- }, [onPress, disabledMessage, showError])
42
- const unselectedBackground = useBackgroundColor(150)
43
- const selectedBackground = useThemeValue('colors.accent.300')
44
- const [width, height] = useMemo(() => (typeof size === 'number' ? [size, size] : size), [size])
45
- const body = (
46
- <View style={[styles.buttonContainer, { width, height, opacity: !disabledMessage ? 1 : 0.6 }]}>
47
- <Pressable
48
- style={[
49
- styles.button,
50
- {
51
- backgroundColor: selected ? selectedBackground : unselectedBackground,
52
- pointerEvents: selected ? 'none' : 'auto',
53
- },
54
- style,
55
- ]}
56
- onPress={handlePress}
57
- disabled={!!disabledMessage}>
58
- {Render(selected)}
59
- </Pressable>
60
- </View>
61
- )
62
-
63
- return body
64
- }
65
-
66
- export const Toggle = <Option extends string>({
67
- value,
68
- onChange,
69
- size = 28,
70
- options,
71
- style,
72
- buttonStyle,
73
- }: ToggleProps<Option>) => {
74
- const borderColor = useBorderColor()
75
- const backgroundColor = useBackgroundColor(150)
76
- return (
77
- <View style={[styles.container, { borderColor, backgroundColor }, style]}>
78
- {options.map(option => (
79
- <ToggleButton<Option>
80
- key={option.id}
81
- onPress={() => {
82
- onChange(option.id)
83
- }}
84
- option={option}
85
- size={size}
86
- selected={option.id === value}
87
- style={buttonStyle}
88
- />
89
- ))}
90
- </View>
91
- )
92
- }
93
-
94
- const styles = StyleSheet.create({
95
- container: {
96
- flexDirection: 'row',
97
- borderWidth: 1,
98
- borderRadius: 3,
99
- },
100
- buttonContainer: {
101
- justifyContent: 'center',
102
- alignItems: 'center',
103
- },
104
- button: {
105
- justifyContent: 'center',
106
- alignItems: 'center',
107
- borderRadius: 3,
108
- },
109
- })
@@ -1,66 +0,0 @@
1
- import { ButtonColors } from '@chem-po/core'
2
- import { useTheme } from '@chem-po/react'
3
- import { useMemo } from 'react'
4
- import { useFont } from '../../hooks/useFont'
5
-
6
- export const useButtonFont = (size: 'lg' | 'md' | 'sm' | 'xs') => {
7
- const fontSize = useMemo(() => (size === 'xs' ? 'sm' : size), [size])
8
- const font = useFont('display', fontSize)
9
- return font
10
- }
11
-
12
- export const useButtonColors = (variant: 'solid' | 'outline') => {
13
- const { buttons } = useTheme()
14
- return useMemo(() => buttons[variant], [buttons, variant])
15
- }
16
-
17
- export const useButtonTextColor = (
18
- colors: ButtonColors,
19
- variant: 'solid' | 'outline',
20
- buttonColor: string | undefined,
21
- disabled: boolean,
22
- disabledColor: string | undefined,
23
- ) => {
24
- return useMemo(() => {
25
- if (disabled) {
26
- if (disabledColor && variant === 'outline') return disabledColor
27
- return colors.disabled.text
28
- }
29
- if (buttonColor && variant === 'outline') return buttonColor
30
- return colors.text
31
- }, [variant, buttonColor, disabledColor, disabled, colors])
32
- }
33
-
34
- export const useButtonBackgroundColor = (
35
- colors: ButtonColors,
36
- variant: 'solid' | 'outline',
37
- buttonColor: string | undefined,
38
- disabled: boolean,
39
- disabledColor: string | undefined,
40
- ) => {
41
- return useMemo(() => {
42
- if (disabled) {
43
- if (disabledColor && variant === 'solid') return disabledColor
44
- return colors.disabled.background
45
- }
46
- if (buttonColor && variant === 'solid') return buttonColor
47
- return colors.background
48
- }, [variant, buttonColor, disabledColor, disabled, colors])
49
- }
50
-
51
- export const useButtonBorderColor = (
52
- colors: ButtonColors,
53
- variant: 'solid' | 'outline',
54
- buttonColor: string | undefined,
55
- disabled: boolean,
56
- disabledColor: string | undefined,
57
- ) => {
58
- return useMemo(() => {
59
- if (disabled) {
60
- if (disabledColor && variant === 'outline') return disabledColor
61
- return colors.disabled.border
62
- }
63
- if (buttonColor && variant === 'outline') return buttonColor
64
- return colors.border
65
- }, [variant, buttonColor, disabledColor, disabled, colors])
66
- }
@@ -1,5 +0,0 @@
1
- export * from './ActionButton'
2
- export * from './ButtonText'
3
- export * from './DeleteButton'
4
- export * from './LoadingButton'
5
- export * from './Toggle'
@@ -1,97 +0,0 @@
1
- import { AnyObject, WithId } from '@chem-po/core'
2
- import { PanelStatus, useDocument, useScreen } from '@chem-po/react'
3
- import React, { JSX, useEffect, useMemo, useRef } from 'react'
4
- // import { motion, MotionValue, useMotionValue, useSpring, useTransform } from 'framer-motion'
5
- import { Animated } from 'react-native'
6
-
7
- const getContentScale = (status: PanelStatus) => {
8
- // if (status === 'current') return 1
9
- if (status === 'current') return 1
10
- return 0
11
- }
12
- // const getContentX = (status: PanelStatus, contentSize: { width: number; height: number }) => {
13
- // const { width: cWidth } = contentSize
14
- // if (status === 'current') return 0
15
- // if (status === 'next') return cWidth
16
- // if (status === 'prev') return -cWidth
17
- // return 0
18
- // }
19
-
20
- const getContentY = (status: PanelStatus, contentSize: { width: number; height: number }) => {
21
- const { height: cHeight } = contentSize
22
- if (status === 'current') return 0
23
- if (status === 'next') return cHeight * 1.1
24
- if (status === 'prev') return -cHeight * 1.1
25
- return 0
26
- }
27
-
28
- interface FeedContentPaneProps<T extends AnyObject = AnyObject> {
29
- id: string
30
- collectionPath: string
31
- RenderItem: (i: WithId<T>) => JSX.Element
32
- onItemLoad: (data: WithId<T> | null) => void
33
- status: PanelStatus
34
- enterStatus?: PanelStatus | null
35
- offsetY: Animated.Value
36
- }
37
-
38
- export const FeedContentPane = <T extends AnyObject = AnyObject>({
39
- id,
40
- collectionPath,
41
- onItemLoad,
42
- RenderItem,
43
- status,
44
- offsetY,
45
- enterStatus,
46
- }: FeedContentPaneProps<T>) => {
47
- const { height, width } = useScreen()
48
- const contentSize = useMemo(() => ({ height, width }), [height, width])
49
- const scale = useRef(new Animated.Value(0)).current
50
- const baseY = useRef(new Animated.Value(getContentY(enterStatus ?? 'next', contentSize))).current
51
- const y = Animated.add(baseY, offsetY)
52
-
53
- const docPath = useMemo(() => `${collectionPath}/${id}`, [collectionPath, id])
54
- const { data: item } = useDocument<T>(docPath, onItemLoad)
55
-
56
- // const init = useRef<{
57
- // status: PanelStatus
58
- // contentSize: Size
59
- // y: number
60
- // scale: number
61
- // }>({
62
- // contentSize,
63
- // status: enterStatus ?? status,
64
- // // x: getContentX(fromStatus || status, contentSize),
65
- // y: getContentY(enterStatus ?? status, contentSize),
66
- // scale: getContentScale(enterStatus ?? status),
67
- // })
68
-
69
- useEffect(() => {
70
- const newScale = getContentScale(status)
71
- const updatedY = getContentY(status, contentSize)
72
- baseY.setValue(updatedY)
73
- scale.setValue(newScale)
74
- // baseY.set(updatedY)
75
- // scale.set(newScale)
76
- }, [status, baseY, scale, contentSize])
77
-
78
- return (
79
- // <AnimatePresence>
80
- <Animated.View
81
- style={{
82
- position: 'absolute',
83
- top: 0,
84
- left: 0,
85
- transform: [{ translateY: y }, { scale }],
86
- display: 'flex',
87
- alignItems: 'center',
88
- justifyContent: 'center',
89
- height: '100%',
90
- opacity: scale,
91
- width: '100%',
92
- }}>
93
- {item ? RenderItem(item) : null}
94
- </Animated.View>
95
- // </AnimatePresence>
96
- )
97
- }