• 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_has_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_has_element_description');
31  @State isSetInstance: Boolean = false;
32  @State imagePixelMap: PixelMap | undefined = undefined;
33  @State testcont: string = ' // 测试 N-API napi_has_element \n'
34    + ' let obj = [0, false, "zz"]; \n'
35    + ' const myData = testNapi.testNapiHasElement(obj, 2); \n'
36    + ' console.log(myData); // 输出自定义数据 \n'
37    + ' const myData2 = testNapi.testNapiHasElement(obj, 4); \n'
38    + ' console.log(myData2); // 输出自定义数据 \n';
39
40  controller: TextAreaController = new TextAreaController()
41
42  build() {
43    Column() {
44      // 标题
45      TitleBar({ title: $r('app.string.napi_has_element') })
46
47      Column() {
48        Column() {
49          TextArea({
50            text: this.textcont,
51            placeholder: '',
52          })
53            .placeholderFont({ size: 16, weight: 400 })
54            .width('90%')
55            .margin(10)
56            .fontSize(16)
57            .fontColor($r('app.color.sub_title_color'))
58            .backgroundColor($r('app.color.white'))
59            .enabled(false)
60
61          TextArea({
62            text: this.testcont,
63            placeholder: '',
64          })
65            .placeholderFont({ size: 16, weight: 400 })
66            .width('90%')
67            .margin(10)
68            .fontSize(16)
69            .fontColor($r('app.color.textarea_font_color'))
70            .backgroundColor($r('app.color.textarea_background_color'))
71            .enabled(false)
72        }
73        .width('100%')
74        .alignItems(HorizontalAlign.Center)
75        .justifyContent(FlexAlign.Start)
76
77        Row() {
78
79          Button($r('app.string.napi_has_element'), { type: ButtonType.Capsule })
80            .backgroundColor(Color.Blue)
81            .width('80%')
82            .height(48)
83            .fontSize(16)
84            .fontWeight(500)
85            .fontColor(this.btnFontColor)
86            .margin({ left: 24 })
87            .id('napi_has_element')
88            .onClick(() => {
89              let obj = [0, false, "zz"];
90              let ret = testNapi.testNapiHasElement(obj, 2);
91              this.testcont = this.testcont.replace('log(myData)', 'log(## '+JSON.stringify(ret)+' ##)');
92              let ret2 = testNapi.testNapiHasElement(obj, 4);
93              this.testcont = this.testcont.replace('log(myData2)', 'log(## '+JSON.stringify(ret2)+' ##)');
94            })
95        }
96        .width('100%')
97        .height(48)
98        .alignItems(VerticalAlign.Center)
99        .justifyContent(FlexAlign.SpaceBetween)
100      }
101      .width('100%')
102    }
103    .height('100%')
104    .width('100%')
105    .backgroundColor($r('app.color.background_shallow_grey'))
106  }
107}
108