自定义上下文菜单
自 ComPDF React Native SDK 2.6.0 起,SDK 支持 自定义上下文菜单(Context Menu)项,并提供对应的 点击事件回调机制,用于响应用户点击自定义菜单按钮的操作。
关于如何配置并添加自定义上下文菜单项,请参考上下文菜单。
监听自定义上下文菜单点击事件
在创建 CPDFReaderView 时,可通过设置
onCustomContextMenuItemTapped 回调来监听自定义上下文菜单项的点击事件。例如:
<CPDFReaderView
ref={pdfReaderRef}
document={samplePDF}
configuration={ComPDFKit.getDefaultConfig({
modeConfig: {
initialViewMode: "annotations",
},
})}
onCustomContextMenuItemTapped={(identifier : string, event: any) => {
// 在此处理自定义上下文菜单项的点击逻辑
}}
/>2
3
4
5
6
7
8
9
10
11
12
13
回调函数说明
onCustomContextMenuItemTapped 的函数签名如下:
(identifier: string, event: any) => void;| 参数名 | 类型 | 说明 |
|---|---|---|
| identifier | String | 被点击的自定义菜单项的唯一标识符。在配置菜单项时通过 CPDFContextMenuItem 指定。 |
| event | dynamic | 点击事件携带的上下文数据(payload)。不同菜单上下文及菜单类型返回的数据结构不同。 |
event 数据结构说明
说明: event 通常以 Map<String, dynamic> 的形式返回。 当返回值中包含 CPDFAnnotation、CPDFWidget 等对象时,可通过对应对象的 API 进一步获取详细属性信息。
1)Global
screenshot(截图相关菜单)
event = {
"identifier": string,
"image": string,
};2
3
4
| 字段 | 类型 | 说明 |
|---|---|---|
| identifier | string | 菜单项标识符 |
| image | string | 截图的图像Base64数据 |
2)View Mode
textSelect(查看模式下文本选中)
event = {
"identifier": String,
"text": String,
"rect": CPDFRectF,
"pageIndex": int,
};2
3
4
5
6
| 字段 | 类型 | 说明 |
|---|---|---|
| identifier | string | 菜单项标识符 |
| text | string | 被选中的文本内容 |
| rect | CPDFRectF | 文本选区在页面中的区域 |
| pageIndex | int | 文本所在页面索引 |
3)Annotation Mode
textSelect(注释模式下文本选中)
event = {
"identifier": string,
"text": string,
"rect": CPDFRectF,
"pageIndex": int,
};2
3
4
5
6
longPressContent(长按页面内容)
event = {
"identifier": string,
"point": any,
"pageIndex": int,
};2
3
4
5
markupContent / soundContent / inkContent / shapeContent / freeTextContent / signStampContent / stampContent / linkContent
当上下文菜单对应的是某一注释对象(如高亮、墨迹、图形、自由文本、签名/图章、链接等)时,event 将返回对应的注释实例:
event = {
"annotation": CPDFAnnotation,
};2
3
4)Content Editor Mode
editTextAreaContent / editSelectTextContent
(内容编辑:文本区域 / 选中文本)
event = {
"editArea": CPDFEditTextArea,
};2
3
imageAreaContent(内容编辑:图片区域)
event = {
"imageArea": CPDFEditImageArea,
};2
3
editPathContent(内容编辑:路径 / 图形区域)
event = {
"editArea": CPDFEditPathArea,
};2
3
longPressWithEditTextMode / longPressWithEditImageMode / longPressWithAllMode
(内容编辑模式下的长按操作)
event = {
"point": any,
"pageIndex": int,
};2
3
4
5)Form Mode
textField / checkBox / radioButton / listBox / comboBox / signatureField / pushButton
(表单模式下的表单字段相关菜单)
event = {
"widget": CPDFWidget,
};2
3