【问题标题】:Trying to update renderCustomView in GiftedChat after state change状态更改后尝试在 GiftedChat 中更新 renderCustomView
【发布时间】:2020-08-06 16:31:08
【问题描述】:

我在 onLongPress 函数中发出状态更改信号,但是 renderCustomView 没有更新/重新渲染它的新视图。我曾尝试使用 this.forceUpdate() 但没有成功。我已经提供了我试图在状态更改后呈现的视图。

https://i.stack.imgur.com/Perfv.png

 displayEmojis(){
        if(this.state.toggle){
        return(
        <View 
        style={{flexDirection:'row', right:'35%',  backgroundColor:'white', zIndex:3, overlayColor: 'white',borderRadius:30,  paddingHorizontal:'10%', bottom:'2%' }}>
        {this.beerEmoji()}
        {this.partyEmoji()}
        {this.laughingEmoji()}
        {this.happyEmoji()}
        {this.cryingEmoji()}
        </View>
        )
      }
    }

    toggleEmojis = (val) => {
        this.setState({toggle: true})
    }


    render() {
        return (
            <View style={{ flex: 1 }}>
                <GiftedChat
                    keyboardShouldPersistTaps={'handled'}
                    messages={this.state.messages}
                    onSend={messages => this.onSend(messages)}
                    placeholder={"Post something..."}
                    isKeyboardInternallyHandled={false}
                    renderQuickReplySend={true}
                    multiline={true}
                    alwaysShowSend={true}
                    onLongPress={(context, message)=> this.toggleEmojis()}
                    user={{ _id: 1 }}
                    renderCustomView={this.displayEmojis}
                    renderMessage={this.renderMessage} />
                <KeyboardSpacer />
            </View>
        )
    }
}

【问题讨论】:

    标签: react-native rerender react-native-gifted-chat


    【解决方案1】:

    我已经通过在 GiftedChat 中使用 extraData={this.state} 属性解决了这个问题

    【讨论】:

      猜你喜欢
      • 2019-12-09
      • 1970-01-01
      • 1970-01-01
      • 2016-10-02
      • 2019-04-17
      • 2021-12-29
      • 2021-06-15
      • 1970-01-01
      相关资源
      最近更新 更多