使用MutableStyledString append文本 然后给指定的start - end之间插入特殊customspan 报错 Error: Input span type check failed.@122472bf
let styleString = new MutableStyledString("")
styleString.appendStyledString(new StyledString("第一个段落" + "\r\n"))
try {
styleString.setStyle({
styledKey: StyledStringKey.CUSTOM_SPAN,
styledValue: new QDParagraphSpan(),
start: start,
length: end - start
})
} catch (e) {
readLogError(e)
}
export class QDParagraphSpan extends CustomSpan {
onMeasure(measureInfo: CustomSpanMeasureInfo): CustomSpanMetrics {
return { width: 0, height: 0 }
}
onDraw(context: DrawContext, drawInfo: CustomSpanDrawInfo): void {
}
}
创建CustomSpan只接受 new MutableStyledString(new CustomSpan()) 如果需要使用setStyle来设置 只允许在本身就是CustomSpan上替换CustomSpan。
new MutableStyledString(new CustomSpan())的length只能是1。
考虑要在CustomSpan中存储数据,这样写看下:
customspan可以理解为一个文字字符占位,自绘制的,不能跨多个,长度都是1