【发布时间】:2019-05-22 17:35:39
【问题描述】:
我在 React Native 中使用 gifted 聊天库开发了聊天视图。但我想在点击聊天气泡时执行删除操作。
我尝试了自定义 renderCustomView 、lightboxProps 和 onLongPress 道具,但都没有工作。
【问题讨论】:
标签: react-native chat react-native-gifted-chat
我在 React Native 中使用 gifted 聊天库开发了聊天视图。但我想在点击聊天气泡时执行删除操作。
我尝试了自定义 renderCustomView 、lightboxProps 和 onLongPress 道具,但都没有工作。
【问题讨论】:
标签: react-native chat react-native-gifted-chat
像这样将 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;
}
});
}
【讨论】: