未验证 提交 1344bf60 编写于 作者: O openharmony_ci 提交者: Gitee

!23197 apis下示例代码修改

Merge pull request !23197 from 椎名真昼/master
...@@ -279,9 +279,9 @@ customCurve(interpolate: (fraction: number) => number): ICurve ...@@ -279,9 +279,9 @@ customCurve(interpolate: (fraction: number) => number): ICurve
```ts ```ts
import Curves from '@ohos.curves' import Curves from '@ohos.curves'
let interpolate = function(fraction) { let interpolate = (fraction:number):number => {
return Math.sqrt(fraction) return Math.sqrt(fraction)
} }
let curve = Curves.customCurve(interpolate) // 创建一个用户自定义插值曲线 let curve = Curves.customCurve(interpolate) // 创建一个用户自定义插值曲线
``` ```
......
...@@ -104,7 +104,7 @@ import font from '@ohos.font'; ...@@ -104,7 +104,7 @@ import font from '@ohos.font';
@Entry @Entry
@Component @Component
struct FontExample { struct FontExample {
fontList: Array<string>; fontList: Array<string> = new Array<string>();
build() { build() {
Column() { Column() {
Button("getSystemFontList") Button("getSystemFontList")
...@@ -164,8 +164,8 @@ import font from '@ohos.font'; ...@@ -164,8 +164,8 @@ import font from '@ohos.font';
@Entry @Entry
@Component @Component
struct FontExample { struct FontExample {
fontList: Array<string>; fontList: Array<string> = new Array<string>();
fontInfo: font.FontInfo; fontInfo: font.FontInfo = font.getFontByName('');
build() { build() {
Column() { Column() {
Button("getFontByName") Button("getFontByName")
......
...@@ -561,9 +561,9 @@ import matrix4 from '@ohos.matrix4' ...@@ -561,9 +561,9 @@ import matrix4 from '@ohos.matrix4'
@Entry @Entry
@Component @Component
struct Test { struct Test {
private originPoint: [number, number] = [50, 50] private originPoint: number[] = [50, 50]
private matrix_1 = matrix4.identity().translate({ x: 150, y: -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] }) private matrix_2 = matrix4.identity().translate({ x: this.transformPoint[0], y: this.transformPoint[1] })
build() { build() {
......
...@@ -30,14 +30,14 @@ matchMediaSync(condition: string): MediaQueryListener ...@@ -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 | 媒体事件监听句柄,用于注册和去注册监听回调。 | | MediaQueryListener | 媒体事件监听句柄,用于注册和去注册监听回调。 |
**示例:** **示例:**
...@@ -71,10 +71,10 @@ on(type: 'change', callback: Callback&lt;MediaQueryResult&gt;): void ...@@ -71,10 +71,10 @@ on(type: 'change', callback: Callback&lt;MediaQueryResult&gt;): void
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------------------------------- | ---- | ---------------- | | -------- | -------------------------------- | ---- | ------------------------ |
| type | string | 是 | 必须填写字符串'change'。 | | type | string | 是 | 必须填写字符串'change'。 |
| callback | Callback&lt;MediaQueryResult&gt; | 是 | 向媒体查询注册的回调 | | callback | Callback&lt;MediaQueryResult&gt; | 是 | 向媒体查询注册的回调 |
**示例:** **示例:**
...@@ -102,7 +102,7 @@ off(type: 'change', callback?: Callback&lt;MediaQueryResult&gt;): void ...@@ -102,7 +102,7 @@ off(type: 'change', callback?: Callback&lt;MediaQueryResult&gt;): void
import mediaquery from '@ohos.mediaquery' import mediaquery from '@ohos.mediaquery'
let listener = mediaquery.matchMediaSync('(orientation: landscape)'); //监听横屏事件 let listener = mediaquery.matchMediaSync('(orientation: landscape)'); //监听横屏事件
function onPortrait(mediaQueryResult) { function onPortrait(mediaQueryResult:mediaquery.MediaQueryResult) {
if (mediaQueryResult.matches) { if (mediaQueryResult.matches) {
// do something here // do something here
} else { } else {
...@@ -141,7 +141,7 @@ struct MediaQueryExample { ...@@ -141,7 +141,7 @@ struct MediaQueryExample {
@State text: string = 'Portrait' @State text: string = 'Portrait'
listener = mediaquery.matchMediaSync('(orientation: landscape)') listener = mediaquery.matchMediaSync('(orientation: landscape)')
onPortrait(mediaQueryResult) { onPortrait(mediaQueryResult:mediaquery.MediaQueryResult) {
if (mediaQueryResult.matches) { if (mediaQueryResult.matches) {
this.color = '#FFD700' this.color = '#FFD700'
this.text = 'Landscape' this.text = 'Landscape'
...@@ -152,7 +152,7 @@ struct MediaQueryExample { ...@@ -152,7 +152,7 @@ struct MediaQueryExample {
} }
aboutToAppear() { 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) this.listener.on('change', portraitFunc)
} }
......
...@@ -98,7 +98,10 @@ addListener(callback: (event: MediaQueryEvent) => void): void ...@@ -98,7 +98,10 @@ addListener(callback: (event: MediaQueryEvent) => void): void
**示例:** **示例:**
```ts ```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){ if(e.matches){
// do something // do something
} }
...@@ -124,13 +127,13 @@ removeListener(callback: (event: MediaQueryEvent) => void): void ...@@ -124,13 +127,13 @@ removeListener(callback: (event: MediaQueryEvent) => void): void
**示例:** **示例:**
```ts ```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){ if(e.matches){
// do something // do something
} }
} }
mMediaQueryList.removeListener(maxWidthMatch); mMediaQueryList.removeListener(maxWidthMatch);
``` ```
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册