文档管理中心
FAQ应用框架开发UI框架组件使用如何设置customspan不同位置的点击事件

如何设置customspan不同位置的点击事件

CustomSpan 是最小单位的组件。若需实现特定功能,建议在多个 CustomSpan 上分别进行。如果必须在同一 CustomSpan 上实现,可从点击事件回调的 ClickEvent 中,根据属性判断实际点击位置,从而做出差异化响应。示例代码如下:

收起
自动换行
深色代码主题
复制
  1. @Entry
  2. @Component
  3. struct Index {
  4. controller: RichEditorController = new RichEditorController();
  5. option: RichEditorOptions = { controller: this.controller };
  6. @Builder
  7. comment() {
  8. Row() {
  9. Text() {
  10. Span('123123123')
  11. ImageSpan($r('app.media.startIcon')).width(20).height(20)
  12. Span('ggggggggggggggggggggggxxxxxxxxxxxxxxxxxxxxxxx')
  13. }
  14. .maxLines(1)
  15. .wordBreak(WordBreak.BREAK_ALL)
  16. .textOverflow({ overflow: TextOverflow.Ellipsis })
  17. .constraintSize({
  18. maxWidth: '90%'
  19. })
  20. Image($r('app.media.startIcon'))
  21. .width(25)
  22. .height(25)
  23. .onClick(() => {
  24. this.getUIContext().getPromptAction().showToast({
  25. message: 'Click to delete'
  26. })
  27. })
  28. }
  29. .width('100%')
  30. .align(Alignment.Center)
  31. .padding({
  32. top: 5,
  33. bottom: 5
  34. })
  35. .borderRadius(20)
  36. .backgroundColor(Color.Gray)
  37. }
  38. build() {
  39. Column() {
  40. Column() {
  41. RichEditor(this.option)
  42. .onReady(() => {
  43. this.controller.addBuilderSpan(() => this.comment())
  44. })
  45. .borderWidth(1)
  46. .borderColor(Color.Green)
  47. .width('100%')
  48. .height('30%')
  49. }
  50. .borderWidth(1)
  51. .borderColor(Color.Red)
  52. .width('100%')
  53. .height('70%')
  54. }
  55. }
  56. }
在 FAQ 中进行搜索
请输入您想要搜索的关键词