React-native-gifted-chat: [Feature request] Prevent the text input to be cleared when the onSend() function fails/rejects

Created on 1 Mar 2018  路  5Comments  路  Source: FaridSafi/react-native-gifted-chat

Feature Request Description

The onSend(messages) function doesn't seem to have a callback.

So, for example, if the app cannot connect to the backend the input field text will be cleared no matter if the message was sent successfully or not.

For example, the device is offline, I would like to show an error and allow to retry once it's connected again.

Expected changes

The onSend() to have a callback to handle this.

Additional Information

  • react-native-gifted-chat version: ^0.3.0

Most helpful comment

+1
Is it possible that textInput keep text when onSend return false?

All 5 comments

+1
Is it possible that textInput keep text when onSend return false?

The text is always cleared in Send.js https://github.com/FaridSafi/react-native-gifted-chat/blob/master/src/Send.js#L14 calling the following function with true https://github.com/FaridSafi/react-native-gifted-chat/blob/master/src/GiftedChat.js#L325.

The solution I used is to override the renderSend combined with controlling the text property with onInputTextChanged.

  renderSend = props => (
    <Send
      {...props}
      onSend={this.handleOnSend}
      }}
    />
  );

  <GiftedChat
    ....
    text={/* text from state manager */}
    onInputTextChanged={/* store your text somewhere */}
    renderSend={this.renderSend}
    ....
   />

Now it's up to you to clear the input field after each send.

@ewal awesome thanks!

@gianpaj, hope it helps! Just ping me if you want a complete code example. Otherwise, maybe we could close this issue?

@ewal can you share complete code example

Was this page helpful?
0 / 5 - 0 ratings

Related issues

arayaryoma picture arayaryoma  路  3Comments

emilkarl picture emilkarl  路  3Comments

redwind picture redwind  路  3Comments

inceptivetech picture inceptivetech  路  3Comments

maharjanaman picture maharjanaman  路  3Comments