0

我在 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>
        )
    }
}

4

1 回答 1

0

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

于 2020-04-23T11:51:01.540 回答