HarmonyOS 鸿蒙Next版本何时发布

发布于 1周前 作者 ionicwang 来自 鸿蒙OS

HarmonyOS 鸿蒙Next版本何时发布

import measure from ‘@ohos.measure’

/*

  • 文本折叠组件
  • */ @Component export struct TimeTextCollapseComponent { @Prop rawTitle: string = ‘带宝宝去海边了小家伙们带宝宝去伙们带宝宝去海边了小家伙们小家伙们小家伙们带宝宝去了小家伙们带宝宝去海边’ + ‘了小家伙们带宝宝去伙们带宝宝去海边了小家伙们小家伙们小家伙们带宝宝去了小家伙们带宝宝去海边了’ + ‘小家伙们带宝宝去伙们带宝宝去海边了小家伙们小家伙们小家伙们带宝宝去了小家伙们带宝宝去海边了小家伙’ + ‘们带宝宝去伙们带宝宝去海边了小家伙们小家伙们小家伙们带宝宝去了小家伙们带宝宝去海边了小家伙们’ //标签(夏日出游) @Prop tagText: string = ‘夏日出游’ //段落内容 @State longTitle: string = this.rawTitle //长段落后缀(展开或收起) @State suffixStr: string = “” //展开文字 expanded: boolean = true titleWidth: number = 342 //收起文字 needProcess: boolean = true ellipsis: string = “…” EXPAND_STR: string = " 展开" COLLAPSE_STR: string = " 收起" //最大行数 @Prop maxLine: number = 4; //点击#标签 clickTag: () => void = () => {

}

aboutToAppear(): void { this.process(); }

process(): void { if (this.expanded) { this.collapseText(); } else { this.expandText(); } }

//展开文本 expandText(): void { if (this.needProcess) { this.suffixStr = this.COLLAPSE_STR; this.expanded = true; this.longTitle = this.rawTitle; } }

//收起文本 collapseText(): void { if (!this.needProcess) { return; } let titleSize: SizeOptions = measure.measureTextSize({ textContent: this.rawTitle, constraintWidth: this.titleWidth, fontSize: 14 }) let twoLineSize: SizeOptions = measure.measureTextSize({ textContent: this.rawTitle, constraintWidth: this.titleWidth, fontSize: 14, maxLines: this.maxLine }) //文本未超过限制行数,不进行展开、收起处理 if ((titleSize.height as number) == (twoLineSize.height as number)) { this.needProcess = false; return; }

let clipTitle: string = this.rawTitle
this.suffixStr = this.EXPAND_STR;
while ((titleSize.height as number) > (twoLineSize.height as number)) {
  this.expanded = true;
  // 可以修改其他计算算法提高性能
  clipTitle = clipTitle.substring(0, clipTitle.length - 1);
  titleSize = measure.measureTextSize({
    textContent: clipTitle + this.ellipsis + this.suffixStr,
    constraintWidth: this.titleWidth,
    fontSize: 14
  })
}

this.longTitle = clipTitle + this.ellipsis
this.expanded = false

}

build() { this.newTExtBuilder() }

@Builder newTExtBuilder() { Row() { Text() { Span(#${this.tagText}) .fontSize(14) .fontColor(’#705DD5’) .fontWeight(FontWeight.Medium) .onClick(() => { this.clickTag() }) //Span不支持首行缩进,暂时使用模板字符串代替加空格 Span(${this.longTitle}) .fontSize(14) .lineHeight(26) .fontColor(’#1F1F1F’) if (this.needProcess) { Span(this.suffixStr) .fontColor(’#878787’) .onClick(() => { this.process() }) } } .fontSize(14) .fontColor(’#1F1F1F’) } .margin({ bottom: 2 }) .padding({ left: 12, right: 12 }) .width(‘100%’) } }


更多关于HarmonyOS 鸿蒙Next版本何时发布的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html

2 回复

import measure from ‘@ohos.measure’

/*

  • 文本折叠组件
  • */ @Component export struct TimeTextCollapseComponent { rawTitle: string = ‘带宝宝去海边了小家伙们带宝宝去伙们带宝宝去海边了小家伙们小家伙们小家伙们带宝宝去了小家伙们带宝宝去海边’ + ‘了小家伙们带宝宝去伙们带宝宝去海边了小家伙们小家伙们小家伙们带宝宝去了小家伙们带宝宝去海边了’ + ‘小家伙们带宝宝去伙们带宝宝去海边了小家伙们小家伙们小家伙们带宝宝去了小家伙们带宝宝去海边了小家伙们’ + ‘带宝宝去伙们带宝宝去海边了小家伙们小家伙们小家伙们带宝宝去了小家伙们带宝宝去海边了小家伙们’ //标签(夏日出游) @Prop tagText: string = ‘夏日出游’ //段落内容 @State longTitle: string = this.rawTitle //长段落后缀(展开或收起) @State suffixStr: string = “” //展开文字 expanded: boolean = true titleWidth: number = 342 //收起文字 needProcess: boolean = true ellipsis: string = “…” EXPAND_STR: string = " 展开" COLLAPSE_STR: string = " 收起" //最大行数 @Prop maxLine: number = 4; //点击#标签 clickTag: () => void = () => {

}

aboutToAppear(): void { this.process(); }

process(): void { if (this.expanded) { this.collapseText(); } else { this.expandText(); } }

//展开文本 expandText(): void { if (this.needProcess) { this.suffixStr = this.COLLAPSE_STR; this.expanded = true; this.longTitle = this.rawTitle; } }

//收起文本 collapseText(): void { if (!this.needProcess) { return; } let titleSize: SizeOptions = measure.measureTextSize({ textContent: this.rawTitle, constraintWidth: this.titleWidth, fontSize: 14 }) let twoLineSize: SizeOptions = measure.measureTextSize({ textContent: this.rawTitle, constraintWidth: this.titleWidth, fontSize: 14, maxLines: this.maxLine }) //文本未超过限制行数,不进行展开、收起处理 if ((titleSize.height as number) == (twoLineSize.height as number)) { this.needProcess = false; return; }

let clipTitle: string = this.rawTitle
this.suffixStr = this.EXPAND_STR;
while ((titleSize.height as number) > (twoLineSize.height as number)) {
  // 可以修改其他计算算法提高性能
  clipTitle = clipTitle.substring(0, clipTitle.length - 1);
  titleSize = measure.measureTextSize({
    textContent: clipTitle + this.ellipsis + this.suffixStr,
    constraintWidth: this.titleWidth,
    fontSize: 14
  })
}

this.longTitle = clipTitle + this.ellipsis
this.expanded = false

}

build() { this.newTExtBuilder() }

@Builder newTExtBuilder() { Row() { Text() { Span(#${this.tagText}) .fontSize(14) .fontColor(’#705DD5’) .fontWeight(FontWeight.Medium) .onClick(() => { this.clickTag() }) //Span不支持首行缩进,暂时使用模板字符串代替加空格 Span(${this.longTitle}) .fontSize(14) .lineHeight(26) .fontColor(’#1F1F1F’) if (this.needProcess) { Span(this.suffixStr) .fontColor(’#878787’) .onClick(() => { this.process() }) } } .fontSize(14) .fontColor(’#1F1F1F’) } .margin({ bottom: 2 }) .padding({ left: 12, right: 12 }) .width(‘100%’) } }

更多关于HarmonyOS 鸿蒙Next版本何时发布的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html


关于HarmonyOS(鸿蒙)Next版本的发布时间,这通常取决于华为官方的开发计划和市场策略。鸿蒙系统的更新迭代旨在为用户提供更优质、更安全的操作系统体验,因此每一次版本升级都经过严格的测试和优化。

鸿蒙Next版本的发布时间并未公开透露,这可能与华为希望保持一定的市场神秘感和竞争力有关。一般来说,华为会在适当的时机,通过官方渠道(如官网、社交媒体、开发者论坛等)发布关于新版本的具体信息,包括发布日期、新增功能、优化内容等。

为了获取最准确的信息,建议您密切关注华为官方渠道,以便在第一时间了解鸿蒙Next版本的最新动态。同时,也可以加入华为开发者社区,与其他开发者交流心得,共同期待鸿蒙系统的每一次进步。

如果问题依旧没法解决请联系官网客服,官网地址是: https://www.itying.com/category-93-b0.html

回到顶部