From 37057086c3405ed36edbb7740950f20619910b17 Mon Sep 17 00:00:00 2001 From: mahiru Date: Mon, 28 Aug 2023 10:28:41 +0800 Subject: [PATCH] fixed 343370f from https://gitee.com/shina_mahiru/docs/pulls/23197 fix arkts example code warnings Signed-off-by: mahiru --- .../reference/apis/js-apis-curve.md | 6 ++--- .../reference/apis/js-apis-font.md | 6 ++--- .../reference/apis/js-apis-matrix4.md | 4 ++-- .../reference/apis/js-apis-mediaquery.md | 24 +++++++++---------- .../apis/js-apis-system-mediaquery.md | 15 +++++++----- 5 files changed, 29 insertions(+), 26 deletions(-) diff --git a/zh-cn/application-dev/reference/apis/js-apis-curve.md b/zh-cn/application-dev/reference/apis/js-apis-curve.md index fff376653d..4083dbbdb9 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-curve.md +++ b/zh-cn/application-dev/reference/apis/js-apis-curve.md @@ -279,9 +279,9 @@ customCurve(interpolate: (fraction: number) => number): ICurve ```ts import Curves from '@ohos.curves' -let interpolate = function(fraction) { - return Math.sqrt(fraction) - } +let interpolate = (fraction:number):number => { + return Math.sqrt(fraction) +} let curve = Curves.customCurve(interpolate) // 创建一个用户自定义插值曲线 ``` diff --git a/zh-cn/application-dev/reference/apis/js-apis-font.md b/zh-cn/application-dev/reference/apis/js-apis-font.md index d1ae820a17..ff5d03fda1 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-font.md +++ b/zh-cn/application-dev/reference/apis/js-apis-font.md @@ -104,7 +104,7 @@ import font from '@ohos.font'; @Entry @Component struct FontExample { - fontList: Array; + fontList: Array = new Array(); build() { Column() { Button("getSystemFontList") @@ -164,8 +164,8 @@ import font from '@ohos.font'; @Entry @Component struct FontExample { - fontList: Array; - fontInfo: font.FontInfo; + fontList: Array = new Array(); + fontInfo: font.FontInfo = font.getFontByName(''); build() { Column() { Button("getFontByName") diff --git a/zh-cn/application-dev/reference/apis/js-apis-matrix4.md b/zh-cn/application-dev/reference/apis/js-apis-matrix4.md index 9cd9ee889e..c10be54904 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-matrix4.md +++ b/zh-cn/application-dev/reference/apis/js-apis-matrix4.md @@ -561,9 +561,9 @@ import matrix4 from '@ohos.matrix4' @Entry @Component struct Test { - private originPoint: [number, number] = [50, 50] + private originPoint: number[] = [50, 50] private matrix_1 = matrix4.identity().translate({ x: 150, y: -50 }) - private transformPoint = this.matrix_1.transformPoint(this.originPoint) + private transformPoint = this.matrix_1.transformPoint([this.originPoint[0], this.originPoint[1]]) private matrix_2 = matrix4.identity().translate({ x: this.transformPoint[0], y: this.transformPoint[1] }) build() { diff --git a/zh-cn/application-dev/reference/apis/js-apis-mediaquery.md b/zh-cn/application-dev/reference/apis/js-apis-mediaquery.md index 5277999966..d6e81af5da 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-mediaquery.md +++ b/zh-cn/application-dev/reference/apis/js-apis-mediaquery.md @@ -30,14 +30,14 @@ matchMediaSync(condition: string): MediaQueryListener **参数:** -| 参数名 | 类型 | 必填 | 说明 | -| --------- | ------ | ---- | ---------------------------------------- | -| condition | string | 是 | 媒体事件的匹配条件,具体可参考[媒体查询语法规则](../../ui/arkts-layout-development-media-query.md#语法规则)。 | +| 参数名 | 类型 | 必填 | 说明 | +| --------- | ------ | ---- | ------------------------------------------------------------ | +| condition | string | 是 | 媒体事件的匹配条件,具体可参考[媒体查询语法规则](../../ui/arkts-layout-development-media-query.md#语法规则)。 | **返回值:** -| 类型 | 说明 | -| ------------------ | ---------------------- | +| 类型 | 说明 | +| ------------------ | -------------------------------------------- | | MediaQueryListener | 媒体事件监听句柄,用于注册和去注册监听回调。 | **示例:** @@ -71,10 +71,10 @@ on(type: 'change', callback: Callback<MediaQueryResult>): void **参数:** -| 参数名 | 类型 | 必填 | 说明 | -| -------- | -------------------------------- | ---- | ---------------- | -| type | string | 是 | 必须填写字符串'change'。 | -| callback | Callback<MediaQueryResult> | 是 | 向媒体查询注册的回调 | +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------------------------------- | ---- | ------------------------ | +| type | string | 是 | 必须填写字符串'change'。 | +| callback | Callback<MediaQueryResult> | 是 | 向媒体查询注册的回调 | **示例:** @@ -102,7 +102,7 @@ off(type: 'change', callback?: Callback<MediaQueryResult>): void import mediaquery from '@ohos.mediaquery' let listener = mediaquery.matchMediaSync('(orientation: landscape)'); //监听横屏事件 - function onPortrait(mediaQueryResult) { + function onPortrait(mediaQueryResult:mediaquery.MediaQueryResult) { if (mediaQueryResult.matches) { // do something here } else { @@ -141,7 +141,7 @@ struct MediaQueryExample { @State text: string = 'Portrait' listener = mediaquery.matchMediaSync('(orientation: landscape)') - onPortrait(mediaQueryResult) { + onPortrait(mediaQueryResult:mediaquery.MediaQueryResult) { if (mediaQueryResult.matches) { this.color = '#FFD700' this.text = 'Landscape' @@ -152,7 +152,7 @@ struct MediaQueryExample { } aboutToAppear() { - let portraitFunc = this.onPortrait.bind(this) // bind current js instance + let portraitFunc = (mediaQueryResult:mediaquery.MediaQueryResult):void=>this.onPortrait(mediaQueryResult) // bind current js instance this.listener.on('change', portraitFunc) } diff --git a/zh-cn/application-dev/reference/apis/js-apis-system-mediaquery.md b/zh-cn/application-dev/reference/apis/js-apis-system-mediaquery.md index 7a17fd7c56..b1ca158ad7 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-system-mediaquery.md +++ b/zh-cn/application-dev/reference/apis/js-apis-system-mediaquery.md @@ -98,7 +98,10 @@ addListener(callback: (event: MediaQueryEvent) => void): void **示例:** ```ts -function maxWidthMatch(e){ +import mediaquery, { MediaQueryEvent } from '@system.mediaquery'; +let mMediaQueryList = mediaquery.matchMedia('(max-width: 466)'); + +function maxWidthMatch(e: MediaQueryEvent): void { if(e.matches){ // do something } @@ -124,13 +127,13 @@ removeListener(callback: (event: MediaQueryEvent) => void): void **示例:** ```ts -function maxWidthMatch(e){ +import mediaquery, { MediaQueryEvent } from '@system.mediaquery'; +let mMediaQueryList = mediaquery.matchMedia('(max-width: 466)'); + +function maxWidthMatch(e: MediaQueryEvent): void { if(e.matches){ // do something } } mMediaQueryList.removeListener(maxWidthMatch); -``` - - - +``` \ No newline at end of file -- GitLab