• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16import router from '@ohos.router';
17import image from '@ohos.multimedia.image';
18import Logger from '../../../util/Logger';
19import testNapi, { testNapiValue } from 'libentry.so';
20import { TitleBar } from '../../../common/TitleBar'
21import hilog from '@ohos.hilog';
22
23const TAG: string = 'napi_set_element';
24
25@Entry
26@Component
27struct napiGetPropertyNames {
28  private btnFontColor: Resource = $r('app.color.white');
29  private pixelMapFormat: image.PixelMapFormat = 3;
30  private textcont: Resource = $r('app.string.napi_set_element_description');
31  @State isSetInstance: Boolean = false;
32  @State imagePixelMap: PixelMap | undefined = undefined;
33  @State testcont: string = ' // 测试 N-API napi_set_element \n'
34    + ' let obj1 = [1,2,3]; \n'
35    + ' const myData1 = testNapi.testNapiSetElement(obj1, 1, 5); \n'
36    + ' console.log(myData1); // 输出自定义数据 \n'
37    + ' let obj2 = ["a", "b", "c"]'
38    + ' const myData2 = testNapi.testNapiSetElement(obj2, 4, "d"); \n'
39    + ' console.log(myData2); // 输出自定义数据 \n'
40    + ' let obj3 = [true, false]; \n'
41    + ' const myData3 = testNapi.testNapiSetElement(obj3, 2, true); \n'
42    + ' console.log(myData3); // 输出自定义数据 \n'
43    + ' let obj4 = [0, false, "zz"]; \n'
44    + ' const myData4 = testNapi.testNapiSetElement(obj4, 1, "kk"); \n'
45    + ' console.log(myData4); // 输出自定义数据 \n'
46
47  controller: TextAreaController = new TextAreaController()
48
49  build() {
50    Column() {
51      // 标题
52      TitleBar({ title: $r('app.string.napi_set_element') })
53
54      Column() {
55        Column() {
56          TextArea({
57            text: this.textcont,
58            placeholder: '',
59          })
60            .placeholderFont({ size: 16, weight: 400 })
61            .width('90%')
62            .margin(10)
63            .fontSize(16)
64            .fontColor($r('app.color.sub_title_color'))
65            .backgroundColor($r('app.color.white'))
66            .enabled(false)
67
68          TextArea({
69            text: this.testcont,
70            placeholder: '',
71          })
72            .placeholderFont({ size: 16, weight: 400 })
73            .width('90%')
74            .margin(10)
75            .fontSize(16)
76            .fontColor($r('app.color.textarea_font_color'))
77            .backgroundColor($r('app.color.textarea_background_color'))
78            .enabled(false)
79        }
80        .width('100%')
81        .alignItems(HorizontalAlign.Center)
82        .justifyContent(FlexAlign.Start)
83
84        Row() {
85
86          Button($r('app.string.napi_set_element'), { type: ButtonType.Capsule })
87            .backgroundColor(Color.Blue)
88            .width('80%')
89            .height(48)
90            .fontSize(16)
91            .fontWeight(500)
92            .fontColor(this.btnFontColor)
93            .margin({ left: 24 })
94            .id('napi_set_element')
95            .onClick(() => {
96              let obj1 = [1,2,3];
97              let ret = testNapi.testNapiSetElement(obj1, 1, 5);
98              this.testcont = this.testcont.replace('log(myData1)', 'log(## '+JSON.stringify(ret)+' ##)');
99              let obj2 = ["a", "b", "c"];
100              let ret2 = testNapi.testNapiSetElement(obj2, 4, "d");
101              this.testcont = this.testcont.replace('log(myData2)', 'log(## '+JSON.stringify(ret2)+' ##)');
102              let obj3 = [true, false];
103              let ret3 = testNapi.testNapiSetElement(obj3, 2, true);
104              this.testcont = this.testcont.replace('log(myData3)', 'log(## '+JSON.stringify(ret3)+' ##)');
105              let obj4 = [0, false, "zz"];
106              let ret4 = testNapi.testNapiSetElement(obj4, 1, "kk");
107              this.testcont = this.testcont.replace('log(myData4)', 'log(## '+JSON.stringify(ret4)+' ##)');
108
109            })
110        }
111        .width('100%')
112        .height(48)
113        .alignItems(VerticalAlign.Center)
114        .justifyContent(FlexAlign.SpaceBetween)
115      }
116      .width('100%')
117    }
118    .height('100%')
119    .width('100%')
120    .backgroundColor($r('app.color.background_shallow_grey'))
121  }
122}
123