【问题标题】:How can i delete message on click of bubble touch? React Native Gifted chat library如何在单击气泡触摸时删除消息? React Native Gifted 聊天库
【发布时间】:2019-05-22 17:35:39
【问题描述】:

我在 React Native 中使用 gifted 聊天库开发了聊天视图。但我想在点击聊天气泡时执行删除操作。

我尝试了自定义 renderCustomView 、lightboxProps 和 onLongPress 道具,但都没有工作。

【问题讨论】:

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


    【解决方案1】:

    像这样将 onLongPress 添加到 GiftedChat 组件中

    <GiftedChat
           onLongPress={this.onLongPress}
        
           ....
           ....
    />
    
    

    onLongPress 返回context, message。然后您可以显示一个 ActionSheet 并添加要删除的逻辑。

    
        onLongPress(context, message) {
            console.log(context, message);
            const options = ['Delete Message', 'Cancel'];
            const cancelButtonIndex = options.length - 1;
            context.actionSheet().showActionSheetWithOptions({
                options,
                cancelButtonIndex
            }, (buttonIndex) => {
                switch (buttonIndex) {
                    case 0:
                        // Your delete logic
                        break;
                    case 1:
                        break;
                }
            });
        }
    

    【讨论】:

    • 你能帮忙解决删除消息的逻辑吗? :)
    • 让 temp = messages.filter(temp => message._id !== temp._id); this.setState({ messages: temp, });
    猜你喜欢
    • 2018-11-01
    • 1970-01-01
    • 2018-08-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-17
    • 2020-10-28
    • 1970-01-01
    相关资源
    最近更新 更多