提交 2ff592df 编写于 作者: S sqsyqqy

ArkTS适配

Signed-off-by: Nsqsyqqy <sunqi57@huawei.com>
上级 b5e8941b
...@@ -100,11 +100,9 @@ struct Index { ...@@ -100,11 +100,9 @@ struct Index {
// 运算任务异步处理 // 运算任务异步处理
private computeTaskAsync() { private computeTaskAsync() {
new Promise((resolved, rejected) => { setTimeout(() => { // 这里使用setTimeout来实现异步延迟运行
setTimeout(() => { // 这里使用setTimeout来实现异步延迟运行 this.computeTask();
this.computeTask(); }, 1000)
}, 1000)
})
} }
} }
``` ```
\ No newline at end of file
...@@ -40,7 +40,7 @@ struct ImageExample1 { ...@@ -40,7 +40,7 @@ struct ImageExample1 {
```typescript ```typescript
@Entry @Entry
@Component @Component
struct ImageExample1 { struct ImageExample2 {
build() { build() {
Column() { Column() {
Row() { Row() {
...@@ -78,7 +78,7 @@ function computeTask(arr: string[]): string[] { ...@@ -78,7 +78,7 @@ function computeTask(arr: string[]): string[] {
@Entry @Entry
@Component @Component
struct AspectRatioExample { struct AspectRatioExample3 {
@State children: string[] = ['1', '2', '3', '4', '5', '6']; @State children: string[] = ['1', '2', '3', '4', '5', '6'];
aboutToAppear() { aboutToAppear() {
...@@ -88,8 +88,7 @@ struct AspectRatioExample { ...@@ -88,8 +88,7 @@ struct AspectRatioExample {
async computeTaskInTaskPool() { async computeTaskInTaskPool() {
const param = this.children.slice(); const param = this.children.slice();
let task = new taskpool.Task(computeTask, param); let task = new taskpool.Task(computeTask, param);
// @ts-ignore await taskpool.execute(task);
this.children = await taskpool.execute(task);
} }
build() { build() {
...@@ -105,7 +104,7 @@ struct AspectRatioExample { ...@@ -105,7 +104,7 @@ struct AspectRatioExample {
```typescript ```typescript
@Entry @Entry
@Component @Component
struct AspectRatioExample { struct AspectRatioExample4 {
@State private children: string[] = ['1', '2', '3', '4', '5', '6']; @State private children: string[] = ['1', '2', '3', '4', '5', '6'];
private count: number = 0; private count: number = 0;
...@@ -123,11 +122,9 @@ struct AspectRatioExample { ...@@ -123,11 +122,9 @@ struct AspectRatioExample {
} }
computeTaskAsync() { computeTaskAsync() {
new Promise((resolved, rejected) => { setTimeout(() => { // 这里使用setTimeout来实现异步延迟运行
setTimeout(() => { // 这里使用setTimeout来实现异步延迟运行 this.computeTask();
this.computeTask(); }, 1000)
}, 1000)
})
} }
build() { build() {
...@@ -149,7 +146,7 @@ struct AspectRatioExample { ...@@ -149,7 +146,7 @@ struct AspectRatioExample {
```typescript ```typescript
@Entry @Entry
@Component @Component
struct StackExample { struct StackExample5 {
@State isVisible : boolean = false; @State isVisible : boolean = false;
build() { build() {
...@@ -178,7 +175,7 @@ struct StackExample { ...@@ -178,7 +175,7 @@ struct StackExample {
```typescript ```typescript
@Entry @Entry
@Component @Component
struct StackExample { struct StackExample6 {
@State isVisible : boolean = false; @State isVisible : boolean = false;
build() { build() {
...@@ -211,8 +208,8 @@ struct StackExample { ...@@ -211,8 +208,8 @@ struct StackExample {
```typescript ```typescript
@Entry @Entry
@Component @Component
struct MyComponent { struct MyComponent7 {
@State arr: number[] = Array.from(Array(10000), (v,k) =>k); @State arr: number[] = Array.from(Array<number>(10000), (v,k) =>k);
build() { build() {
List() { List() {
ForEach(this.arr, (item: number) => { ForEach(this.arr, (item: number) => {
...@@ -235,8 +232,8 @@ class BasicDataSource implements IDataSource { ...@@ -235,8 +232,8 @@ class BasicDataSource implements IDataSource {
return 0 return 0
} }
public getData(index: number): any { public getData(index: number): string {
return undefined return ''
} }
registerDataChangeListener(listener: DataChangeListener): void { registerDataChangeListener(listener: DataChangeListener): void {
...@@ -286,13 +283,13 @@ class BasicDataSource implements IDataSource { ...@@ -286,13 +283,13 @@ class BasicDataSource implements IDataSource {
} }
class MyDataSource extends BasicDataSource { class MyDataSource extends BasicDataSource {
private dataArray: string[] = Array.from(Array(10000), (v, k) => k.toString()); private dataArray: string[] = Array.from(Array<number>(10000), (v, k) => k.toString());
public totalCount(): number { public totalCount(): number {
return this.dataArray.length return this.dataArray.length
} }
public getData(index: number): any { public getData(index: number): string {
return this.dataArray[index] return this.dataArray[index]
} }
...@@ -318,7 +315,7 @@ struct MyComponent { ...@@ -318,7 +315,7 @@ struct MyComponent {
ListItem() { ListItem() {
Text(item).fontSize(20).margin({ left: 10 }) Text(item).fontSize(20).margin({ left: 10 })
} }
}, item => item) }, (item:string) => item)
} }
} }
} }
......
...@@ -9,13 +9,13 @@ ...@@ -9,13 +9,13 @@
```typescript ```typescript
@Entry @Entry
@Component @Component
struct AspectRatioExample { struct AspectRatioExample12 {
@State children: Number[] = Array.from(Array(900), (v, k) => k); @State children: Number[] = Array.from(Array<number>(900), (v, k) => k);
build() { build() {
Scroll() { Scroll() {
Grid() { Grid() {
ForEach(this.children, (item) => { ForEach(this.children, (item:Number[]) => {
GridItem() { GridItem() {
Stack() { Stack() {
Stack() { Stack() {
...@@ -25,7 +25,7 @@ struct AspectRatioExample { ...@@ -25,7 +25,7 @@ struct AspectRatioExample {
} }
} }
} }
}, item => item) }, (item:string) => item)
} }
.columnsTemplate('1fr 1fr 1fr 1fr') .columnsTemplate('1fr 1fr 1fr 1fr')
.columnsGap(0) .columnsGap(0)
...@@ -41,17 +41,17 @@ struct AspectRatioExample { ...@@ -41,17 +41,17 @@ struct AspectRatioExample {
```typescript ```typescript
@Entry @Entry
@Component @Component
struct AspectRatioExample { struct AspectRatioExample11 {
@State children: Number[] = Array.from(Array(900), (v, k) => k); @State children: Number[] = Array.from(Array(900), (v, k) => k);
build() { build() {
Scroll() { Scroll() {
Grid() { Grid() {
ForEach(this.children, (item) => { ForEach(this.children, (item:Number[]) => {
GridItem() { GridItem() {
Text(item.toString()) Text(item.toString())
} }
}, item => item) }, (item:string) => item)
} }
.columnsTemplate('1fr 1fr 1fr 1fr') .columnsTemplate('1fr 1fr 1fr 1fr')
.columnsGap(0) .columnsGap(0)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册