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_create_function'; 24 25@Entry 26@Component 27struct napiCreateFunction { 28 private btnFontColor: Resource = $r('app.color.white'); 29 private pixelMapFormat: image.PixelMapFormat = 3; 30 @State isSetInstance: Boolean = false; 31 @State imagePixelMap: PixelMap | undefined = undefined; 32 @State textcont: string = 'napi_create_function允许插件作者以原生代码创建函数对象。' 33 + '这是允许从 JavaScript 调用加载项的原生代码的主要机制。'; 34 @State testcont: string = ' // 测试 N-API napi_create_function \n' 35 + ' const result = testNapi.testNapiCreateFunction(); \n' 36 + ' console.log(result); \n' 37 38 39 controller: TextAreaController = new TextAreaController() 40 41 build() { 42 Column() { 43 // 标题 44 TitleBar({ title: $r('app.string.napi_create_function') }) 45 46 Column() { 47 Column() { 48 TextArea({ 49 text: this.textcont, 50 placeholder: '', 51 }) 52 .placeholderFont({ size: 16, weight: 400 }) 53 .width('90%') 54 .margin(10) 55 .fontSize(16) 56 .fontColor($r('app.color.sub_title_color')) 57 .backgroundColor($r('app.color.white')) 58 .enabled(false) 59 60 TextArea({ 61 text: this.testcont, 62 placeholder: '', 63 }) 64 .placeholderFont({ size: 16, weight: 400 }) 65 .width('90%') 66 .margin(10) 67 .fontSize(16) 68 .fontColor($r('app.color.textarea_font_color')) 69 .backgroundColor($r('app.color.white')) 70 .enabled(false) 71 } 72 .width('100%') 73 .alignItems(HorizontalAlign.Center) 74 .justifyContent(FlexAlign.Start) 75 76 Row() { 77 78 Button($r('app.string.napi_create_function'), { type: ButtonType.Capsule }) 79 .backgroundColor(Color.Blue) 80 .width('80%') 81 .height(48) 82 .fontSize(16) 83 .fontWeight(500) 84 .fontColor(this.btnFontColor) 85 .margin({ left: 24 }) 86 .id('napi_create_function') 87 .onClick(() => { 88 console.log(`result is ${testNapi.testNapiCreateFunction()}`); 89 this.testcont = this.testcont.replace('log(result)', 'log(## typeof result is ' + typeof (testNapi.testNapiCreateFunction()) + ' ##)'); 90 }) 91 } 92 .width('100%') 93 .height(48) 94 .alignItems(VerticalAlign.Center) 95 .justifyContent(FlexAlign.SpaceBetween) 96 } 97 .width('100%') 98 } 99 .height('100%') 100 .width('100%') 101 .backgroundColor($r('app.color.background_shallow_grey')) 102 } 103}