From 0e8698e0966ce90a6d01b2255972d503b48f8b39 Mon Sep 17 00:00:00 2001 From: lidan Date: Thu, 31 Jul 2025 15:53:59 +0800 Subject: [PATCH] fix 6.0 bug and memory gc --- build-profile.json5 | 1 - .../src/main/ets/common/utils/OCRManager.ets | 5 +- entry/src/main/ets/model/DataModel.ets | 4 +- entry/src/main/ets/pages/Index.ets | 17 +++-- .../src/main/ets/views/ConsigneeInfoItem.ets | 67 +++++++++---------- 5 files changed, 47 insertions(+), 47 deletions(-) diff --git a/build-profile.json5 b/build-profile.json5 index 8186785..807c91e 100644 --- a/build-profile.json5 +++ b/build-profile.json5 @@ -1,7 +1,6 @@ { "app": { "signingConfigs": [ - ], "products": [ { diff --git a/entry/src/main/ets/common/utils/OCRManager.ets b/entry/src/main/ets/common/utils/OCRManager.ets index 549dd12..bb5c753 100644 --- a/entry/src/main/ets/common/utils/OCRManager.ets +++ b/entry/src/main/ets/common/utils/OCRManager.ets @@ -68,6 +68,7 @@ export class OCRManager { // Visual information to be recognized. Currently, only the visual information of the PixelMap type in color data format RGBA_8888 is supported. let visionInfo: textRecognition.VisionInfo = { pixelMap: await OCRManager.getPixelMap(uri) }; let result: textRecognition.TextRecognitionResult = await textRecognition.recognizeText(visionInfo); + visionInfo.pixelMap.release(); return result.value; } @@ -75,7 +76,9 @@ export class OCRManager { // Convert image resources to PixelMap let fileSource = await fs.open(uri, fs.OpenMode.READ_ONLY); let imgSource: image.ImageSource = image.createImageSource(fileSource.fd); + let pixelMap: image.PixelMap = await imgSource.createPixelMap(); fs.close(fileSource); - return imgSource.createPixelMap(); + imgSource.release(); + return pixelMap; } } \ No newline at end of file diff --git a/entry/src/main/ets/model/DataModel.ets b/entry/src/main/ets/model/DataModel.ets index 8f6ef1b..f68dfa9 100644 --- a/entry/src/main/ets/model/DataModel.ets +++ b/entry/src/main/ets/model/DataModel.ets @@ -13,11 +13,11 @@ * limitations under the License. */ -@Observed +@ObservedV2 export class ConsigneeInfo { label: ResourceStr; placeholder: ResourceStr; - value: string; + @Trace value: string; constructor(label: ResourceStr, placeholder: ResourceStr, value: string) { this.label = label; diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index baadb20..6e1f153 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -130,19 +130,19 @@ struct Index { List() { ForEach(this.consigneeInfos, (item: ConsigneeInfo) => { ListItem() { - ConsigneeInfoItem({ - item: item, checkAvailable: () => { - if (this.consigneeInfos[0].value && this.consigneeInfos[1].value && this.consigneeInfos[2].value) { - this.saveAvailable = true; - } else { - this.saveAvailable = false; - } + ConsigneeInfoItem( + item, () => { + if (this.consigneeInfos[0].value && this.consigneeInfos[1].value && this.consigneeInfos[2].value) { + this.saveAvailable = true; + } else { + this.saveAvailable = false; } }) } }, (item: ConsigneeInfo, index: number) => JSON.stringify(item) + index) } .width("100%") + .height(LayoutPolicy.matchParent) .scrollBar(BarState.Off) .divider({ strokeWidth: 0.5, color: $r('app.color.divider_color') }) .padding({ @@ -151,9 +151,12 @@ struct Index { top: 4, bottom: 4 }) + .borderRadius(16) + .backgroundColor($r('app.color.light_background')) } .borderRadius(16) .margin({ top: 12 }) + .constraintSize({ minHeight: 150, maxHeight: '50%' }) .backgroundColor($r('app.color.light_background')) } diff --git a/entry/src/main/ets/views/ConsigneeInfoItem.ets b/entry/src/main/ets/views/ConsigneeInfoItem.ets index fdea874..2b7ab05 100644 --- a/entry/src/main/ets/views/ConsigneeInfoItem.ets +++ b/entry/src/main/ets/views/ConsigneeInfoItem.ets @@ -16,42 +16,37 @@ import CommonConstants from "../common/constants/CommonConstants"; import { ConsigneeInfo } from "../model/DataModel"; -@Component -export struct ConsigneeInfoItem { - @ObjectLink item: ConsigneeInfo; - checkAvailable?: () => void; +@Builder +export function ConsigneeInfoItem(item: ConsigneeInfo, checkAvailable?: () => void) { + Row() { + Text(item.label) + .fontSize(16) + .fontWeight(400) + .lineHeight(19) + .textAlign(TextAlign.Start) + .fontColor($r('app.color.item_label_color')) + .opacity(0.9) + .layoutWeight(1) - build() { - Row() { - Text(this.item.label) - .fontSize(16) - .fontWeight(400) - .lineHeight(19) - .textAlign(TextAlign.Start) - .fontColor($r('app.color.item_label_color')) - .opacity(0.9) - .layoutWeight(1) - - TextArea({ placeholder: this.item.placeholder, text: this.item.value }) - .type(this.item.label === CommonConstants.PHONE_LABEL ? TextAreaType.PHONE_NUMBER : TextAreaType.NORMAL) - .fontSize(16) - .fontWeight(500) - .lineHeight(21) - .padding(0) - .borderRadius(0) - .textAlign(TextAlign.End) - .fontColor($r('app.color.item_label_color')) - .opacity(0.9) - .backgroundColor($r('app.color.light_background')) - .heightAdaptivePolicy(TextHeightAdaptivePolicy.MIN_FONT_SIZE_FIRST) - .layoutWeight(2) - .onChange((value: string) => { - this.item.value = value; - this.checkAvailable?.(); - }) - } - .width("100%") - .constraintSize({ minHeight: 48 }) - .justifyContent(FlexAlign.SpaceBetween) + TextArea({ placeholder: item.placeholder, text: item.value }) + .type(item.label === CommonConstants.PHONE_LABEL ? TextAreaType.PHONE_NUMBER : TextAreaType.NORMAL) + .fontSize(16) + .fontWeight(500) + .lineHeight(21) + .padding(0) + .borderRadius(0) + .textAlign(TextAlign.End) + .fontColor($r('app.color.item_label_color')) + .opacity(0.9) + .backgroundColor($r('app.color.light_background')) + .heightAdaptivePolicy(TextHeightAdaptivePolicy.MIN_FONT_SIZE_FIRST) + .layoutWeight(2) + .onChange((value: string) => { + item.value = value; + checkAvailable?.(); + }) } + .width("100%") + .constraintSize({ minHeight: 48 }) + .justifyContent(FlexAlign.SpaceBetween) } \ No newline at end of file -- Gitee