React-native-gifted-chat: mintoolbarheight updates one message render call too late?

Created on 8 Sep 2017  路  2Comments  路  Source: FaridSafi/react-native-gifted-chat

Issue Description

I am confused by this one - in my app I am setting minToolBarHeight{this.state.toolbarHeight}. My expectation is that this.setState({toolbarHeight: 100}) would cause the toolbar to change to that height but it does not do this. Worth noting that setting a static value in minToolbarHeight{100 // for instance} works as expected.

Steps to Reproduce / Code Snippets

I have a dummy button whose onPress, for testing purposes, is:

onPress={() =>
    this.setState({
        toolbarHeight: this.state.toolbarHeight > 0 ? 0 : 100
    },
    () =>
        console.log("Toolbar height: ", this.state.toolbarHeight)
    )
}

Expected Results

Hitting the above button will make the toolbar toggle between having 0 and 100 height.

In fact it causes no immediate effect but the next time a message is pushed onto the message stack the toolbar will at THAT point snap to the height in this.state.toolbarHeight.

I am perfectly willing to accept that I am making a basic error here but if I am I am not seeing it and help would be GREATLY appreciated!!

Additional Information

  • React Native version: 0.46.9
  • react-native-gifted-chat version: 0.2.5
  • Platform(s) (iOS, Android, or both?): iOs
help wanted wontfix

Most helpful comment

438 helped me solve this. Feel free to close this but I'm going to leave it open so that anyone trying to find a solution might stumble upon this.

The specific steps I took were:

<GiftedChat
    minInputToolbarHeight={this.state.minInputToolbarHeight}
    ref={ref => (this.chat = ref)} // <-- important
    ...
/>

coupled with:

componentDidUpdate(prevProps, prevState) {
        if (
            prevState.minInputToolbarHeight != this.state.minInputToolbarHeight
        ) {
            this.chat.resetInputToolbar();
        }
    }

All 2 comments

438 helped me solve this. Feel free to close this but I'm going to leave it open so that anyone trying to find a solution might stumble upon this.

The specific steps I took were:

<GiftedChat
    minInputToolbarHeight={this.state.minInputToolbarHeight}
    ref={ref => (this.chat = ref)} // <-- important
    ...
/>

coupled with:

componentDidUpdate(prevProps, prevState) {
        if (
            prevState.minInputToolbarHeight != this.state.minInputToolbarHeight
        ) {
            this.chat.resetInputToolbar();
        }
    }

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

arayaryoma picture arayaryoma  路  3Comments

yogiben picture yogiben  路  3Comments

tafelito picture tafelito  路  3Comments

SytzeAndr picture SytzeAndr  路  3Comments

inceptivetech picture inceptivetech  路  3Comments