单击气泡触摸后如何删除消息?反应本机资优聊天库

时间:2019-05-22 17:35:39

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

我已经使用What's the principal difference between MS AppCenter and Azure DevOps (former VSTS)?聊天库在React Native中开发了聊天视图。但是我想在单击聊天气泡时执行删除操作。

我尝试了自定义renderCustomView,lightboxProps和onLongPress道具,但都无法正常工作。

1 个答案:

答案 0 :(得分:4)

像这样将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 `:
                    break;
            }
        });
    }