asasugar / HPRichText

hp-richtext, 是一个适用于 HarmonyOS Next 的富文本解析组件。
Apache License 2.0
50 stars 3 forks source link

onLinkPress会导致想点击整个组件没办法回调 #35

Closed ycbiao closed 3 months ago

ycbiao commented 3 months ago

image

asasugar commented 3 months ago

image

HPRichText({
        richTextOption: $richTextOption,
        needScroll: true,
        onLinkPress: (e) => {
          return e;
        }
      })
        .onTouch((event) => {
          if ((event as TouchEvent).type == TouchType.Down) {
            console.info('stack touched type: ' + (event as TouchEvent).type)
          }
        })
hejinxigege commented 1 month ago

在列表中怎么解决这个问题

asasugar commented 1 month ago

在列表中怎么解决这个问题

import { HPRichTextV2, RichTextOptionModelV2 } from '@ohasasugar/hp-richtext';

@Entry
@Component
struct Index {
  @State arr: RichTextOptionModelV2[] = []

  // 模拟请求接口数据
  aboutToAppear(): void {
    for (let i = 0; i < 4; i++) {
      let o = new RichTextOptionModelV2();
      o.richTextOption.content = `<span style="color: #fff">我是 HPRichTextV2 组件${i}</span>`;
      this.arr.push(o)
    }
  }

  build() {
    Column() {
      List({ space: 10 }) {
        ForEach(this.arr, (item: RichTextOptionModelV2) => {
          ListItem() {
            HPRichTextV2({
              richTextModel: item
            })
              .width('100%')
              .height(100)
              .borderRadius(10)
              .backgroundColor(0x007DFF)
              .onClick((event) => {
                console.log('1111', JSON.stringify(item), JSON.stringify(event))
              })
          }
        }, (item: number) => JSON.stringify(item))
      }
    }
    .padding(12)
    .height('100%')
    .backgroundColor(0xF1F3F5)
  }
}