@chem-po/react-native 0.0.30 → 0.0.31

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 (147) hide show
  1. package/lib/commonjs/components/button/DeleteButton.js +7 -8
  2. package/lib/commonjs/components/button/DeleteButton.js.map +1 -1
  3. package/lib/commonjs/components/button/LoadingButton.js +3 -3
  4. package/lib/commonjs/components/button/LoadingButton.js.map +1 -1
  5. package/lib/commonjs/components/button/Toggle.js +2 -1
  6. package/lib/commonjs/components/button/Toggle.js.map +1 -1
  7. package/lib/commonjs/components/form/Form.js +30 -4
  8. package/lib/commonjs/components/form/Form.js.map +1 -1
  9. package/lib/commonjs/components/form/FormFooter.js +3 -2
  10. package/lib/commonjs/components/form/FormFooter.js.map +1 -1
  11. package/lib/commonjs/components/form/input/Editable.js +4 -6
  12. package/lib/commonjs/components/form/input/Editable.js.map +1 -1
  13. package/lib/commonjs/components/form/input/common/InputClearButton.js +2 -1
  14. package/lib/commonjs/components/form/input/common/InputClearButton.js.map +1 -1
  15. package/lib/commonjs/components/form/input/date/index.js +23 -10
  16. package/lib/commonjs/components/form/input/date/index.js.map +1 -1
  17. package/lib/commonjs/components/form/input/datetime/index.js +27 -11
  18. package/lib/commonjs/components/form/input/datetime/index.js.map +1 -1
  19. package/lib/commonjs/components/form/input/file/index.js +27 -27
  20. package/lib/commonjs/components/form/input/file/index.js.map +1 -1
  21. package/lib/commonjs/components/form/input/hooks/useInputStyles.js +5 -6
  22. package/lib/commonjs/components/form/input/hooks/useInputStyles.js.map +1 -1
  23. package/lib/commonjs/components/form/input/input.js +3 -3
  24. package/lib/commonjs/components/form/input/input.js.map +1 -1
  25. package/lib/commonjs/components/form/input/multipleSelect/index.js +35 -23
  26. package/lib/commonjs/components/form/input/multipleSelect/index.js.map +1 -1
  27. package/lib/commonjs/components/form/input/socialMedia/index.js +3 -2
  28. package/lib/commonjs/components/form/input/socialMedia/index.js.map +1 -1
  29. package/lib/commonjs/components/form/input/text/AutoResizeTextarea.js +1 -6
  30. package/lib/commonjs/components/form/input/text/AutoResizeTextarea.js.map +1 -1
  31. package/lib/commonjs/components/form/input/text/index.js +2 -1
  32. package/lib/commonjs/components/form/input/text/index.js.map +1 -1
  33. package/lib/commonjs/components/form/input/text/textarea.js +2 -1
  34. package/lib/commonjs/components/form/input/text/textarea.js.map +1 -1
  35. package/lib/commonjs/components/form/input/text/useWebAutoResize.js +4 -4
  36. package/lib/commonjs/components/form/input/text/useWebAutoResize.js.map +1 -1
  37. package/lib/commonjs/components/form/input/time/index.js +2 -1
  38. package/lib/commonjs/components/form/input/time/index.js.map +1 -1
  39. package/lib/commonjs/components/form/view/select.js +6 -2
  40. package/lib/commonjs/components/form/view/select.js.map +1 -1
  41. package/lib/commonjs/components/image/ImageViewModal.js +18 -15
  42. package/lib/commonjs/components/image/ImageViewModal.js.map +1 -1
  43. package/lib/commonjs/components/layout/CollapseHorizontal.js +23 -11
  44. package/lib/commonjs/components/layout/CollapseHorizontal.js.map +1 -1
  45. package/lib/commonjs/components/loading/LoadingImage.js +20 -13
  46. package/lib/commonjs/components/loading/LoadingImage.js.map +1 -1
  47. package/lib/commonjs/components/theme/colorMode/DarkModeToggle.js +2 -1
  48. package/lib/commonjs/components/theme/colorMode/DarkModeToggle.js.map +1 -1
  49. package/lib/module/components/button/DeleteButton.js +8 -9
  50. package/lib/module/components/button/DeleteButton.js.map +1 -1
  51. package/lib/module/components/button/LoadingButton.js +4 -4
  52. package/lib/module/components/button/LoadingButton.js.map +1 -1
  53. package/lib/module/components/button/Toggle.js +3 -2
  54. package/lib/module/components/button/Toggle.js.map +1 -1
  55. package/lib/module/components/form/Form.js +31 -5
  56. package/lib/module/components/form/Form.js.map +1 -1
  57. package/lib/module/components/form/FormFooter.js +4 -3
  58. package/lib/module/components/form/FormFooter.js.map +1 -1
  59. package/lib/module/components/form/input/Editable.js +5 -7
  60. package/lib/module/components/form/input/Editable.js.map +1 -1
  61. package/lib/module/components/form/input/common/InputClearButton.js +3 -2
  62. package/lib/module/components/form/input/common/InputClearButton.js.map +1 -1
  63. package/lib/module/components/form/input/date/index.js +24 -11
  64. package/lib/module/components/form/input/date/index.js.map +1 -1
  65. package/lib/module/components/form/input/datetime/index.js +29 -13
  66. package/lib/module/components/form/input/datetime/index.js.map +1 -1
  67. package/lib/module/components/form/input/file/index.js +29 -29
  68. package/lib/module/components/form/input/file/index.js.map +1 -1
  69. package/lib/module/components/form/input/hooks/useInputStyles.js +5 -6
  70. package/lib/module/components/form/input/hooks/useInputStyles.js.map +1 -1
  71. package/lib/module/components/form/input/input.js +3 -3
  72. package/lib/module/components/form/input/input.js.map +1 -1
  73. package/lib/module/components/form/input/multipleSelect/index.js +35 -23
  74. package/lib/module/components/form/input/multipleSelect/index.js.map +1 -1
  75. package/lib/module/components/form/input/socialMedia/index.js +4 -3
  76. package/lib/module/components/form/input/socialMedia/index.js.map +1 -1
  77. package/lib/module/components/form/input/text/AutoResizeTextarea.js +1 -6
  78. package/lib/module/components/form/input/text/AutoResizeTextarea.js.map +1 -1
  79. package/lib/module/components/form/input/text/index.js +3 -2
  80. package/lib/module/components/form/input/text/index.js.map +1 -1
  81. package/lib/module/components/form/input/text/textarea.js +2 -1
  82. package/lib/module/components/form/input/text/textarea.js.map +1 -1
  83. package/lib/module/components/form/input/text/useWebAutoResize.js +4 -4
  84. package/lib/module/components/form/input/text/useWebAutoResize.js.map +1 -1
  85. package/lib/module/components/form/input/time/index.js +3 -2
  86. package/lib/module/components/form/input/time/index.js.map +1 -1
  87. package/lib/module/components/form/view/select.js +6 -2
  88. package/lib/module/components/form/view/select.js.map +1 -1
  89. package/lib/module/components/image/ImageViewModal.js +20 -17
  90. package/lib/module/components/image/ImageViewModal.js.map +1 -1
  91. package/lib/module/components/layout/CollapseHorizontal.js +24 -12
  92. package/lib/module/components/layout/CollapseHorizontal.js.map +1 -1
  93. package/lib/module/components/loading/LoadingImage.js +21 -14
  94. package/lib/module/components/loading/LoadingImage.js.map +1 -1
  95. package/lib/module/components/theme/colorMode/DarkModeToggle.js +3 -2
  96. package/lib/module/components/theme/colorMode/DarkModeToggle.js.map +1 -1
  97. package/lib/typescript/components/button/DeleteButton.d.ts.map +1 -1
  98. package/lib/typescript/components/button/LoadingButton.d.ts.map +1 -1
  99. package/lib/typescript/components/button/Toggle.d.ts.map +1 -1
  100. package/lib/typescript/components/form/Form.d.ts.map +1 -1
  101. package/lib/typescript/components/form/FormFooter.d.ts.map +1 -1
  102. package/lib/typescript/components/form/input/Editable.d.ts.map +1 -1
  103. package/lib/typescript/components/form/input/common/InputClearButton.d.ts.map +1 -1
  104. package/lib/typescript/components/form/input/date/index.d.ts.map +1 -1
  105. package/lib/typescript/components/form/input/datetime/index.d.ts.map +1 -1
  106. package/lib/typescript/components/form/input/file/index.d.ts +2 -1
  107. package/lib/typescript/components/form/input/file/index.d.ts.map +1 -1
  108. package/lib/typescript/components/form/input/hooks/useInputStyles.d.ts +3 -6
  109. package/lib/typescript/components/form/input/hooks/useInputStyles.d.ts.map +1 -1
  110. package/lib/typescript/components/form/input/multipleSelect/index.d.ts.map +1 -1
  111. package/lib/typescript/components/form/input/socialMedia/index.d.ts.map +1 -1
  112. package/lib/typescript/components/form/input/text/AutoResizeTextarea.d.ts.map +1 -1
  113. package/lib/typescript/components/form/input/text/index.d.ts.map +1 -1
  114. package/lib/typescript/components/form/input/text/useWebAutoResize.d.ts +2 -3
  115. package/lib/typescript/components/form/input/text/useWebAutoResize.d.ts.map +1 -1
  116. package/lib/typescript/components/form/input/time/index.d.ts.map +1 -1
  117. package/lib/typescript/components/form/view/select.d.ts.map +1 -1
  118. package/lib/typescript/components/image/ImageViewModal.d.ts.map +1 -1
  119. package/lib/typescript/components/layout/CollapseHorizontal.d.ts.map +1 -1
  120. package/lib/typescript/components/loading/LoadingImage.d.ts +4 -1
  121. package/lib/typescript/components/loading/LoadingImage.d.ts.map +1 -1
  122. package/lib/typescript/components/theme/colorMode/DarkModeToggle.d.ts.map +1 -1
  123. package/package.json +4 -4
  124. package/src/components/button/DeleteButton.tsx +12 -25
  125. package/src/components/button/LoadingButton.tsx +4 -5
  126. package/src/components/button/Toggle.tsx +4 -3
  127. package/src/components/form/Form.tsx +31 -11
  128. package/src/components/form/FormFooter.tsx +6 -5
  129. package/src/components/form/input/Editable.tsx +8 -9
  130. package/src/components/form/input/common/InputClearButton.tsx +4 -3
  131. package/src/components/form/input/date/index.tsx +24 -11
  132. package/src/components/form/input/datetime/index.tsx +33 -16
  133. package/src/components/form/input/file/index.tsx +34 -35
  134. package/src/components/form/input/hooks/useInputStyles.ts +10 -7
  135. package/src/components/form/input/input.tsx +2 -2
  136. package/src/components/form/input/multipleSelect/index.tsx +35 -35
  137. package/src/components/form/input/socialMedia/index.tsx +6 -5
  138. package/src/components/form/input/text/AutoResizeTextarea.tsx +1 -5
  139. package/src/components/form/input/text/index.tsx +4 -3
  140. package/src/components/form/input/text/textarea.tsx +1 -1
  141. package/src/components/form/input/text/useWebAutoResize.tsx +6 -4
  142. package/src/components/form/input/time/index.tsx +4 -3
  143. package/src/components/form/view/select.tsx +5 -1
  144. package/src/components/image/ImageViewModal.tsx +56 -50
  145. package/src/components/layout/CollapseHorizontal.tsx +20 -10
  146. package/src/components/loading/LoadingImage.tsx +19 -19
  147. package/src/components/theme/colorMode/DarkModeToggle.tsx +4 -3
@@ -1,8 +1,13 @@
1
1
  import { useScreen, useToast } from '@chem-po/react'
2
2
  import { Ionicons } from '@expo/vector-icons'
3
3
  import React, { useCallback, useEffect, useMemo, useState } from 'react'
4
- import { Image, Modal, StyleSheet, TouchableOpacity, View } from 'react-native'
5
- import { Gesture, GestureDetector, GestureHandlerRootView } from 'react-native-gesture-handler'
4
+ import { Image, Modal, SafeAreaView, StyleSheet, View } from 'react-native'
5
+ import {
6
+ Gesture,
7
+ GestureDetector,
8
+ GestureHandlerRootView,
9
+ Pressable,
10
+ } from 'react-native-gesture-handler'
6
11
  import Animated, { useAnimatedStyle, useSharedValue, withSpring } from 'react-native-reanimated'
7
12
  import { downloadFile } from '../../utils/downloadFile'
8
13
  import { LoadingLogo } from '../loading/Loading'
@@ -53,11 +58,13 @@ export const ImageViewModal: React.FC<ImageViewModalProps> = ({
53
58
  }, [screenHeight, screenWidth, imageSize, loading])
54
59
 
55
60
  const onLoadStart = useCallback(() => setLoading(true), [])
56
- const onLoad = useCallback((e: any) => {
57
- const { width: naturalWidth, height: naturalHeight } = e.nativeEvent.source
58
- setImageSize({ width: naturalWidth, height: naturalHeight })
59
- setLoading(false)
60
- }, [])
61
+ const onLoad = useCallback(() => {
62
+ if (!src) return
63
+ Image.getSize(src, (width, height) => {
64
+ setImageSize({ width, height })
65
+ setLoading(false)
66
+ })
67
+ }, [src])
61
68
 
62
69
  // Reset zoom and pan when modal opens/closes
63
70
  const resetTransform = useCallback(() => {
@@ -203,53 +210,51 @@ export const ImageViewModal: React.FC<ImageViewModalProps> = ({
203
210
 
204
211
  return (
205
212
  <Modal visible={isOpen} transparent animationType="fade" onRequestClose={onClose}>
206
- <GestureHandlerRootView style={styles.gestureRoot}>
207
- <View style={styles.modalOverlay}>
208
- <TouchableOpacity
209
- style={styles.backgroundTouchable}
210
- activeOpacity={1}
211
- onPress={onClose}
212
- />
213
- <View style={styles.contentContainer}>
214
- <GestureDetector gesture={combinedGestures}>
215
- <Animated.View
216
- style={[
217
- styles.imageContainer,
218
- {
219
- width,
220
- height,
221
- opacity: loading ? 0 : 1,
222
- },
223
- animatedStyle,
224
- ]}>
225
- <Image
226
- source={src ? { uri: src } : undefined}
227
- style={styles.image}
228
- onLoadStart={onLoadStart}
229
- onLoad={onLoad}
230
- resizeMode="contain"
231
- />
232
- </Animated.View>
233
- </GestureDetector>
213
+ <SafeAreaView style={{ flex: 1 }}>
214
+ <GestureHandlerRootView style={styles.gestureRoot}>
215
+ <View style={styles.modalOverlay}>
216
+ <Pressable style={styles.backgroundTouchable} onPress={onClose} />
217
+ <View style={styles.contentContainer}>
218
+ <GestureDetector gesture={combinedGestures}>
219
+ <Animated.View
220
+ style={[
221
+ styles.imageContainer,
222
+ {
223
+ width,
224
+ height,
225
+ opacity: loading ? 0 : 1,
226
+ },
227
+ animatedStyle,
228
+ ]}>
229
+ <Image
230
+ source={src ? { uri: src } : undefined}
231
+ style={styles.image}
232
+ onLoadStart={onLoadStart}
233
+ onLoad={onLoad}
234
+ resizeMode="contain"
235
+ />
236
+ </Animated.View>
237
+ </GestureDetector>
234
238
 
235
- {withDownload && (
236
- <TouchableOpacity style={styles.downloadButton} onPress={() => void handleDownload()}>
237
- <Ionicons name="download" size={24} color="white" />
238
- </TouchableOpacity>
239
- )}
239
+ {withDownload && (
240
+ <Pressable style={styles.downloadButton} onPress={() => void handleDownload()}>
241
+ <Ionicons name="download" size={24} color="white" />
242
+ </Pressable>
243
+ )}
240
244
 
241
- <TouchableOpacity style={styles.closeButton} onPress={onClose}>
242
- <Ionicons name="close" size={24} color="white" />
243
- </TouchableOpacity>
245
+ <Pressable style={styles.closeButton} onPress={onClose}>
246
+ <Ionicons name="close" size={24} color="white" />
247
+ </Pressable>
244
248
 
245
- {loading || !src ? (
246
- <View style={styles.loadingContainer}>
247
- <LoadingLogo isLoading={loading} size={70} />
248
- </View>
249
- ) : null}
249
+ {loading || !src ? (
250
+ <View style={styles.loadingContainer}>
251
+ <LoadingLogo isLoading={loading} size={70} />
252
+ </View>
253
+ ) : null}
254
+ </View>
250
255
  </View>
251
- </View>
252
- </GestureHandlerRootView>
256
+ </GestureHandlerRootView>
257
+ </SafeAreaView>
253
258
  </Modal>
254
259
  )
255
260
  }
@@ -303,6 +308,7 @@ const styles = StyleSheet.create({
303
308
  },
304
309
  loadingContainer: {
305
310
  ...StyleSheet.absoluteFillObject,
311
+ pointerEvents: 'none',
306
312
  justifyContent: 'center',
307
313
  alignItems: 'center',
308
314
  },
@@ -1,4 +1,4 @@
1
- import React, { useCallback } from 'react'
1
+ import React, { useCallback, useLayoutEffect, useRef, useState } from 'react'
2
2
  import { LayoutChangeEvent, StyleProp, View, ViewStyle } from 'react-native'
3
3
  import Animated, {
4
4
  useAnimatedStyle,
@@ -18,26 +18,34 @@ export const CollapseHorizontal = ({
18
18
  duration?: number
19
19
  style?: StyleProp<ViewStyle>
20
20
  }) => {
21
- const contentWidth = useSharedValue(0)
21
+ const contentRef = useRef<View>(null)
22
+ const [contentWidth, setContentWidth] = useState(0)
22
23
  const width = useSharedValue(0)
23
24
  const opacity = useSharedValue(0)
24
-
25
25
  const handleLayout = useCallback(
26
26
  (event: LayoutChangeEvent) => {
27
- contentWidth.value = event.nativeEvent.layout.width
27
+ setContentWidth(event.nativeEvent.layout.width)
28
28
  // Initialize width if component is initially visible
29
29
  if (isIn && width.value === 0) {
30
- width.value = contentWidth.value
30
+ width.value = event.nativeEvent.layout.width
31
31
  opacity.value = 1
32
32
  }
33
33
  },
34
- [isIn, contentWidth, width, opacity],
34
+ [isIn, width, opacity],
35
35
  )
36
36
 
37
+ useLayoutEffect(() => {
38
+ if (contentRef.current) {
39
+ contentRef.current.measure((_x, _y, width) => {
40
+ setContentWidth(width)
41
+ })
42
+ }
43
+ }, [])
44
+
37
45
  React.useEffect(() => {
38
46
  if (isIn) {
39
47
  // Fade in: width first, then opacity
40
- width.value = withTiming(contentWidth.value, {
48
+ width.value = withTiming(contentWidth, {
41
49
  duration,
42
50
  })
43
51
  opacity.value = withSequence(
@@ -58,7 +66,7 @@ export const CollapseHorizontal = ({
58
66
  }),
59
67
  )
60
68
  }
61
- }, [isIn, contentWidth.value, duration, width, opacity])
69
+ }, [isIn, contentWidth, duration, width, opacity])
62
70
 
63
71
  const animatedStyle = useAnimatedStyle(() => ({
64
72
  width: width.value,
@@ -74,8 +82,10 @@ export const CollapseHorizontal = ({
74
82
  },
75
83
  animatedStyle,
76
84
  ]}>
77
- <View style={[{ position: 'absolute' }, style]} onLayout={handleLayout}>
78
- {children}
85
+ <View style={{ position: 'absolute', width: 'auto' }}>
86
+ <View style={style} onLayout={handleLayout} ref={contentRef}>
87
+ {children}
88
+ </View>
79
89
  </View>
80
90
  </Animated.View>
81
91
  )
@@ -1,14 +1,15 @@
1
1
  import { useMounted } from '@chem-po/react'
2
2
  import { Ionicons } from '@expo/vector-icons'
3
3
  import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'
4
- import { DimensionValue, Image, StyleSheet, TouchableOpacity, View, ViewStyle } from 'react-native'
4
+ import { DimensionValue, Image, StyleSheet, View, ViewStyle } from 'react-native'
5
+ import { Pressable } from 'react-native-gesture-handler'
5
6
  import { ImageViewModal } from '../image/ImageViewModal'
6
7
  import { LoadingLogo } from './Loading'
7
8
 
8
9
  export interface LoadingImageProps {
9
10
  src?: string | null
10
11
  loadingOverride?: boolean
11
- onLoad?: (e: any) => void
12
+ onLoad?: (dims: { width: number; height: number }) => void
12
13
  filename?: string
13
14
  fileType?: string
14
15
  withFullView?: boolean
@@ -41,12 +42,13 @@ export const LoadingImage = ({
41
42
  const [viewing, setViewing] = useState(false)
42
43
  const mounted = useMounted(100)
43
44
 
44
- const handleImageLoad = useCallback(
45
- (e: any) => {
46
- if (onLoad) onLoad(e)
47
- },
48
- [onLoad],
49
- )
45
+ const handleImageLoad = useCallback(() => {
46
+ if (onLoad && src) {
47
+ Image.getSize(src, (width, height) => {
48
+ onLoad({ width, height })
49
+ })
50
+ }
51
+ }, [onLoad, src])
50
52
 
51
53
  const [prevSrc, setPrevSrc] = useState(src)
52
54
  useEffect(() => {
@@ -65,7 +67,6 @@ export const LoadingImage = ({
65
67
  opacity: src && !loading ? 1 : 0,
66
68
  },
67
69
  ]}
68
- // onLoadStart={() => setImageLoading(true)}
69
70
  onLoadEnd={() => setImageLoading(false)}
70
71
  onLoad={handleImageLoad}
71
72
  resizeMode={src ? 'cover' : 'contain'}
@@ -86,23 +87,22 @@ export const LoadingImage = ({
86
87
  {!withFullView || buttonFullView ? (
87
88
  ImageComponent
88
89
  ) : (
89
- <TouchableOpacity
90
- activeOpacity={0.9}
90
+ <Pressable
91
91
  onPress={() => setViewing(true)}
92
92
  style={{
93
- width: width ? undefined : '100%',
94
- height: height ? undefined : '100%',
93
+ position: 'absolute',
94
+ top: 0,
95
+ left: 0,
96
+ right: 0,
97
+ bottom: 0,
95
98
  }}>
96
99
  {ImageComponent}
97
- </TouchableOpacity>
100
+ </Pressable>
98
101
  )}
99
102
  {buttonFullView && (
100
- <TouchableOpacity
101
- style={styles.fullViewButton}
102
- onPress={() => setViewing(true)}
103
- activeOpacity={0.7}>
103
+ <Pressable style={styles.fullViewButton} onPress={() => setViewing(true)}>
104
104
  <Ionicons name="expand" size={20} color="white" style={styles.fullViewIcon} />
105
- </TouchableOpacity>
105
+ </Pressable>
106
106
  )}
107
107
  <View
108
108
  style={[
@@ -1,7 +1,8 @@
1
1
  import { useBackgroundColor, useIconColor, useTheme } from '@chem-po/react'
2
2
  import { Ionicons } from '@expo/vector-icons'
3
3
  import React from 'react'
4
- import { StyleSheet, TouchableOpacity, View } from 'react-native'
4
+ import { StyleSheet, View } from 'react-native'
5
+ import { Pressable } from 'react-native-gesture-handler'
5
6
 
6
7
  export const DarkModeToggle = () => {
7
8
  const { colorMode, toggleColorMode } = useTheme()
@@ -11,7 +12,7 @@ export const DarkModeToggle = () => {
11
12
  const iconName = isDark ? 'moon' : 'sunny'
12
13
  const bg = useBackgroundColor(100)
13
14
  return (
14
- <TouchableOpacity
15
+ <Pressable
15
16
  onPress={toggleColorMode}
16
17
  style={[
17
18
  styles.button,
@@ -20,7 +21,7 @@ export const DarkModeToggle = () => {
20
21
  },
21
22
  ]}>
22
23
  <Ionicons name={iconName} size={16} color={iconColor} />
23
- </TouchableOpacity>
24
+ </Pressable>
24
25
  )
25
26
  }
26
27