question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Re-render a Button inside “renderMessageImage” to change its “disabled” property

See original GitHub issue

Issue Description

I’m trying to re-render a Button inside renderMessageImage to make its disabled property change from false to true when onPress.

I am doing it through a boolean in this.state, however I see the state value updating on the logs but the button remains visually the same and it can be pressed again and again without actually changing its disabled property.

Steps to Reproduce / Code Snippets

Just setting up a simple class (eg. Chat.js) where I set the renderMessageImage to return a View with a Button which disabled property is obtained from a state value:

constructor(props) {
    super(props);
    this.state = {
        messages: [],
        isButtonDisabled: false
    };
}

renderMessageImage = (props) => {
      return (
      <View>
          <Button
            title="Disable Button"
            disabled={this.state.isButtonDisabled}
            onPress={() => this.disableButton(props.currentMessage.id)}
          />
      </View>)
}

render() {
    return (
      <View style={{ flex: 1 }}>
        <GiftedChat
          messages={this.state.messages}
          user={this.user}
          placeholder={"Write a message..."}
          renderMessageImage={this.renderMessageImage}
        />
      </View>
    );
}

Then I call a simple method when onPress that button to make the isButtonDisabled state value change to true:

disableButton = async (message_id) => {
      console.log("Disabling message_id: " + message_id); //This shows the msg_id correctly where the button is
      this.setState(previousState => ({
          isButtonDisabled: true
        }));
      return true;
}

Finally I am checking this.state.isButtonDisabled and it is actually changing, but the button remains enabled, it doesn’t get re-rendered and thus it can be clicked again and again.

Expected Results

I checked that the GiftedChat.js component and messages are being updated once per button click so I guess that it should be forcing a re-render, however the button created in renderMessageImage is never re-rendering/updating to properly show its new disabled value and actually become disabled.

Additional Information

  • Nodejs version: 10.15.3
  • React version: 16.8.3
  • React Native version: 0.59.8
  • react-native-gifted-chat version: 0.12.0-beta-0
  • Platform(s) (iOS, Android, or both?): Android
  • TypeScript version: -

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:18

github_iconTop GitHub Comments

5reactions
stale[bot]commented, Sep 27, 2020

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.

5reactions
charles-goodecommented, Mar 8, 2020

I’m experiencing a very similar issue where my FB messenger-esque emoji reaction popup (part of my custom message bubble) only re-renders for the top message and the most recent message. This has been a VERY common problem for a while now, so I’d love to see it fixed. 1378 1588 are the two most recent to stale out with no action. In 1483 some claim to have gotten it to work by updating. This is definitely not working for some of us. Just searching “re-render” on this repo gives various reformulations of this same problem dating back at least TWO years: 654

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to re-render a Button to change "disabled" property on ...
I'm trying to re-render a button to make its disabled property change ... This button is being manually rendered inside renderMessageImage ...
Read more >
How to re-render a Button to change .. - W3coded.com
How to re-render a Button to change “disabled” property on “renderMessageImage” with react-native-gifted-chat ... Skills Develop in { ANGULAR } Learning.
Read more >
The most complete chat UI for React Native & Web - Morioh
... to be passed to the <Image> component created by the default renderMessageImage ... disabled?: boolean, disabled 'item' is greyed out and onPress...
Read more >
keyboardshouldpersisttaps - OSCHINA - 中文开源技术交流社区
... 自定义消息的文本renderMessageImage(Function) - 自定义图片 ... 搜索 'react native button' onPress title color disabled Picker <Picker ...
Read more >
react-native-gifted-chat - Updating messages properties will ...
renderMessage.bind(this)} renderMessageImage={this. ... this.props.match.chat_user && this.props.match.chat_user.disabled ? this.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found