react-native-gifted-chat: Multiline does not grow TextInput until several characters into new line
Issue Description
First of all, I’m a big fan of the chat! Thank you to all who have contributed. 🎉
We’re seeing an issue where the TextInput does not grow vertically until several characters into the new line (see attached gif). So, it’ll grow to two lines on, say, the 5th character after the wrap. Same with the third line, fourth line, etc. After a few characters, the TextInput does grow to show the line.
Steps to Reproduce / Code Snippets
Repro Steps:
- Type until the end of the first line.
- Type 1-3 characters into the second line, so that the text wraps. See the TextInput has not yet grown.
- Type a few more characters. See that TextInput grows to show the second line.
<GiftedChat
alignTop
renderSend={() => null}
renderAccessory={({ text, onSend }) => (
<MessengerInputButtons
sendButton={sendButton}
onSend={onSend}
text={text}
showMediaPrompt={this.props.showMediaPrompt}
/>
)}
renderBubble={(props) => <ChatBubble {...props} />}
messages={formattedMessages}
renderMessageText={(props) => <MessageText {...props} />}
renderMessageImage={(props) => <MessageImage {...props} />}
renderTime={() => null}
renderDay={(props) => <ChatTimeStamp {...props} />}
renderAvatar={(msgs) => (
<FailedMessage
showRetryActionSheet={this.props.showRetryActionSheet}
messages={msgs}
/>
)}
showUserAvatar
placeholder={'Write a message...'}
placeholderTextColor={colors.brightGrey}
textInputStyle={styles.textInputStyle}
renderInputToolbar={(props) => (
<InputToolbar
{...props}
containerStyle={styles.inputContainerStyle}
/>
)}
onSend={sendButton ? () => {} : message => this._onSend(message)}
minInputToolbarHeight={this.determineMinInputHeight()}
keyboardShouldPersistTaps={'never'}
imageStyle={{ margin: 0 }}
user={{ _id: this.props.user.id }}
textInputProps={{
selectionColor: colors.seafoam,
marginTop: 12,
marginLeft: 0,
marginBottom: interfaceHelper.styleSwitch({
xphone: 21, iphone: 6, android: 6,
}),
marginRight: 0,
paddingTop: 0,
}}
/>
Expected Results
When text wrapped, we expect the TextInput to grow on the first new character of the new line, not on the, say, 5th or 6th character of the new line.
Additional Information
- Nodejs version: v8.11.4
- React version: 16.4.1
- React Native version: 0.56.0
- react-native-gifted-chat version: 0.13.0
- Platform(s) (iOS, Android, or both?): iOS
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 17
- Comments: 31 (12 by maintainers)
This was not an easy one. It took me a lot of work to find and fix the issue too + animate the input nicely. You simple can’t use padding for your input, it will break the multi-line calculation (thats why you have this glitch)
Since I really wanted a round input + be flexible with animation, I ended up providing my own InputToolbar and I copied the
<Composer>
from gifted chat and reworked it, rendering my own <Composer>.The roudness and padding comes from my
<View>
(and not from the Input) with border and all that padding around it, too. The input is a dead simple input without any borders or padding. But now, setting lineHeight and fontSize won’t break the calculation, since the input has no padding 😃I won’t give any support on this, but here is my custom Composer, which you can add as custom prop to
<GiftedChat>
. Play with it until it fits your needs.It will prob. not work right away for you and you need to know that I use the UIManager for the animation, which have to be activated for android. (its already in the code) In my case, it works butter smooth on iOS and very good on low end Android devices (also butter smooth on high end devices).
If you don’t want that smooth nice animation, delete that parts and just have a look how I fixed the issue.
Here is a video of my input: https://streamable.com/qedbpb
TL;DR: dont add padding to your input, add the padding you need to a wrapping view.
@izakfilmalter functional component version 😉
really god job @Hirbod
There are many factors to keep in mind @newkolay. This are some props which kick into the calculation (remember, they are all suited to my layout and app and might differ from yours and need to be adjusted)
I also have a custom
renderInputToolbar
prop. These paddings kick in too.And think to pass the composer right
Fit those parameters to your need. I am currently rewriting my Chat to functional components and will do a big cleanup and repost my new effort in couple of weeks but for now it should be understandable. Make sure to also install the newest version since it has some toolbar fixes wich I’ve send a PR for.
I also think that a single iPhoneX check might not be enough since there are also android devices with a notch. I will change that to use safe-area insets once I’m done refactoring.
For everyone else, you can try the following, though not sure if it’ll break anything else that might rely on a fixed height.
@newkolay ok I fixed it: Change the onContentSizeChange function with this here. Thanks for reporting, since it was also bugged in my App 😄
I also updated my original post
I’m testing with a fixed value of 22, as you pointed. It’s not happening anymore. I’m going to test it and if it’s good, I let you know.
UPDATE
@Hirbod, it’s not happening anymore. I’m using a hook from
react-native-safe-area-view-context
to get the precisely value for the bottom inset.Thanks!
Any news on this? Still happening. Thanks!
I noticed that this is happening because of setting a custom padding in textInputStyle of the Composer.
@Johan-dutoit I believe the problem is being caused by this line: https://github.com/FaridSafi/react-native-gifted-chat/blame/d40c3bb011c4b8e303f7fda18fd7afd2bdbd695e/src/Composer.tsx#L106 which by default sets the height of the composer to a fixed height of 200. When I comment out that line, then it starts working again.
I switched to getstream. This lib is dead.
On Thu, Feb 24, 2022 at 9:57 AM Hirbod @.***> wrote:
– Izak
I abandoned this project and switched over to https://github.com/flyerhq/react-native-chat-ui, which also has superb input accessory support
@izakfilmalter unfortunately not. The chat is the last thing in my app I haven’t refactored yet.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.