如何在单击气泡触摸时删除消息?React Native 天才聊天库

Raj*_*sit 0 chat react-native react-native-gifted-chat

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

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

小智 8

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

<GiftedChat
       onLongPress={this.onLongPress}

       ....
       ....
/>

Run Code Online (Sandbox Code Playgroud)

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;
            }
        });
    }
Run Code Online (Sandbox Code Playgroud)