diff --git a/en/application-dev/faqs/Readme-EN.md b/en/application-dev/faqs/Readme-EN.md index b9bde5d6ebd9c35e203d4f08ccb0e551c9eb6ad1..b7ff0dc957de51621a24016d127d8aca585676d5 100644 --- a/en/application-dev/faqs/Readme-EN.md +++ b/en/application-dev/faqs/Readme-EN.md @@ -1,6 +1,8 @@ # FAQs - [Ability Development](faqs-ability.md) +- [ArkUI Development](faqs-arkui.md) +- [Web Development](faqs-arkui-web.md) - [Bundle Management Development](faqs-bundle-management.md) - [Resource Manager Development](faqs-globalization.md) - [Common Event and Notification Development](faqs-event-notification.md) @@ -16,4 +18,5 @@ - [Pan-Sensor Development](faqs-sensor.md) - [Startup Development](faqs-startup.md) - [Distributed Device Development](faqs-distributed-device-profile.md) +- [SDK Usage](faqs-sdk.md) - [Usage of Third- and Fourth-Party Libraries](faqs-third-fourth-party-library.md) diff --git a/en/application-dev/faqs/faqs-arkui-web.md b/en/application-dev/faqs/faqs-arkui-web.md new file mode 100644 index 0000000000000000000000000000000000000000..074a13ac37392b4404876149e582948e84f2464e --- /dev/null +++ b/en/application-dev/faqs/faqs-arkui-web.md @@ -0,0 +1,175 @@ +# Web Development + +## How does the return result of onUrlLoadIntercept affect onInterceptRequest in the \ component? + +Applicable to: OpenHarmony 3.2 Beta 5 (API version 9) + +**Solution** + +The operation that follows **onUrlLoadIntercept** is subject to its return result. + +- If **true** is returned, the URL request is intercepted. +- If **false** is returned , the **onInterceptRequest** callback is performed. + +**Reference** + +[onUrlloadIntercept](../reference/arkui-ts/ts-basic-components-web.md#onurlloadinterceptdeprecated) + +## What should I do if the onKeyEvent event of the \ component is not triggered as expected? + +Applicable to: OpenHarmony 3.2 Beta 5 (API version 9) + +**Problem** + +The **onKeyEvent** event is set for the **\** component to listen for keyboard events. However, it is not triggered when a key is pressed or lifted. + +**Solution** + +Currently, the **\** component does not support the **onKeyEvent** event. To listen for keyboard events for the **\** component, you can use the **onInterceptKeyEvent** callback function. + +**Reference** + +[onInterceptKeyEvent](../reference/arkui-ts/ts-basic-components-web.md#oninterceptkeyevent9) + +## What should I do if page loading fails when onInterceptRequest is used to intercept URLs and return the custom HTML file? + +Applicable to: OpenHarmony 3.2 Beta 5 (API version 9) + +**Problem** + +The **onInterceptRequest** API intercepts URLs specified by **src** and returns the custom HTML file. However, the content in the **script** tag in the HTML file is not loaded. + +**Solution** + +If only **setResponseData** is set for the interceptor, the kernel cannot identify the HTML file. You must also set parameters such as **setResponseEncoding**, **setResponseMimeType**, and **setResponseHeader** for the kernel to identify the HTML file. + +**Example** + +``` +Web({ src: 'www.example.com', controller: this.controller }) + .onInterceptRequest((event) => { + console.log('url:' + event.request.getRequestUrl()) + this.responseweb = new WebResourceResponse(); + var head1:Header = { + headerKey:"Connection", + headerValue:"keep-alive" + } + var length = this.heads.push(head1) + this.responseweb.setResponseHeader(this.heads) + this.responseweb.setResponseData(this.webdata) + this.responseweb.setResponseEncoding('utf-8') + this.responseweb.setResponseMimeType('text/html') + this.responseweb.setResponseCode(200) + this.responseweb.setReasonMessage('OK') + return this.responseweb +}) +``` + +**Reference** + +[WebResourceResponse](../reference/arkui-ts/ts-basic-components-web.md#webresourceresponse) + +## How do I execute JS functions in HTML in ArkTS code? + +Applicable to: OpenHarmony 3.2 Beta 5 (API version 9) + +**Solution** + +Use the **runJavaScript** API in **WebviewController** to asynchronously execute JavaScript scripts and obtain the execution result in a callback. + +>**NOTE** +> +>**runJavaScript** can be invoked only after l**oadUrl** is executed. For example, it can be invoked in **onPageEnd**. + +**Reference** + +[runJavaScript](../reference/apis/js-apis-webview.md#runjavascript) + +## How do I invoke an ArkTS method on a local web page loaded in the \ component? + +Applicable to: OpenHarmony 3.2 Beta 5 (API version 9) + +**Solution** + +1. Prepare an HTML file. Below is the sample code: + + ``` + + + + + + + Document + + +

Title

+
+
+ + + + + ``` + +2. Use the **JavaScriptProxy** API in ArkTs to register the object in ArkTS with the window object of H5, and then use the window object to call the method in H5. In the following example, the **testObj** object in ArkTS is registered with the window object of H5 with the alias **objName**. In H5, **window.objName** can then be used to access the object. + + ``` + // xxx.ets + import web_webview from '@ohos.web.webview' + @Entry + @Component + struct Index { + @State message: string = 'Hello World' + controller: web_webview.WebviewController = new web_webview.WebviewController() + testObj = { + test: (data1, data2, data3) => { + console.log("data1:" + data1); + console.log("data2:" + data2); + console.log("data3:" + data3); + return "AceString"; + }, + toString: () => { + console.log('toString' + "interface instead."); + } + } + build() { + Row() { + Column() { + Web({ src:$rawfile('index.html'), controller:this.controller }) + .javaScriptAccess(true) + .javaScriptProxy({ + object: this.testObj, + name: "objName", + methodList: ["test", "toString"], + controller: this.controller, + }) + } + .width('100%') + } + .height('100%') + } + } + ``` + + +**Reference** + +[javaScriptProxy](../reference/arkui-ts/ts-basic-components-web.md#javascriptproxy) + +## How do I set the domStorageAccess attribute of the \ component? + +Applicable to: OpenHarmony 3.2 Beta 5 (API version 9) + +**Solution** + +The **domStorageAccess** attribute sets whether to enable the DOM Storage API. By default, this feature is disabled. + +**Reference** + +[domStorageAccess](../reference/arkui-ts/ts-basic-components-web.md#domstorageaccess) diff --git a/en/application-dev/faqs/faqs-arkui.md b/en/application-dev/faqs/faqs-arkui.md new file mode 100644 index 0000000000000000000000000000000000000000..0cce1a7add01d15e8bb6dcb1aa11e6c0ce5c2ab8 --- /dev/null +++ b/en/application-dev/faqs/faqs-arkui.md @@ -0,0 +1,1416 @@ +# ArkUI Development + +## How do I dynamically replace the %s placeholder in a resource file? + +Applicable to: OpenHarmony 3.2 Beta 5 (API version 9) + +**Symptom** + +How do I dynamically replace the %s placeholder in a resource file? + +**Solution** + +In an application, you can replace the **%s** placeholder by using the second parameter in **$r('app.string.xx')**, which is used to reference application resources. + +**Example** + +``` +build() { + //do something + // The second parameter indicates the referenced string resource, which can be used to replace the %s placeholder. + Text($r('app.string.entry_desc','aaa')) + .fontSize(100) + .fontColor(Color.Black) + //do something +} +``` + +## Can custom dialog boxes be defined or used in .ts files? + +Applicable to: OpenHarmony 3.2 Beta5 (API version 9, stage model) + +Unfortunately, no. ArkTS syntax is required for defining and initializing custom dialog boxes. Therefore, they can be defined and used only in .ets files. + +**Reference** + +[Custom Dialog Box](../reference/arkui-ts/ts-methods-custom-dialog-box.md) + +## How do I transfer variables in a custom dialog box to a page? + +Applicable to: OpenHarmony 3.2 Beta5 (API version 9, stage model) + +**Symptom** + +The variable defined in a custom dialog box needs to be transferred to the page when the dialog box is closed or the variable changes. + +**Solution** + +- Method 1: Define the variable as a state variable of the custom dialog box. +- Method 2: During initialization of the custom dialog box, pass to it a method, which is triggered in the custom dialog box and accepts the variable in the custom dialog box as a parameter. +- Method 3: Use AppStorage or LocalStorage to manage page state and implement state sharing between the custom dialog box and page. + +**Example** + +- Method 1: + + ``` + @CustomDialog + struct CustomDialog01 { + @Link inputValue: string + controller: CustomDialogController + build() { + Column() { + Text('Change text').fontSize(20).margin({ top: 10, bottom: 10 }) + TextInput({ placeholder: '', text: this.inputValue }).height(60).width('90%') + .onChange((value: string) => { + this.inputValue = value + }) + } + } + } + + @Entry + @Component + struct DialogDemo01 { + @State inputValue: string = 'click me' + dialogController: CustomDialogController = new CustomDialogController({ + builder: CustomDialog01({ + inputValue: $inputValue + }) + }) + + build() { + Column() { + Button(this.inputValue) + .onClick(() => { + this.dialogController.open() + }).backgroundColor(0x317aff) + }.width('100%').margin({ top: 5 }) + } + } + + ``` + +- Method 2: + + ``` + @CustomDialog + struct CustomDialog02 { + private inputValue: string + changeInputValue: (val: string) => void + controller: CustomDialogController + build() { + Column() { + Text('Change text').fontSize(20).margin({ top: 10, bottom: 10 }) + TextInput({ placeholder: '', text: this.inputValue }).height(60).width('90%') + .onChange((value: string) => { + this.changeInputValue(value) + }) + } + } + } + + @Entry + @Component + struct DialogDemo02 { + @State inputValue: string = 'click me' + dialogController: CustomDialogController = new CustomDialogController({ + builder: CustomDialog02({ + inputValue: this.inputValue, + changeInputValue: (val: string) => { + this.inputValue = val + } + }) + }) + + build() { + Column() { + Button(this.inputValue) + .onClick(() => { + this.dialogController.open() + }).backgroundColor(0x317aff) + }.width('100%').margin({ top: 5 }) + } + } + + ``` + +- Method 3: + + ``` + let storage = LocalStorage.GetShared() + @CustomDialog + struct CustomDialog03 { + @LocalStorageLink('inputVal') inputValue: string = '' + controller: CustomDialogController + build() { + Column() { + Text('Change text').fontSize(20).margin({ top: 10, bottom: 10 }) + TextInput({ placeholder: '', text: this.inputValue }).height(60).width('90%') + .onChange((value: string) => { + this.inputValue = value; + }) + } + } + } + + @Entry(storage) + @Component + struct DialogDemo03 { + @LocalStorageLink('inputVal') inputValue: string = '' + dialogController: CustomDialogController = new CustomDialogController({ + builder: CustomDialog03() + }) + + build() { + Column() { + Button(this.inputValue) + .onClick(() => { + this.dialogController.open() + }).backgroundColor(0x317aff) + }.width('100%').margin({ top: 5 }) + } + } + + ``` + + +## How do I obtain the width and height of a component? + +Applicable to: OpenHarmony 3.2 Beta5 (API version 9, stage model) + +**Symptom** + +The width and height of a component need to be obtained to calculate the size and offset of the layout area. + +**Solution** + +- Method 1: Use the **onAreaChange** event of the component, which is triggered when the component is initialized or the component size changes. +- Manner 2: Use the callback in the click or touch event, which provides the area information of the target element. + +**Reference** + +[Component Area Change Event](../reference/arkui-ts/ts-universal-component-area-change-event.md), [Click Event](../reference/arkui-ts/ts-universal-events-click.md), [Touch Event](../reference/arkui-ts/ts-universal-events-touch.md) + +## How do I clear the content of the \ and \