react-native-gifted-chat 3.0.0 → 3.0.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-gifted-chat",
3
- "version": "3.0.0",
3
+ "version": "3.0.1",
4
4
  "description": "The most complete chat UI for React Native",
5
5
  "keywords": [
6
6
  "android",
package/src/Composer.tsx CHANGED
@@ -1,7 +1,10 @@
1
- import React from 'react'
1
+ import React, { useCallback, useMemo, useState } from 'react'
2
2
  import {
3
+ Platform,
3
4
  StyleSheet,
4
5
  TextInput,
6
+ TextInputChangeEvent,
7
+ TextInputContentSizeChangeEvent,
5
8
  TextInputProps,
6
9
  useColorScheme,
7
10
  View,
@@ -24,6 +27,37 @@ export function Composer ({
24
27
 
25
28
  const placeholder = textInputProps?.placeholder ?? 'Type a message...'
26
29
 
30
+ const minHeight = useMemo(() =>
31
+ Platform.select({
32
+ web: styles.textInput.lineHeight + styles.textInput.paddingTop + styles.textInput.paddingBottom,
33
+ default: undefined,
34
+ })
35
+ , [])
36
+
37
+ const [height, setHeight] = useState<number | undefined>(minHeight)
38
+
39
+ const handleContentSizeChange = useMemo(() => {
40
+ if (Platform.OS === 'web')
41
+ return (e: TextInputContentSizeChangeEvent) => {
42
+ const contentHeight = e.nativeEvent.contentSize.height
43
+ setHeight(Math.max(minHeight ?? 0, contentHeight))
44
+ }
45
+
46
+ return undefined
47
+ }, [minHeight])
48
+
49
+ const handleChange = useCallback((event: TextInputChangeEvent) => {
50
+ if (Platform.OS === 'web')
51
+ // Reset height to 0 to get the correct scrollHeight
52
+ // @ts-expect-error - web-specific code
53
+ window.requestAnimationFrame(() => {
54
+ // @ts-expect-error - web-specific code
55
+ event.nativeEvent.target.style.height = '0px'
56
+ // @ts-expect-error - web-specific code
57
+ event.nativeEvent.target.style.height = `${event.nativeEvent.target.scrollHeight}px`
58
+ })
59
+ }, [])
60
+
27
61
  return (
28
62
  <View style={stylesCommon.fill}>
29
63
  <TextInput
@@ -37,8 +71,10 @@ export function Composer ({
37
71
  keyboardAppearance={isDark ? 'dark' : 'default'}
38
72
  multiline
39
73
  placeholder={placeholder}
74
+ onContentSizeChange={handleContentSizeChange}
75
+ onChange={handleChange}
40
76
  {...textInputProps}
41
- style={getColorSchemeStyle(styles, 'textInput', colorScheme)}
77
+ style={[getColorSchemeStyle(styles, 'textInput', colorScheme), stylesWeb.textInput, { height }, textInputProps?.style]}
42
78
  />
43
79
  </View>
44
80
  )
@@ -55,3 +91,10 @@ const styles = StyleSheet.create({
55
91
  color: '#fff',
56
92
  },
57
93
  })
94
+
95
+ const stylesWeb = StyleSheet.create({
96
+ textInput: {
97
+ /* @ts-expect-error - web-specific styles */
98
+ outlineStyle: 'none',
99
+ },
100
+ })
@@ -14,15 +14,25 @@ exports[`should render <Composer /> and compare with snapshot 1`] = `
14
14
  enablesReturnKeyAutomatically={true}
15
15
  keyboardAppearance="default"
16
16
  multiline={true}
17
+ onChange={[Function]}
17
18
  placeholder="Type a message..."
18
19
  placeholderTextColor="#b2b2b2"
19
20
  style={
20
21
  [
22
+ [
23
+ {
24
+ "fontSize": 16,
25
+ "lineHeight": 22,
26
+ "paddingBottom": 10,
27
+ "paddingTop": 8,
28
+ },
29
+ undefined,
30
+ ],
21
31
  {
22
- "fontSize": 16,
23
- "lineHeight": 22,
24
- "paddingBottom": 10,
25
- "paddingTop": 8,
32
+ "outlineStyle": "none",
33
+ },
34
+ {
35
+ "height": undefined,
26
36
  },
27
37
  undefined,
28
38
  ]
@@ -43,15 +43,25 @@ exports[`should render <InputToolbar /> and compare with snapshot 1`] = `
43
43
  enablesReturnKeyAutomatically={true}
44
44
  keyboardAppearance="default"
45
45
  multiline={true}
46
+ onChange={[Function]}
46
47
  placeholder="Type a message..."
47
48
  placeholderTextColor="#b2b2b2"
48
49
  style={
49
50
  [
51
+ [
52
+ {
53
+ "fontSize": 16,
54
+ "lineHeight": 22,
55
+ "paddingBottom": 10,
56
+ "paddingTop": 8,
57
+ },
58
+ undefined,
59
+ ],
50
60
  {
51
- "fontSize": 16,
52
- "lineHeight": 22,
53
- "paddingBottom": 10,
54
- "paddingTop": 8,
61
+ "outlineStyle": "none",
62
+ },
63
+ {
64
+ "height": undefined,
55
65
  },
56
66
  undefined,
57
67
  ]