chenquansheng

fix |> 评论行数显示优化

... ... @@ -751,7 +751,7 @@ struct commentHeaderView {
maxline: 3,
fontSize: 16,
fontWeight: FontWeight.Regular,
marginWidth: (this.isZD?60:70 + 16)
marginWidth: (this.isZD?60:this.leftGap + 16)
})
.margin({ left: this.leftGap, right: 16,top:-12 })
.onClick(() => {
... ...
... ... @@ -41,36 +41,37 @@ export struct CommentText {
promise: Promise<Array<display.Display>> = display.getAllDisplays()
aboutToAppear() {
// this.longMessage = TestLongText
let tempMessage = new String(this.longMessage)
tempMessage = tempMessage.replace(/\n/g,'')
// console.log(`>>>>>>>文本:${this.longMessage}-${tempMessage}`)
console.log(`文本宽度为:${this.textWidth}`)
let padding = vp2px(5 + this.marginWidth)
this.textWidth = measure.measureText({
textContent: this.longMessage,
textContent: tempMessage.toString(),
fontSize: this.fontSize,
fontWeight: this.fontWeight,
constraintWidth: (this.screenWidth - padding),
wordBreak:WordBreak.BREAK_ALL
})
console.log(`文本宽度为:${this.textWidth}`)
// console.log(`>>>>>>>文本宽度为:${this.textWidth}-${this.contentText}`)
this.promise.then((data: Array<display.Display>) => {
console.log(`所有的屏幕信息:${JSON.stringify(data)}`)
//单位为像素
this.screenWidth = data[0]["width"]
// 屏幕宽度 * 最大行数 * 组件宽度比例 和 文字测量宽度
// 屏幕宽度 * 最大行数 * 组件宽度比例 和 文字测量宽度3900,,3951
this.isExpanded = (this.screenWidth - padding) * this.lines <= this.textWidth
// this.expandedStates = this.isExpanded;
let lines = this.getTextLineNum(
this.longMessage,
tempMessage.toString(),
(this.screenWidth - padding),
this.lineHeight,
this.fontSize,
this.fontWeight
)
console.log(`>>>>>>>行高数:${lines}-${this.screenWidth}-${this.longMessage}`)
if (lines > 3) {
this.isExpanded = true
}
... ... @@ -82,8 +83,8 @@ export struct CommentText {
let padding = vp2px(5 + this.marginWidth)
let maxLineTextWidth = (this.screenWidth - padding) * this.maxline;
for (let index = 0; index < this.longMessage.length; index++) {
const element = this.longMessage.substring(0, index)
for (let index = 0; index < tempMessage.length; index++) {
const element = tempMessage.substring(0, index)
const string = element + this.collapseText; //截取
const thisTextWidth = measure.measureText({
textContent: string,
... ...