react-native-gifted-chat 2.8.2-alpha.4 → 2.9.0-alpha.0

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 (62) hide show
  1. package/CHANGELOG_2.8.1_to_2.8.2-alpha.5.md +374 -0
  2. package/README.md +26 -26
  3. package/package.json +2 -1
  4. package/src/Actions.tsx +1 -1
  5. package/src/Bubble/index.tsx +12 -14
  6. package/src/Bubble/styles.ts +1 -1
  7. package/src/Bubble/types.ts +4 -5
  8. package/src/Color.ts +1 -1
  9. package/src/Composer.tsx +1 -1
  10. package/src/Day/styles.ts +1 -1
  11. package/src/GiftedAvatar.tsx +1 -1
  12. package/src/GiftedChat/index.tsx +12 -49
  13. package/src/GiftedChat/types.ts +2 -2
  14. package/src/InputToolbar.tsx +22 -13
  15. package/src/LoadEarlierMessages.tsx +48 -51
  16. package/src/Message/index.tsx +6 -8
  17. package/src/MessageAudio.tsx +1 -1
  18. package/src/MessageContainer/components/DayAnimated/index.tsx +2 -3
  19. package/src/MessageContainer/components/Item/index.tsx +8 -10
  20. package/src/MessageContainer/index.tsx +9 -11
  21. package/src/MessageContainer/styles.ts +1 -1
  22. package/src/MessageText.tsx +2 -1
  23. package/src/MessageVideo.tsx +1 -1
  24. package/src/QuickReplies.tsx +1 -1
  25. package/src/Send.tsx +1 -1
  26. package/src/SystemMessage.tsx +30 -24
  27. package/src/Time.tsx +5 -5
  28. package/src/TypingIndicator/index.tsx +1 -3
  29. package/src/TypingIndicator/styles.ts +1 -1
  30. package/src/__tests__/Actions.test.tsx +1 -1
  31. package/src/__tests__/Avatar.test.tsx +7 -2
  32. package/src/__tests__/Bubble.test.tsx +3 -7
  33. package/src/__tests__/Color.test.tsx +1 -1
  34. package/src/__tests__/Composer.test.tsx +1 -1
  35. package/src/__tests__/Day.test.tsx +3 -3
  36. package/src/__tests__/DayAnimated.test.tsx +5 -11
  37. package/src/__tests__/GiftedAvatar.test.tsx +1 -1
  38. package/src/__tests__/GiftedChat.test.tsx +1 -1
  39. package/src/__tests__/InputToolbar.test.tsx +1 -1
  40. package/src/__tests__/LoadEarlier.test.tsx +2 -2
  41. package/src/__tests__/Message.test.tsx +5 -11
  42. package/src/__tests__/MessageContainer.test.tsx +4 -4
  43. package/src/__tests__/MessageImage.test.tsx +2 -2
  44. package/src/__tests__/MessageText.test.tsx +3 -2
  45. package/src/__tests__/Send.test.tsx +1 -1
  46. package/src/__tests__/SystemMessage.test.tsx +1 -1
  47. package/src/__tests__/Time.test.tsx +1 -1
  48. package/src/__tests__/__snapshots__/Actions.test.tsx.snap +61 -57
  49. package/src/__tests__/__snapshots__/Bubble.test.tsx.snap +1 -2
  50. package/src/__tests__/__snapshots__/Day.test.tsx.snap +96 -2
  51. package/src/__tests__/__snapshots__/GiftedChat.test.tsx.snap +56 -36
  52. package/src/__tests__/__snapshots__/InputToolbar.test.tsx.snap +1 -1
  53. package/src/__tests__/__snapshots__/LoadEarlier.test.tsx.snap +64 -52
  54. package/src/__tests__/__snapshots__/Message.test.tsx.snap +41 -5
  55. package/src/__tests__/__snapshots__/MessageText.test.tsx.snap +1 -2
  56. package/src/__tests__/__snapshots__/Send.test.tsx.snap +120 -108
  57. package/src/__tests__/__snapshots__/SystemMessage.test.tsx.snap +38 -8
  58. package/src/__tests__/data.ts +1 -1
  59. package/src/components/TouchableOpacity.tsx +26 -15
  60. package/src/index.ts +19 -1
  61. package/src/utils.ts +22 -1
  62. package/src/LoadEarlier.tsx +0 -95
@@ -15,6 +15,7 @@ exports[`SystemMessage should render <SystemMessage /> and compare with snapshot
15
15
  },
16
16
  {
17
17
  "marginBottom": 10,
18
+ "marginHorizontal": 20,
18
19
  "marginTop": 5,
19
20
  },
20
21
  undefined,
@@ -22,21 +23,50 @@ exports[`SystemMessage should render <SystemMessage /> and compare with snapshot
22
23
  }
23
24
  >
24
25
  <View>
25
- <Text
26
+ <View
26
27
  style={
27
28
  [
28
29
  {
29
- "backgroundColor": "transparent",
30
- "color": "#b2b2b2",
31
- "fontSize": 12,
32
- "fontWeight": "300",
30
+ "marginBottom": 5,
31
+ "marginLeft": 10,
32
+ "marginRight": 10,
33
+ "marginTop": 5,
34
+ },
35
+ {
36
+ "backgroundColor": "rgba(0,0,0,0.05)",
37
+ "borderColor": "rgba(0,0,0,0.1)",
38
+ "borderRadius": 20,
39
+ "borderWidth": 1,
40
+ "paddingHorizontal": 10,
41
+ "paddingVertical": 10,
33
42
  },
34
- undefined,
35
43
  ]
36
44
  }
37
45
  >
38
- test
39
- </Text>
46
+ <Text
47
+ style={
48
+ [
49
+ {
50
+ "color": "black",
51
+ },
52
+ undefined,
53
+ [
54
+ {
55
+ "backgroundColor": "transparent",
56
+ "fontSize": 12,
57
+ "fontStyle": "italic",
58
+ "fontWeight": "300",
59
+ },
60
+ undefined,
61
+ ],
62
+ ]
63
+ }
64
+ >
65
+ <Text>
66
+ test
67
+ </Text>
68
+ </Text>
69
+ </View>
40
70
  </View>
41
71
  </View>
42
72
  `;
@@ -4,5 +4,5 @@ export const DEFAULT_TEST_MESSAGE: IMessage = {
4
4
  _id: 'test',
5
5
  text: 'test',
6
6
  user: { _id: 'test' },
7
- createdAt: new Date(2022, 3, 17),
7
+ createdAt: new Date(2022, 3, 17).getTime(),
8
8
  }
@@ -6,40 +6,51 @@ import Animated, {
6
6
  withTiming,
7
7
  } from 'react-native-reanimated'
8
8
 
9
- const AnimatedPressable = Animated.createAnimatedComponent(Pressable)
10
-
11
- export interface TouchableOpacityProps extends React.ComponentProps<typeof AnimatedPressable> {
9
+ export type TouchableOpacityProps = React.ComponentProps<typeof Pressable> & {
12
10
  activeOpacity?: number
13
- }
11
+ } & React.ComponentProps<typeof Animated.View>
14
12
 
15
- export function TouchableOpacity({
13
+ export const TouchableOpacity: React.FC<TouchableOpacityProps> = ({
16
14
  children,
17
15
  style,
18
16
  activeOpacity = 0.2,
17
+ onPress,
19
18
  ...rest
20
- }: TouchableOpacityProps) {
19
+ }) => {
21
20
  const opacity = useSharedValue(1)
21
+ const isAnimationInFinished = useSharedValue(false)
22
22
 
23
23
  const handlePressIn = useCallback(() => {
24
- opacity.value = withTiming(activeOpacity, { duration: 150 })
25
- }, [activeOpacity, opacity])
24
+ opacity.value = withTiming(activeOpacity, { duration: 150 }, () => {
25
+ isAnimationInFinished.value = true
26
+ })
27
+ }, [activeOpacity, opacity, isAnimationInFinished])
26
28
 
27
29
  const handlePressOut = useCallback(() => {
28
- opacity.value = withTiming(1, { duration: 150 })
29
- }, [opacity])
30
+ setTimeout(() => {
31
+ 'worklet'
32
+
33
+ opacity.value = withTiming(1, { duration: 150 })
34
+ isAnimationInFinished.value = false
35
+ }, isAnimationInFinished.value ? 0 : 150)
36
+ }, [opacity, isAnimationInFinished])
30
37
 
31
38
  const animatedStyle = useAnimatedStyle(() => ({
32
39
  opacity: opacity.value,
33
40
  }))
34
41
 
35
42
  return (
36
- <AnimatedPressable
37
- {...rest}
43
+ <Pressable
38
44
  onPressIn={handlePressIn}
39
45
  onPressOut={handlePressOut}
40
- style={[style, animatedStyle]}
46
+ onPress={onPress}
41
47
  >
42
- {children}
43
- </AnimatedPressable>
48
+ <Animated.View
49
+ {...rest}
50
+ style={[style, animatedStyle]}
51
+ >
52
+ {children}
53
+ </Animated.View>
54
+ </Pressable>
44
55
  )
45
56
  }
package/src/index.ts CHANGED
@@ -1,4 +1,22 @@
1
1
  export * from './GiftedChat'
2
2
  export * from './Constant'
3
- export * from './utils'
3
+ export * as utils from './utils'
4
4
  export * from './GiftedChatContext'
5
+ export * from './types'
6
+ export { Actions } from './Actions'
7
+ export { Avatar } from './Avatar'
8
+ export { Bubble } from './Bubble'
9
+ export { SystemMessage } from './SystemMessage'
10
+ export { MessageImage } from './MessageImage'
11
+ export { MessageText } from './MessageText'
12
+ export { Composer } from './Composer'
13
+ export { Day } from './Day'
14
+ export { InputToolbar } from './InputToolbar'
15
+ export { LoadEarlierMessages } from './LoadEarlierMessages'
16
+ export { Message } from './Message'
17
+ export { MessageContainer } from './MessageContainer'
18
+ export { Send } from './Send'
19
+ export { Time } from './Time'
20
+ export { GiftedAvatar } from './GiftedAvatar'
21
+ export { MessageAudio } from './MessageAudio'
22
+ export { MessageVideo } from './MessageVideo'
package/src/utils.ts CHANGED
@@ -1,7 +1,28 @@
1
- import { useCallback, useEffect, useRef } from 'react'
1
+ import React, { useCallback, useEffect, useRef } from 'react'
2
2
  import dayjs from 'dayjs'
3
3
  import { IMessage } from './types'
4
4
 
5
+ export function renderComponentOrElement<TProps extends Record<string, any>>(
6
+ component: React.ComponentType<TProps> | React.ReactElement | ((props: TProps) => React.ReactNode) | null | undefined,
7
+ props: TProps
8
+ ): React.ReactNode {
9
+ if (!component)
10
+ return null
11
+
12
+ if (React.isValidElement(component))
13
+ // If it's already a React element, clone it with props
14
+ return React.cloneElement(component, props as any)
15
+
16
+ if (typeof component === 'function') {
17
+ // If it's a component or render function
18
+ const Component = component as React.ComponentType<TProps>
19
+ return React.createElement(Component, props as any)
20
+ }
21
+
22
+ // If it's neither, return it as-is
23
+ return component
24
+ }
25
+
5
26
  export function isSameDay (
6
27
  currentMessage: IMessage,
7
28
  diffMessage: IMessage | null | undefined
@@ -1,95 +0,0 @@
1
- import React, { useMemo } from 'react'
2
- import {
3
- ActivityIndicator,
4
- Platform,
5
- StyleSheet,
6
- Text,
7
- View,
8
- StyleProp,
9
- ViewStyle,
10
- TextStyle,
11
- } from 'react-native'
12
- import Color from './Color'
13
- import { TouchableOpacity } from './components/TouchableOpacity'
14
- import stylesCommon from './styles'
15
-
16
- const styles = StyleSheet.create({
17
- container: {
18
- alignItems: 'center',
19
- marginTop: 5,
20
- marginBottom: 10,
21
- },
22
- wrapper: {
23
- backgroundColor: Color.defaultColor,
24
- borderRadius: 15,
25
- height: 30,
26
- paddingLeft: 10,
27
- paddingRight: 10,
28
- },
29
- text: {
30
- backgroundColor: Color.backgroundTransparent,
31
- color: Color.white,
32
- fontSize: 12,
33
- },
34
- activityIndicator: {
35
- marginTop: Platform.select({
36
- ios: -14,
37
- android: -16,
38
- default: -15,
39
- }),
40
- },
41
- })
42
-
43
- export interface LoadEarlierMessagesProps {
44
- isLoadingEarlier?: boolean
45
- label?: string
46
- containerStyle?: StyleProp<ViewStyle>
47
- wrapperStyle?: StyleProp<ViewStyle>
48
- textStyle?: StyleProp<TextStyle>
49
- activityIndicatorStyle?: StyleProp<ViewStyle>
50
- activityIndicatorColor?: string
51
- activityIndicatorSize?: number | 'small' | 'large'
52
- onPress: () => void
53
- }
54
-
55
- export const LoadEarlierMessages: React.FC<LoadEarlierMessagesProps> = ({
56
- isLoadingEarlier = false,
57
- onPress,
58
- label = 'Load earlier messages',
59
- containerStyle,
60
- wrapperStyle,
61
- textStyle,
62
- activityIndicatorColor = 'white',
63
- activityIndicatorSize = 'small',
64
- activityIndicatorStyle,
65
- }) => {
66
- const loadingContent = useMemo(() => (
67
- <View>
68
- <Text style={[styles.text, textStyle, { opacity: 0 }]}>
69
- {label}
70
- </Text>
71
- <ActivityIndicator
72
- color={activityIndicatorColor!}
73
- size={activityIndicatorSize!}
74
- style={[styles.activityIndicator, activityIndicatorStyle]}
75
- />
76
- </View>
77
- ), [label, textStyle, activityIndicatorColor, activityIndicatorSize, activityIndicatorStyle])
78
-
79
- const labelContent = useMemo(() => (
80
- <Text style={[styles.text, textStyle]}>{label}</Text>
81
- ), [label, textStyle])
82
-
83
- return (
84
- <TouchableOpacity
85
- style={[styles.container, containerStyle]}
86
- onPress={onPress}
87
- disabled={isLoadingEarlier}
88
- accessibilityRole='button'
89
- >
90
- <View style={[stylesCommon.centerItems, styles.wrapper, wrapperStyle]}>
91
- {isLoadingEarlier ? loadingContent : labelContent}
92
- </View>
93
- </TouchableOpacity>
94
- )
95
- }