提交 021b606d 编写于 作者: L liuliu

arkui-ts

Signed-off-by: Nliuliu <liuliu40@huawei.com>
Change-Id: I1d0fcc2a1771fd115bf22064b1204cd709b0b0e6
上级 10f3cc07
...@@ -86,11 +86,37 @@ Web(options: { src: ResourceStr, controller: WebviewController | WebController}) ...@@ -86,11 +86,37 @@ Web(options: { src: ResourceStr, controller: WebviewController | WebController})
加载沙箱路径下的本地资源文件 加载沙箱路径下的本地资源文件
1.通过[globalthis](../../application-models/uiability-data-sync-with-ui.md#uiability和page之间使用globalthis)获取沙箱路径。 1.通过构造的单例对象GlobalContext获取沙箱路径。
```ts
// GlobalContext.ts
export class GlobalContext {
private constructor() {}
private static instance: GlobalContext;
private _objects = new Map<string, Object>();
public static getContext(): GlobalContext {
if (!GlobalContext.instance) {
GlobalContext.instance = new GlobalContext();
}
return GlobalContext.instance;
}
getObject(value: string): Object | undefined {
return this._objects.get(value);
}
setObject(key: string, objectClass: Object): void {
this._objects.set(key, objectClass);
}
}
```
```ts ```ts
// xxx.ets // xxx.ets
import web_webview from '@ohos.web.webview' import web_webview from '@ohos.web.webview'
let url = 'file://' + globalThis.filesDir + '/index.html' import { GlobalContext } from '../GlobalContext'
let url = 'file://' + GlobalContext.getContext().getObject("filesDir") + '/index.html'
@Entry @Entry
@Component @Component
...@@ -110,13 +136,16 @@ Web(options: { src: ResourceStr, controller: WebviewController | WebController}) ...@@ -110,13 +136,16 @@ Web(options: { src: ResourceStr, controller: WebviewController | WebController})
```ts ```ts
// xxx.ts // xxx.ts
import UIAbility from '@ohos.app.ability.UIAbility'; import UIAbility from '@ohos.app.ability.UIAbility';
import AbilityConstant from '@ohos.app.ability.AbilityConstant';
import Want from '@ohos.app.ability.Want';
import web_webview from '@ohos.web.webview'; import web_webview from '@ohos.web.webview';
import { GlobalContext } from '../GlobalContext'
export default class EntryAbility extends UIAbility { export default class EntryAbility extends UIAbility {
onCreate(want, launchParam) { onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) {
// 通过在globalThis对象上绑定filesDir,可以实现UIAbility组件与UI之间的数据同步。 // 通过在GlobalContext对象上绑定filesDir,可以实现UIAbility组件与UI之间的数据同步。
globalThis.filesDir = this.context.filesDir GlobalContext.getContext().setObject("filesDir", this.context.filesDir);
console.log("Sandbox path is " + globalThis.filesDir) console.log("Sandbox path is " + GlobalContext.getContext().getObject("filesDir"))
} }
} }
``` ```
...@@ -250,21 +279,27 @@ javaScriptProxy(javaScriptProxy: { object: object, name: string, methodList: Arr ...@@ -250,21 +279,27 @@ javaScriptProxy(javaScriptProxy: { object: object, name: string, methodList: Arr
// xxx.ets // xxx.ets
import web_webview from '@ohos.web.webview' import web_webview from '@ohos.web.webview'
@Entry class TestObj {
@Component constructor() {
struct WebComponent { }
controller: web_webview.WebviewController = new web_webview.WebviewController()
testObj = { test(data1: string, data2: string, data3: string): string {
test: (data1, data2, data3) => {
console.log("data1:" + data1) console.log("data1:" + data1)
console.log("data2:" + data2) console.log("data2:" + data2)
console.log("data3:" + data3) console.log("data3:" + data3)
return "AceString" return "AceString"
}, }
toString: () => {
toString(): void {
console.log('toString' + "interface instead.") console.log('toString' + "interface instead.")
} }
} }
@Entry
@Component
struct WebComponent {
controller: web_webview.WebviewController = new web_webview.WebviewController()
testObj = new TestObj();
build() { build() {
Column() { Column() {
Web({ src: 'www.example.com', controller: this.controller }) Web({ src: 'www.example.com', controller: this.controller })
...@@ -1332,8 +1367,8 @@ allowWindowOpenMethod(flag: boolean) ...@@ -1332,8 +1367,8 @@ allowWindowOpenMethod(flag: boolean)
//在同一page页有两个web组件。在WebComponent新开窗口时,会跳转到NewWebViewComp。 //在同一page页有两个web组件。在WebComponent新开窗口时,会跳转到NewWebViewComp。
@CustomDialog @CustomDialog
struct NewWebViewComp { struct NewWebViewComp {
controller: CustomDialogController controller?: CustomDialogController
webviewController1: web_webview.WebviewController webviewController1: web_webview.WebviewController = new web_webview.WebviewController()
build() { build() {
Column() { Column() {
Web({ src: "", controller: this.webviewController1 }) Web({ src: "", controller: this.webviewController1 })
...@@ -1341,7 +1376,9 @@ allowWindowOpenMethod(flag: boolean) ...@@ -1341,7 +1376,9 @@ allowWindowOpenMethod(flag: boolean)
.multiWindowAccess(false) .multiWindowAccess(false)
.onWindowExit(()=> { .onWindowExit(()=> {
console.info("NewWebViewComp onWindowExit") console.info("NewWebViewComp onWindowExit")
if (this.controller) {
this.controller.close() this.controller.close()
}
}) })
} }
} }
...@@ -1351,7 +1388,7 @@ allowWindowOpenMethod(flag: boolean) ...@@ -1351,7 +1388,7 @@ allowWindowOpenMethod(flag: boolean)
@Component @Component
struct WebComponent { struct WebComponent {
controller: web_webview.WebviewController = new web_webview.WebviewController() controller: web_webview.WebviewController = new web_webview.WebviewController()
dialogController: CustomDialogController = null dialogController: CustomDialogController | null = null
build() { build() {
Column() { Column() {
Web({ src: 'www.example.com', controller: this.controller }) Web({ src: 'www.example.com', controller: this.controller })
...@@ -1454,6 +1491,7 @@ onAlert(callback: (event?: { url: string; message: string; result: JsResult }) = ...@@ -1454,6 +1491,7 @@ onAlert(callback: (event?: { url: string; message: string; result: JsResult }) =
Column() { Column() {
Web({ src: $rawfile("index.html"), controller: this.controller }) Web({ src: $rawfile("index.html"), controller: this.controller })
.onAlert((event) => { .onAlert((event) => {
if (event) {
console.log("event.url:" + event.url) console.log("event.url:" + event.url)
console.log("event.message:" + event.message) console.log("event.message:" + event.message)
AlertDialog.show({ AlertDialog.show({
...@@ -1475,6 +1513,7 @@ onAlert(callback: (event?: { url: string; message: string; result: JsResult }) = ...@@ -1475,6 +1513,7 @@ onAlert(callback: (event?: { url: string; message: string; result: JsResult }) =
event.result.handleCancel() event.result.handleCancel()
} }
}) })
}
return true return true
}) })
} }
...@@ -1537,6 +1576,7 @@ onBeforeUnload(callback: (event?: { url: string; message: string; result: JsResu ...@@ -1537,6 +1576,7 @@ onBeforeUnload(callback: (event?: { url: string; message: string; result: JsResu
Column() { Column() {
Web({ src: $rawfile("index.html"), controller: this.controller }) Web({ src: $rawfile("index.html"), controller: this.controller })
.onBeforeUnload((event) => { .onBeforeUnload((event) => {
if (event) {
console.log("event.url:" + event.url) console.log("event.url:" + event.url)
console.log("event.message:" + event.message) console.log("event.message:" + event.message)
AlertDialog.show({ AlertDialog.show({
...@@ -1558,6 +1598,7 @@ onBeforeUnload(callback: (event?: { url: string; message: string; result: JsResu ...@@ -1558,6 +1598,7 @@ onBeforeUnload(callback: (event?: { url: string; message: string; result: JsResu
event.result.handleCancel() event.result.handleCancel()
} }
}) })
}
return true return true
}) })
} }
...@@ -1620,6 +1661,7 @@ onConfirm(callback: (event?: { url: string; message: string; result: JsResult }) ...@@ -1620,6 +1661,7 @@ onConfirm(callback: (event?: { url: string; message: string; result: JsResult })
Column() { Column() {
Web({ src: $rawfile("index.html"), controller: this.controller }) Web({ src: $rawfile("index.html"), controller: this.controller })
.onConfirm((event) => { .onConfirm((event) => {
if (event) {
console.log("event.url:" + event.url) console.log("event.url:" + event.url)
console.log("event.message:" + event.message) console.log("event.message:" + event.message)
AlertDialog.show({ AlertDialog.show({
...@@ -1641,6 +1683,7 @@ onConfirm(callback: (event?: { url: string; message: string; result: JsResult }) ...@@ -1641,6 +1683,7 @@ onConfirm(callback: (event?: { url: string; message: string; result: JsResult })
event.result.handleCancel() event.result.handleCancel()
} }
}) })
}
return true return true
}) })
} }
...@@ -1710,6 +1753,7 @@ onPrompt(callback: (event?: { url: string; message: string; value: string; resul ...@@ -1710,6 +1753,7 @@ onPrompt(callback: (event?: { url: string; message: string; value: string; resul
Column() { Column() {
Web({ src: $rawfile("index.html"), controller: this.controller }) Web({ src: $rawfile("index.html"), controller: this.controller })
.onPrompt((event) => { .onPrompt((event) => {
if (event) {
console.log("url:" + event.url) console.log("url:" + event.url)
console.log("message:" + event.message) console.log("message:" + event.message)
console.log("value:" + event.value) console.log("value:" + event.value)
...@@ -1732,6 +1776,7 @@ onPrompt(callback: (event?: { url: string; message: string; value: string; resul ...@@ -1732,6 +1776,7 @@ onPrompt(callback: (event?: { url: string; message: string; value: string; resul
event.result.handleCancel() event.result.handleCancel()
} }
}) })
}
return true return true
}) })
} }
...@@ -1797,10 +1842,12 @@ onConsole(callback: (event?: { message: ConsoleMessage }) => boolean) ...@@ -1797,10 +1842,12 @@ onConsole(callback: (event?: { message: ConsoleMessage }) => boolean)
Column() { Column() {
Web({ src: 'www.example.com', controller: this.controller }) Web({ src: 'www.example.com', controller: this.controller })
.onConsole((event) => { .onConsole((event) => {
if (event) {
console.log('getMessage:' + event.message.getMessage()) console.log('getMessage:' + event.message.getMessage())
console.log('getSourceId:' + event.message.getSourceId()) console.log('getSourceId:' + event.message.getSourceId())
console.log('getLineNumber:' + event.message.getLineNumber()) console.log('getLineNumber:' + event.message.getLineNumber())
console.log('getMessageLevel:' + event.message.getMessageLevel()) console.log('getMessageLevel:' + event.message.getMessageLevel())
}
return false return false
}) })
} }
...@@ -1839,11 +1886,13 @@ onDownloadStart(callback: (event?: { url: string, userAgent: string, contentDisp ...@@ -1839,11 +1886,13 @@ onDownloadStart(callback: (event?: { url: string, userAgent: string, contentDisp
Column() { Column() {
Web({ src: 'www.example.com', controller: this.controller }) Web({ src: 'www.example.com', controller: this.controller })
.onDownloadStart((event) => { .onDownloadStart((event) => {
if (event) {
console.log('url:' + event.url) console.log('url:' + event.url)
console.log('userAgent:' + event.userAgent) console.log('userAgent:' + event.userAgent)
console.log('contentDisposition:' + event.contentDisposition) console.log('contentDisposition:' + event.contentDisposition)
console.log('contentLength:' + event.contentLength) console.log('contentLength:' + event.contentLength)
console.log('mimetype:' + event.mimetype) console.log('mimetype:' + event.mimetype)
}
}) })
} }
} }
...@@ -1878,6 +1927,7 @@ onErrorReceive(callback: (event?: { request: WebResourceRequest, error: WebResou ...@@ -1878,6 +1927,7 @@ onErrorReceive(callback: (event?: { request: WebResourceRequest, error: WebResou
Column() { Column() {
Web({ src: 'www.example.com', controller: this.controller }) Web({ src: 'www.example.com', controller: this.controller })
.onErrorReceive((event) => { .onErrorReceive((event) => {
if (event) {
console.log('getErrorInfo:' + event.error.getErrorInfo()) console.log('getErrorInfo:' + event.error.getErrorInfo())
console.log('getErrorCode:' + event.error.getErrorCode()) console.log('getErrorCode:' + event.error.getErrorCode())
console.log('url:' + event.request.getRequestUrl()) console.log('url:' + event.request.getRequestUrl())
...@@ -1890,6 +1940,7 @@ onErrorReceive(callback: (event?: { request: WebResourceRequest, error: WebResou ...@@ -1890,6 +1940,7 @@ onErrorReceive(callback: (event?: { request: WebResourceRequest, error: WebResou
for (let i of result) { for (let i of result) {
console.log('The request header key is : ' + i.headerKey + ', value is : ' + i.headerValue) console.log('The request header key is : ' + i.headerKey + ', value is : ' + i.headerValue)
} }
}
}) })
} }
} }
...@@ -1924,6 +1975,7 @@ onHttpErrorReceive(callback: (event?: { request: WebResourceRequest, response: W ...@@ -1924,6 +1975,7 @@ onHttpErrorReceive(callback: (event?: { request: WebResourceRequest, response: W
Column() { Column() {
Web({ src: 'www.example.com', controller: this.controller }) Web({ src: 'www.example.com', controller: this.controller })
.onHttpErrorReceive((event) => { .onHttpErrorReceive((event) => {
if (event) {
console.log('url:' + event.request.getRequestUrl()) console.log('url:' + event.request.getRequestUrl())
console.log('isMainFrame:' + event.request.isMainFrame()) console.log('isMainFrame:' + event.request.isMainFrame())
console.log('isRedirect:' + event.request.isRedirect()) console.log('isRedirect:' + event.request.isRedirect())
...@@ -1943,6 +1995,7 @@ onHttpErrorReceive(callback: (event?: { request: WebResourceRequest, response: W ...@@ -1943,6 +1995,7 @@ onHttpErrorReceive(callback: (event?: { request: WebResourceRequest, response: W
for (let i of resph) { for (let i of resph) {
console.log('The response header key is : ' + i.headerKey + ' , value is : ' + i.headerValue) console.log('The response header key is : ' + i.headerKey + ' , value is : ' + i.headerValue)
} }
}
}) })
} }
} }
...@@ -1976,7 +2029,9 @@ onPageBegin(callback: (event?: { url: string }) => void) ...@@ -1976,7 +2029,9 @@ onPageBegin(callback: (event?: { url: string }) => void)
Column() { Column() {
Web({ src: 'www.example.com', controller: this.controller }) Web({ src: 'www.example.com', controller: this.controller })
.onPageBegin((event) => { .onPageBegin((event) => {
if (event) {
console.log('url:' + event.url) console.log('url:' + event.url)
}
}) })
} }
} }
...@@ -2010,7 +2065,9 @@ onPageEnd(callback: (event?: { url: string }) => void) ...@@ -2010,7 +2065,9 @@ onPageEnd(callback: (event?: { url: string }) => void)
Column() { Column() {
Web({ src: 'www.example.com', controller: this.controller }) Web({ src: 'www.example.com', controller: this.controller })
.onPageEnd((event) => { .onPageEnd((event) => {
if (event) {
console.log('url:' + event.url) console.log('url:' + event.url)
}
}) })
} }
} }
...@@ -2044,7 +2101,9 @@ onProgressChange(callback: (event?: { newProgress: number }) => void) ...@@ -2044,7 +2101,9 @@ onProgressChange(callback: (event?: { newProgress: number }) => void)
Column() { Column() {
Web({ src: 'www.example.com', controller: this.controller }) Web({ src: 'www.example.com', controller: this.controller })
.onProgressChange((event) => { .onProgressChange((event) => {
if (event) {
console.log('newProgress:' + event.newProgress) console.log('newProgress:' + event.newProgress)
}
}) })
} }
} }
...@@ -2078,7 +2137,9 @@ onTitleReceive(callback: (event?: { title: string }) => void) ...@@ -2078,7 +2137,9 @@ onTitleReceive(callback: (event?: { title: string }) => void)
Column() { Column() {
Web({ src: 'www.example.com', controller: this.controller }) Web({ src: 'www.example.com', controller: this.controller })
.onTitleReceive((event) => { .onTitleReceive((event) => {
if (event) {
console.log('title:' + event.title) console.log('title:' + event.title)
}
}) })
} }
} }
...@@ -2113,7 +2174,9 @@ onRefreshAccessedHistory(callback: (event?: { url: string, isRefreshed: boolean ...@@ -2113,7 +2174,9 @@ onRefreshAccessedHistory(callback: (event?: { url: string, isRefreshed: boolean
Column() { Column() {
Web({ src: 'www.example.com', controller: this.controller }) Web({ src: 'www.example.com', controller: this.controller })
.onRefreshAccessedHistory((event) => { .onRefreshAccessedHistory((event) => {
if (event) {
console.log('url:' + event.url + ' isReload:' + event.isRefreshed) console.log('url:' + event.url + ' isReload:' + event.isRefreshed)
}
}) })
} }
} }
...@@ -2167,7 +2230,9 @@ onRenderExited(callback: (event?: { renderExitReason: RenderExitReason }) => voi ...@@ -2167,7 +2230,9 @@ onRenderExited(callback: (event?: { renderExitReason: RenderExitReason }) => voi
Column() { Column() {
Web({ src: 'chrome://crash/', controller: this.controller }) Web({ src: 'chrome://crash/', controller: this.controller })
.onRenderExited((event) => { .onRenderExited((event) => {
if (event) {
console.log('reason:' + event.renderExitReason) console.log('reason:' + event.renderExitReason)
}
}) })
} }
} }
...@@ -2199,6 +2264,7 @@ onShowFileSelector(callback: (event?: { result: FileSelectorResult, fileSelector ...@@ -2199,6 +2264,7 @@ onShowFileSelector(callback: (event?: { result: FileSelectorResult, fileSelector
// xxx.ets // xxx.ets
import web_webview from '@ohos.web.webview'; import web_webview from '@ohos.web.webview';
import picker from '@ohos.file.picker'; import picker from '@ohos.file.picker';
import { BusinessError } from '@ohos.base';
@Entry @Entry
@Component @Component
...@@ -2211,13 +2277,15 @@ onShowFileSelector(callback: (event?: { result: FileSelectorResult, fileSelector ...@@ -2211,13 +2277,15 @@ onShowFileSelector(callback: (event?: { result: FileSelectorResult, fileSelector
.onShowFileSelector((event) => { .onShowFileSelector((event) => {
console.log('MyFileUploader onShowFileSelector invoked') console.log('MyFileUploader onShowFileSelector invoked')
const documentSelectOptions = new picker.DocumentSelectOptions(); const documentSelectOptions = new picker.DocumentSelectOptions();
let uri = null; let uri: string | null = null;
const documentViewPicker = new picker.DocumentViewPicker(); const documentViewPicker = new picker.DocumentViewPicker();
documentViewPicker.select(documentSelectOptions).then((documentSelectResult) => { documentViewPicker.select(documentSelectOptions).then((documentSelectResult) => {
uri = documentSelectResult[0]; uri = documentSelectResult[0];
console.info('documentViewPicker.select to file succeed and uri is:' + uri); console.info('documentViewPicker.select to file succeed and uri is:' + uri);
if (event) {
event.result.handleFileList([uri]); event.result.handleFileList([uri]);
}).catch((err) => { }
}).catch((err: BusinessError) => {
console.error(`Invoke documentViewPicker.select failed, code is ${err.code}, message is ${err.message}`); console.error(`Invoke documentViewPicker.select failed, code is ${err.code}, message is ${err.message}`);
}) })
return true return true
...@@ -2343,7 +2411,9 @@ onUrlLoadIntercept(callback: (event?: { data:string | WebResourceRequest }) => b ...@@ -2343,7 +2411,9 @@ onUrlLoadIntercept(callback: (event?: { data:string | WebResourceRequest }) => b
Column() { Column() {
Web({ src: 'www.example.com', controller: this.controller }) Web({ src: 'www.example.com', controller: this.controller })
.onUrlLoadIntercept((event) => { .onUrlLoadIntercept((event) => {
if (event) {
console.log('onUrlLoadIntercept ' + event.data.toString()) console.log('onUrlLoadIntercept ' + event.data.toString())
}
return true return true
}) })
} }
...@@ -2394,16 +2464,18 @@ onInterceptRequest(callback: (event?: { request: WebResourceRequest}) => WebReso ...@@ -2394,16 +2464,18 @@ onInterceptRequest(callback: (event?: { request: WebResourceRequest}) => WebReso
Column() { Column() {
Web({ src: 'www.example.com', controller: this.controller }) Web({ src: 'www.example.com', controller: this.controller })
.onInterceptRequest((event) => { .onInterceptRequest((event) => {
if (event) {
console.log('url:' + event.request.getRequestUrl()) console.log('url:' + event.request.getRequestUrl())
var head1:Header = { }
let head1:Header = {
headerKey:"Connection", headerKey:"Connection",
headerValue:"keep-alive" headerValue:"keep-alive"
} }
var head2:Header = { let head2:Header = {
headerKey:"Cache-Control", headerKey:"Cache-Control",
headerValue:"no-cache" headerValue:"no-cache"
} }
var length = this.heads.push(head1) let length = this.heads.push(head1)
length = this.heads.push(head2) length = this.heads.push(head2)
this.responseweb.setResponseHeader(this.heads) this.responseweb.setResponseHeader(this.heads)
this.responseweb.setResponseData(this.webdata) this.responseweb.setResponseData(this.webdata)
...@@ -2453,6 +2525,7 @@ onHttpAuthRequest(callback: (event?: { handler: HttpAuthHandler, host: string, r ...@@ -2453,6 +2525,7 @@ onHttpAuthRequest(callback: (event?: { handler: HttpAuthHandler, host: string, r
Column() { Column() {
Web({ src: 'www.example.com', controller: this.controller }) Web({ src: 'www.example.com', controller: this.controller })
.onHttpAuthRequest((event) => { .onHttpAuthRequest((event) => {
if (event) {
AlertDialog.show({ AlertDialog.show({
title: 'onHttpAuthRequest', title: 'onHttpAuthRequest',
message: 'text', message: 'text',
...@@ -2481,6 +2554,7 @@ onHttpAuthRequest(callback: (event?: { handler: HttpAuthHandler, host: string, r ...@@ -2481,6 +2554,7 @@ onHttpAuthRequest(callback: (event?: { handler: HttpAuthHandler, host: string, r
event.handler.cancel() event.handler.cancel()
} }
}) })
}
return true return true
}) })
} }
...@@ -2595,8 +2669,11 @@ onClientAuthenticationRequest(callback: (event: {handler : ClientAuthenticationH ...@@ -2595,8 +2669,11 @@ onClientAuthenticationRequest(callback: (event: {handler : ClientAuthenticationH
```ts ```ts
// xxx.ets API10 // xxx.ets API10
import common from '@ohos.app.ability.common';
import Want from '@ohos.app.ability.Want';
import web_webview from '@ohos.web.webview' import web_webview from '@ohos.web.webview'
import bundle from '@ohos.bundle' import bundle from '@ohos.bundle'
import { GlobalContext } from '../GlobalContext'
let uri = ""; let uri = "";
...@@ -2611,15 +2688,15 @@ onClientAuthenticationRequest(callback: (event: {handler : ClientAuthenticationH ...@@ -2611,15 +2688,15 @@ onClientAuthenticationRequest(callback: (event: {handler : ClientAuthenticationH
return CertManagerService.sInstance; return CertManagerService.sInstance;
} }
async grantAppPm(callback) { async grantAppPm(callback: (message: string) => void) {
let message = ''; let message = '';
//注:com.example.myapplication需要写实际应用名称 //注:com.example.myapplication需要写实际应用名称
let bundleInfo = await bundle.getBundleInfo("com.example.myapplication", bundle.BundleFlag.GET_BUNDLE_DEFAULT) let bundleInfo = await bundle.getBundleInfo("com.example.myapplication", bundle.BundleFlag.GET_BUNDLE_DEFAULT)
let clientAppUid = bundleInfo.uid let clientAppUid = bundleInfo.uid
let appUid = clientAppUid.toString() let appUid = clientAppUid.toString()
//注:globalThis.AbilityContext需要在MainAbility.ts文件的onCreate函数里添加globalThis.AbilityContext = this.context //注:需要在MainAbility.ts文件的onCreate函数里添加GlobalContext.getContext().setObject("AbilityContext", this.context)
await globalThis.AbilityContext.startAbilityForResult( await GlobalContext.getContext().getObject("AbilityContext").startAbilityForResult(
{ {
bundleName: "com.ohos.certmanager", bundleName: "com.ohos.certmanager",
abilityName: "MainAbility", abilityName: "MainAbility",
...@@ -2627,10 +2704,12 @@ onClientAuthenticationRequest(callback: (event: {handler : ClientAuthenticationH ...@@ -2627,10 +2704,12 @@ onClientAuthenticationRequest(callback: (event: {handler : ClientAuthenticationH
parameters: { parameters: {
appUid: appUid, //传入申请应用的appUid appUid: appUid, //传入申请应用的appUid
} }
}) } as Want)
.then((data) => { .then((data: common.AbilityResult) => {
if (!data.resultCode) { if (!data.resultCode && data.want) {
this.authUri = data.want.parameters.authUri; //授权成功后获取返回的authUri if (data.want.parameters) {
this.authUri = data.want.parameters.authUri as string; //授权成功后获取返回的authUri
}
} }
}) })
message += "after grantAppPm authUri: " + this.authUri; message += "after grantAppPm authUri: " + this.authUri;
...@@ -2719,6 +2798,7 @@ onPermissionRequest(callback: (event?: { request: PermissionRequest }) => void) ...@@ -2719,6 +2798,7 @@ onPermissionRequest(callback: (event?: { request: PermissionRequest }) => void)
Column() { Column() {
Web({ src: 'www.example.com', controller: this.controller }) Web({ src: 'www.example.com', controller: this.controller })
.onPermissionRequest((event) => { .onPermissionRequest((event) => {
if (event) {
AlertDialog.show({ AlertDialog.show({
title: 'title', title: 'title',
message: 'text', message: 'text',
...@@ -2738,6 +2818,7 @@ onPermissionRequest(callback: (event?: { request: PermissionRequest }) => void) ...@@ -2738,6 +2818,7 @@ onPermissionRequest(callback: (event?: { request: PermissionRequest }) => void)
event.request.deny() event.request.deny()
} }
}) })
}
}) })
} }
} }
...@@ -2777,8 +2858,10 @@ onContextMenuShow(callback: (event?: { param: WebContextMenuParam, result: WebCo ...@@ -2777,8 +2858,10 @@ onContextMenuShow(callback: (event?: { param: WebContextMenuParam, result: WebCo
Column() { Column() {
Web({ src: 'www.example.com', controller: this.controller }) Web({ src: 'www.example.com', controller: this.controller })
.onContextMenuShow((event) => { .onContextMenuShow((event) => {
if (event) {
console.info("x coord = " + event.param.x()) console.info("x coord = " + event.param.x())
console.info("link url = " + event.param.getLinkUrl()) console.info("link url = " + event.param.getLinkUrl())
}
return true return true
}) })
} }
...@@ -2849,6 +2932,7 @@ onGeolocationShow(callback: (event?: { origin: string, geolocation: JsGeolocatio ...@@ -2849,6 +2932,7 @@ onGeolocationShow(callback: (event?: { origin: string, geolocation: JsGeolocatio
Web({ src:'www.example.com', controller:this.controller }) Web({ src:'www.example.com', controller:this.controller })
.geolocationAccess(true) .geolocationAccess(true)
.onGeolocationShow((event) => { .onGeolocationShow((event) => {
if (event) {
AlertDialog.show({ AlertDialog.show({
title: 'title', title: 'title',
message: 'text', message: 'text',
...@@ -2862,6 +2946,7 @@ onGeolocationShow(callback: (event?: { origin: string, geolocation: JsGeolocatio ...@@ -2862,6 +2946,7 @@ onGeolocationShow(callback: (event?: { origin: string, geolocation: JsGeolocatio
event.geolocation.invoke(event.origin, false, true) event.geolocation.invoke(event.origin, false, true)
} }
}) })
}
}) })
} }
} }
...@@ -2924,7 +3009,7 @@ onFullScreenEnter(callback: (event: { handler: FullScreenExitHandler }) => void) ...@@ -2924,7 +3009,7 @@ onFullScreenEnter(callback: (event: { handler: FullScreenExitHandler }) => void)
@Component @Component
struct WebComponent { struct WebComponent {
controller: web_webview.WebviewController = new web_webview.WebviewController() controller: web_webview.WebviewController = new web_webview.WebviewController()
handler: FullScreenExitHandler = null handler: FullScreenExitHandler | null = null
build() { build() {
Column() { Column() {
Web({ src:'www.example.com', controller:this.controller }) Web({ src:'www.example.com', controller:this.controller })
...@@ -2959,13 +3044,15 @@ onFullScreenExit(callback: () => void) ...@@ -2959,13 +3044,15 @@ onFullScreenExit(callback: () => void)
@Component @Component
struct WebComponent { struct WebComponent {
controller: web_webview.WebviewController = new web_webview.WebviewController() controller: web_webview.WebviewController = new web_webview.WebviewController()
handler: FullScreenExitHandler = null handler: FullScreenExitHandler | null = null
build() { build() {
Column() { Column() {
Web({ src:'www.example.com', controller:this.controller }) Web({ src:'www.example.com', controller:this.controller })
.onFullScreenExit(() => { .onFullScreenExit(() => {
console.log("onFullScreenExit...") console.log("onFullScreenExit...")
if (this.handler) {
this.handler.exitFullScreen() this.handler.exitFullScreen()
}
}) })
.onFullScreenEnter((event) => { .onFullScreenEnter((event) => {
this.handler = event.handler this.handler = event.handler
...@@ -3001,8 +3088,8 @@ onWindowNew(callback: (event: {isAlert: boolean, isUserTrigger: boolean, targetU ...@@ -3001,8 +3088,8 @@ onWindowNew(callback: (event: {isAlert: boolean, isUserTrigger: boolean, targetU
//在同一page页有两个web组件。在WebComponent新开窗口时,会跳转到NewWebViewComp。 //在同一page页有两个web组件。在WebComponent新开窗口时,会跳转到NewWebViewComp。
@CustomDialog @CustomDialog
struct NewWebViewComp { struct NewWebViewComp {
controller: CustomDialogController controller?: CustomDialogController
webviewController1: web_webview.WebviewController webviewController1: web_webview.WebviewController = new web_webview.WebviewController()
build() { build() {
Column() { Column() {
Web({ src: "", controller: this.webviewController1 }) Web({ src: "", controller: this.webviewController1 })
...@@ -3010,7 +3097,9 @@ onWindowNew(callback: (event: {isAlert: boolean, isUserTrigger: boolean, targetU ...@@ -3010,7 +3097,9 @@ onWindowNew(callback: (event: {isAlert: boolean, isUserTrigger: boolean, targetU
.multiWindowAccess(false) .multiWindowAccess(false)
.onWindowExit(()=> { .onWindowExit(()=> {
console.info("NewWebViewComp onWindowExit") console.info("NewWebViewComp onWindowExit")
if (this.controller) {
this.controller.close() this.controller.close()
}
}) })
} }
} }
...@@ -3020,7 +3109,7 @@ onWindowNew(callback: (event: {isAlert: boolean, isUserTrigger: boolean, targetU ...@@ -3020,7 +3109,7 @@ onWindowNew(callback: (event: {isAlert: boolean, isUserTrigger: boolean, targetU
@Component @Component
struct WebComponent { struct WebComponent {
controller: web_webview.WebviewController = new web_webview.WebviewController() controller: web_webview.WebviewController = new web_webview.WebviewController()
dialogController: CustomDialogController = null dialogController: CustomDialogController | null = null
build() { build() {
Column() { Column() {
Web({ src: 'www.example.com', controller: this.controller }) Web({ src: 'www.example.com', controller: this.controller })
...@@ -3109,8 +3198,10 @@ onSearchResultReceive(callback: (event?: {activeMatchOrdinal: number, numberOfMa ...@@ -3109,8 +3198,10 @@ onSearchResultReceive(callback: (event?: {activeMatchOrdinal: number, numberOfMa
Column() { Column() {
Web({ src: 'www.example.com', controller: this.controller }) Web({ src: 'www.example.com', controller: this.controller })
.onSearchResultReceive(ret => { .onSearchResultReceive(ret => {
if (ret) {
console.log("on search result receive:" + "[cur]" + ret.activeMatchOrdinal + console.log("on search result receive:" + "[cur]" + ret.activeMatchOrdinal +
"[total]" + ret.numberOfMatches + "[isDone]"+ ret.isDoneCounting) "[total]" + ret.numberOfMatches + "[isDone]"+ ret.isDoneCounting)
}
}) })
} }
} }
...@@ -3279,7 +3370,7 @@ onFaviconReceived(callback: (event: {favicon: image.PixelMap}) => void) ...@@ -3279,7 +3370,7 @@ onFaviconReceived(callback: (event: {favicon: image.PixelMap}) => void)
@Component @Component
struct WebComponent { struct WebComponent {
controller: web_webview.WebviewController = new web_webview.WebviewController() controller: web_webview.WebviewController = new web_webview.WebviewController()
@State icon: image.PixelMap = undefined; @State icon: image.PixelMap | undefined = undefined;
build() { build() {
Column() { Column() {
Web({ src:'www.example.com', controller: this.controller }) Web({ src:'www.example.com', controller: this.controller })
...@@ -3353,9 +3444,11 @@ onFirstContentfulPaint(callback: (event?: { navigationStartTick: number, firstCo ...@@ -3353,9 +3444,11 @@ onFirstContentfulPaint(callback: (event?: { navigationStartTick: number, firstCo
Column() { Column() {
Web({ src:'www.example.com', controller: this.controller }) Web({ src:'www.example.com', controller: this.controller })
.onFirstContentfulPaint(event => { .onFirstContentfulPaint(event => {
if (event) {
console.log("onFirstContentfulPaint:" + "[navigationStartTick]:" + console.log("onFirstContentfulPaint:" + "[navigationStartTick]:" +
event.navigationStartTick + ", [firstContentfulPaintMs]:" + event.navigationStartTick + ", [firstContentfulPaintMs]:" +
event.firstContentfulPaintMs) event.firstContentfulPaintMs)
}
}) })
} }
} }
...@@ -3459,6 +3552,7 @@ onScreenCaptureRequest(callback: (event?: { handler: ScreenCaptureHandler }) => ...@@ -3459,6 +3552,7 @@ onScreenCaptureRequest(callback: (event?: { handler: ScreenCaptureHandler }) =>
Column() { Column() {
Web({ src: 'www.example.com', controller: this.controller }) Web({ src: 'www.example.com', controller: this.controller })
.onScreenCaptureRequest((event) => { .onScreenCaptureRequest((event) => {
if (event) {
AlertDialog.show({ AlertDialog.show({
title: 'title: ' + event.handler.getOrigin(), title: 'title: ' + event.handler.getOrigin(),
message: 'text', message: 'text',
...@@ -3478,6 +3572,7 @@ onScreenCaptureRequest(callback: (event?: { handler: ScreenCaptureHandler }) => ...@@ -3478,6 +3572,7 @@ onScreenCaptureRequest(callback: (event?: { handler: ScreenCaptureHandler }) =>
event.handler.deny() event.handler.deny()
} }
}) })
}
}) })
} }
} }
...@@ -3552,6 +3647,7 @@ onControllerAttached(callback: () => void) ...@@ -3552,6 +3647,7 @@ onControllerAttached(callback: () => void)
```ts ```ts
// xxx.ets // xxx.ets
import web_webview from '@ohos.web.webview' import web_webview from '@ohos.web.webview'
import { BusinessError } from '@ohos.base';
@Entry @Entry
@Component @Component
...@@ -3566,7 +3662,9 @@ onControllerAttached(callback: () => void) ...@@ -3566,7 +3662,9 @@ onControllerAttached(callback: () => void)
let id = this.controller.getWebId(); let id = this.controller.getWebId();
console.log("id: " + id); console.log("id: " + id);
} catch (error) { } catch (error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`); let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`ErrorCode: ${code}, Message: ${message}`);
} }
}) })
} }
...@@ -4627,8 +4725,8 @@ cancel(): void ...@@ -4627,8 +4725,8 @@ cancel(): void
### 创建对象 ### 创建对象
``` ```ts
webController: WebController = new WebController() let webController: WebController = new WebController()
``` ```
### getCookieManager<sup>9+</sup> ### getCookieManager<sup>9+</sup>
...@@ -5167,18 +5265,24 @@ registerJavaScriptProxy(options: { object: object, name: string, methodList: Arr ...@@ -5167,18 +5265,24 @@ registerJavaScriptProxy(options: { object: object, name: string, methodList: Arr
```ts ```ts
// xxx.ets // xxx.ets
@Entry class TestObj {
@Component constructor() {
struct Index { }
controller: WebController = new WebController()
testObj = { test(): string {
test: (data) => {
return "ArkUI Web Component" return "ArkUI Web Component"
}, }
toString: () => {
toString(): void {
console.log('Web Component toString') console.log('Web Component toString')
} }
} }
@Entry
@Component
struct Index {
controller: WebController = new WebController()
testObj = new TestObj();
build() { build() {
Column() { Column() {
Row() { Row() {
...@@ -5252,7 +5356,9 @@ runJavaScript(options: { script: string, callback?: (result: string) => void }) ...@@ -5252,7 +5356,9 @@ runJavaScript(options: { script: string, callback?: (result: string) => void })
this.webResult = result this.webResult = result
console.info(`The test() return value is: ${result}`) console.info(`The test() return value is: ${result}`)
}}) }})
if (e) {
console.info('url: ', e.url) console.info('url: ', e.url)
}
}) })
} }
} }
......
...@@ -45,8 +45,8 @@ struct LongPressGestureExample { ...@@ -45,8 +45,8 @@ struct LongPressGestureExample {
.gesture( .gesture(
LongPressGesture({ repeat: true }) LongPressGesture({ repeat: true })
// 由于repeat设置为true,长按动作存在时会连续触发,触发间隔为duration(默认值500ms) // 由于repeat设置为true,长按动作存在时会连续触发,触发间隔为duration(默认值500ms)
.onAction((event: GestureEvent) => { .onAction((event?: GestureEvent) => {
if (event.repeat) { if (event && event.repeat) {
this.count++ this.count++
} }
}) })
......
...@@ -95,12 +95,14 @@ struct PanGestureExample { ...@@ -95,12 +95,14 @@ struct PanGestureExample {
// 左右拖动触发该手势事件 // 左右拖动触发该手势事件
.gesture( .gesture(
PanGesture(this.panOption) PanGesture(this.panOption)
.onActionStart((event: GestureEvent) => { .onActionStart((event?: GestureEvent) => {
console.info('Pan start') console.info('Pan start')
}) })
.onActionUpdate((event: GestureEvent) => { .onActionUpdate((event?: GestureEvent) => {
if (event) {
this.offsetX = this.positionX + event.offsetX this.offsetX = this.positionX + event.offsetX
this.offsetY = this.positionY + event.offsetY this.offsetY = this.positionY + event.offsetY
}
}) })
.onActionEnd(() => { .onActionEnd(() => {
this.positionX = this.offsetX this.positionX = this.offsetX
......
...@@ -56,13 +56,15 @@ struct PinchGestureExample { ...@@ -56,13 +56,15 @@ struct PinchGestureExample {
// 三指捏合触发该手势事件 // 三指捏合触发该手势事件
.gesture( .gesture(
PinchGesture({ fingers: 3 }) PinchGesture({ fingers: 3 })
.onActionStart((event: GestureEvent) => { .onActionStart((event?: GestureEvent) => {
console.info('Pinch start') console.info('Pinch start')
}) })
.onActionUpdate((event: GestureEvent) => { .onActionUpdate((event?: GestureEvent) => {
if (event) {
this.scaleValue = this.pinchValue * event.scale this.scaleValue = this.pinchValue * event.scale
this.pinchX = event.pinchCenterX this.pinchX = event.pinchCenterX
this.pinchY = event.pinchCenterY this.pinchY = event.pinchCenterY
}
}) })
.onActionEnd(() => { .onActionEnd(() => {
this.pinchValue = this.scaleValue this.pinchValue = this.scaleValue
......
...@@ -53,11 +53,13 @@ struct RotationGestureExample { ...@@ -53,11 +53,13 @@ struct RotationGestureExample {
// 双指旋转触发该手势事件 // 双指旋转触发该手势事件
.gesture( .gesture(
RotationGesture() RotationGesture()
.onActionStart((event: GestureEvent) => { .onActionStart((event?: GestureEvent) => {
console.info('Rotation start') console.info('Rotation start')
}) })
.onActionUpdate((event: GestureEvent) => { .onActionUpdate((event?: GestureEvent) => {
if (event) {
this.angle = this.rotateValue + event.angle this.angle = this.rotateValue + event.angle
}
}) })
.onActionEnd(() => { .onActionEnd(() => {
this.rotateValue = this.angle this.rotateValue = this.angle
......
...@@ -59,9 +59,11 @@ struct SwipeGestureExample { ...@@ -59,9 +59,11 @@ struct SwipeGestureExample {
// 单指竖直方向滑动时触发该事件 // 单指竖直方向滑动时触发该事件
.gesture( .gesture(
SwipeGesture({ direction: SwipeDirection.Vertical }) SwipeGesture({ direction: SwipeDirection.Vertical })
.onAction((event: GestureEvent) => { .onAction((event?: GestureEvent) => {
if (event) {
this.speed = event.speed this.speed = event.speed
this.rotateAngle = event.angle this.rotateAngle = event.angle
}
}) })
) )
}.width('100%') }.width('100%')
......
...@@ -41,8 +41,10 @@ struct TapGestureExample { ...@@ -41,8 +41,10 @@ struct TapGestureExample {
Text('Click twice').fontSize(28) Text('Click twice').fontSize(28)
.gesture( .gesture(
TapGesture({ count: 2 }) TapGesture({ count: 2 })
.onAction((event: GestureEvent) => { .onAction((event?: GestureEvent) => {
if (event) {
this.value = JSON.stringify(event.fingerList[0]) this.value = JSON.stringify(event.fingerList[0])
}
}) })
) )
Text(this.value) Text(this.value)
......
...@@ -1423,8 +1423,10 @@ createPattern(image: ImageBitmap, repetition: string | null): CanvasPattern | nu ...@@ -1423,8 +1423,10 @@ createPattern(image: ImageBitmap, repetition: string | null): CanvasPattern | nu
.height('100%') .height('100%')
.backgroundColor('#ffff00') .backgroundColor('#ffff00')
.onReady(() =>{ .onReady(() =>{
var pattern = this.context.createPattern(this.img, 'repeat') let pattern = this.context.createPattern(this.img, 'repeat')
if (pattern) {
this.context.fillStyle = pattern this.context.fillStyle = pattern
}
this.context.fillRect(0, 0, 200, 200) this.context.fillRect(0, 0, 200, 200)
}) })
} }
...@@ -2421,7 +2423,7 @@ getImageData(sx: number, sy: number, sw: number, sh: number): ImageData ...@@ -2421,7 +2423,7 @@ getImageData(sx: number, sy: number, sw: number, sh: number): ImageData
.backgroundColor('#ffff00') .backgroundColor('#ffff00')
.onReady(() =>{ .onReady(() =>{
this.context.drawImage(this.img,0,0,130,130) this.context.drawImage(this.img,0,0,130,130)
var imagedata = this.context.getImageData(50,50,130,130) let imagedata = this.context.getImageData(50,50,130,130)
this.context.putImageData(imagedata,150,150) this.context.putImageData(imagedata,150,150)
}) })
} }
...@@ -2473,8 +2475,8 @@ putImageData(imageData: ImageData, dx: number | string, dy: number | string, dir ...@@ -2473,8 +2475,8 @@ putImageData(imageData: ImageData, dx: number | string, dy: number | string, dir
.height('100%') .height('100%')
.backgroundColor('#ffff00') .backgroundColor('#ffff00')
.onReady(() =>{ .onReady(() =>{
var imageData = this.context.createImageData(100, 100) let imageData = this.context.createImageData(100, 100)
for (var i = 0; i < imageData.data.length; i += 4) { for (let i = 0; i < imageData.data.length; i += 4) {
imageData.data[i + 0] = 255 imageData.data[i + 0] = 255
imageData.data[i + 1] = 0 imageData.data[i + 1] = 0
imageData.data[i + 2] = 255 imageData.data[i + 2] = 255
...@@ -2626,15 +2628,15 @@ transferFromImageBitmap(bitmap: ImageBitmap): void ...@@ -2626,15 +2628,15 @@ transferFromImageBitmap(bitmap: ImageBitmap): void
.height('100%') .height('100%')
.backgroundColor('#ffff00') .backgroundColor('#ffff00')
.onReady(() =>{ .onReady(() =>{
var imageData = this.offContext.createImageData(100, 100) let imageData = this.offContext.createImageData(100, 100)
for (var i = 0; i < imageData.data.length; i += 4) { for (let i = 0; i < imageData.data.length; i += 4) {
imageData.data[i + 0] = 255 imageData.data[i + 0] = 255
imageData.data[i + 1] = 0 imageData.data[i + 1] = 0
imageData.data[i + 2] = 255 imageData.data[i + 2] = 255
imageData.data[i + 3] = 255 imageData.data[i + 3] = 255
} }
this.offContext.putImageData(imageData, 10, 10) this.offContext.putImageData(imageData, 10, 10)
var image = this.offContext.transferToImageBitmap() let image = this.offContext.transferToImageBitmap()
this.context.transferFromImageBitmap(image) this.context.transferFromImageBitmap(image)
}) })
} }
...@@ -2684,7 +2686,7 @@ toDataURL(type?: string, quality?: number): string ...@@ -2684,7 +2686,7 @@ toDataURL(type?: string, quality?: number): string
.height('100%') .height('100%')
.backgroundColor('#ffff00') .backgroundColor('#ffff00')
.onReady(() =>{ .onReady(() =>{
var dataURL = this.context.toDataURL() let dataURL = this.context.toDataURL()
}) })
} }
.width('100%') .width('100%')
...@@ -2808,7 +2810,7 @@ createLinearGradient(x0: number, y0: number, x1: number, y1: number): void ...@@ -2808,7 +2810,7 @@ createLinearGradient(x0: number, y0: number, x1: number, y1: number): void
.height('100%') .height('100%')
.backgroundColor('#ffff00') .backgroundColor('#ffff00')
.onReady(() =>{ .onReady(() =>{
var grad = this.context.createLinearGradient(50,0, 300,100) let grad = this.context.createLinearGradient(50,0, 300,100)
grad.addColorStop(0.0, '#ff0000') grad.addColorStop(0.0, '#ff0000')
grad.addColorStop(0.5, '#ffffff') grad.addColorStop(0.5, '#ffffff')
grad.addColorStop(1.0, '#00ff00') grad.addColorStop(1.0, '#00ff00')
...@@ -2861,7 +2863,7 @@ createRadialGradient(x0: number, y0: number, r0: number, x1: number, y1: number, ...@@ -2861,7 +2863,7 @@ createRadialGradient(x0: number, y0: number, r0: number, x1: number, y1: number,
.height('100%') .height('100%')
.backgroundColor('#ffff00') .backgroundColor('#ffff00')
.onReady(() =>{ .onReady(() =>{
var grad = this.context.createRadialGradient(200,200,50, 200,200,200) let grad = this.context.createRadialGradient(200,200,50, 200,200,200)
grad.addColorStop(0.0, '#ff0000') grad.addColorStop(0.0, '#ff0000')
grad.addColorStop(0.5, '#ffffff') grad.addColorStop(0.5, '#ffffff')
grad.addColorStop(1.0, '#00ff00') grad.addColorStop(1.0, '#00ff00')
...@@ -2908,7 +2910,7 @@ struct CanvasExample { ...@@ -2908,7 +2910,7 @@ struct CanvasExample {
.height('100%') .height('100%')
.backgroundColor('#ffffff') .backgroundColor('#ffffff')
.onReady(() => { .onReady(() => {
var grad = this.context.createConicGradient(0, 50, 80) let grad = this.context.createConicGradient(0, 50, 80)
grad.addColorStop(0.0, '#ff0000') grad.addColorStop(0.0, '#ff0000')
grad.addColorStop(0.5, '#ffffff') grad.addColorStop(0.5, '#ffffff')
grad.addColorStop(1.0, '#00ff00') grad.addColorStop(1.0, '#00ff00')
......
...@@ -62,8 +62,8 @@ struct GestureGroupExample { ...@@ -62,8 +62,8 @@ struct GestureGroupExample {
// 以下组合手势为顺序识别,当长按手势事件未正常触发时则不会触发拖动手势事件 // 以下组合手势为顺序识别,当长按手势事件未正常触发时则不会触发拖动手势事件
GestureGroup(GestureMode.Sequence, GestureGroup(GestureMode.Sequence,
LongPressGesture({ repeat: true }) LongPressGesture({ repeat: true })
.onAction((event: GestureEvent) => { .onAction((event?: GestureEvent) => {
if (event.repeat) { if (event && event.repeat) {
this.count++ this.count++
} }
console.info('LongPress onAction') console.info('LongPress onAction')
...@@ -76,9 +76,11 @@ struct GestureGroupExample { ...@@ -76,9 +76,11 @@ struct GestureGroupExample {
this.borderStyles = BorderStyle.Dashed this.borderStyles = BorderStyle.Dashed
console.info('pan start') console.info('pan start')
}) })
.onActionUpdate((event: GestureEvent) => { .onActionUpdate((event?: GestureEvent) => {
if (event) {
this.offsetX = this.positionX + event.offsetX this.offsetX = this.positionX + event.offsetX
this.offsetY = this.positionY + event.offsetY this.offsetY = this.positionY + event.offsetY
}
console.info('pan update') console.info('pan update')
}) })
.onActionEnd(() => { .onActionEnd(() => {
......
...@@ -42,7 +42,7 @@ struct Page45 { ...@@ -42,7 +42,7 @@ struct Page45 {
.height('100%') .height('100%')
.backgroundColor('#ffff00') .backgroundColor('#ffff00')
.onReady(() => { .onReady(() => {
var grad = this.context.createLinearGradient(50, 0, 300, 100) let grad = this.context.createLinearGradient(50, 0, 300, 100)
grad.addColorStop(0.0, '#ff0000') grad.addColorStop(0.0, '#ff0000')
grad.addColorStop(0.5, '#ffffff') grad.addColorStop(0.5, '#ffffff')
grad.addColorStop(1.0, '#00ff00') grad.addColorStop(1.0, '#00ff00')
......
...@@ -33,7 +33,7 @@ struct CanvasPatternPage { ...@@ -33,7 +33,7 @@ struct CanvasPatternPage {
private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
private matrix: Matrix2D = new Matrix2D() private matrix: Matrix2D = new Matrix2D()
private img: ImageBitmap = new ImageBitmap("common/pattern.jpg") private img: ImageBitmap = new ImageBitmap("common/pattern.jpg")
private pattern : CanvasPattern private pattern : CanvasPattern | null = null
build() { build() {
Column() { Column() {
...@@ -43,7 +43,9 @@ struct CanvasPatternPage { ...@@ -43,7 +43,9 @@ struct CanvasPatternPage {
this.matrix.scaleX = 1 this.matrix.scaleX = 1
this.matrix.translateX = 50 this.matrix.translateX = 50
this.matrix.translateY = 200 this.matrix.translateY = 200
if (this.pattern) {
this.pattern.setTransform(this.matrix) this.pattern.setTransform(this.matrix)
}
this.context.fillRect(0, 0, 480, 720) this.context.fillRect(0, 0, 480, 720)
}) })
.width("45%") .width("45%")
...@@ -54,12 +56,14 @@ struct CanvasPatternPage { ...@@ -54,12 +56,14 @@ struct CanvasPatternPage {
.backgroundColor('#FFFFFF') .backgroundColor('#FFFFFF')
.onReady(() => { .onReady(() => {
this.pattern = this.context.createPattern(this.img, 'no-repeat') this.pattern = this.context.createPattern(this.img, 'no-repeat')
this.context.fillStyle = this.pattern
this.matrix.scaleY = 0.5 this.matrix.scaleY = 0.5
this.matrix.scaleX = 0.5 this.matrix.scaleX = 0.5
this.matrix.translateX = 50 this.matrix.translateX = 50
this.matrix.translateY = 50 this.matrix.translateY = 50
if (this.pattern) {
this.context.fillStyle = this.pattern
this.pattern.setTransform(this.matrix) this.pattern.setTransform(this.matrix)
}
this.context.fillRect(0, 0, 480, 720) this.context.fillRect(0, 0, 480, 720)
}) })
} }
......
...@@ -39,7 +39,7 @@ ImageData对象可以存储canvas渲染的像素数据。 ...@@ -39,7 +39,7 @@ ImageData对象可以存储canvas渲染的像素数据。
.backgroundColor('#ffff00') .backgroundColor('#ffff00')
.onReady(() =>{ .onReady(() =>{
this.context.drawImage(this.img,0,0,130,130) this.context.drawImage(this.img,0,0,130,130)
var imagedata = this.context.getImageData(50,50,130,130) let imagedata = this.context.getImageData(50,50,130,130)
this.context.putImageData(imagedata,150,150) this.context.putImageData(imagedata,150,150)
}) })
} }
......
...@@ -36,7 +36,7 @@ Matrix2D() ...@@ -36,7 +36,7 @@ Matrix2D()
struct Matrix2DScaleX { struct Matrix2DScaleX {
@State message: string = 'Matrix2D ScaleX' @State message: string = 'Matrix2D ScaleX'
printMatrix(title, matrix) { printMatrix(title: string, matrix: Matrix2D) {
console.log(title) console.log(title)
console.log("Matrix [scaleX = " + matrix.scaleX + ", scaleY = " + matrix.scaleY + console.log("Matrix [scaleX = " + matrix.scaleX + ", scaleY = " + matrix.scaleY +
", rotateX = " + matrix.rotateX + ", rotateY = " + matrix.rotateY + ", rotateX = " + matrix.rotateX + ", rotateY = " + matrix.rotateY +
...@@ -50,7 +50,7 @@ struct Matrix2DScaleX { ...@@ -50,7 +50,7 @@ struct Matrix2DScaleX {
.fontWeight(FontWeight.Bold) .fontWeight(FontWeight.Bold)
Button("Set scaleX") Button("Set scaleX")
.onClick(() => { .onClick(() => {
var matrix : Matrix2D = new Matrix2D() let matrix : Matrix2D = new Matrix2D()
matrix.scaleX = 1 matrix.scaleX = 1
this.printMatrix(this.message, matrix) this.printMatrix(this.message, matrix)
}) })
...@@ -71,7 +71,7 @@ struct Matrix2DScaleX { ...@@ -71,7 +71,7 @@ struct Matrix2DScaleX {
struct Matrix2DScaleY { struct Matrix2DScaleY {
@State message: string = 'Matrix2D ScaleY' @State message: string = 'Matrix2D ScaleY'
printMatrix(title, matrix) { printMatrix(title: string, matrix: Matrix2D) {
console.log(title) console.log(title)
console.log("Matrix [scaleX = " + matrix.scaleX + ", scaleY = " + matrix.scaleY + console.log("Matrix [scaleX = " + matrix.scaleX + ", scaleY = " + matrix.scaleY +
", rotateX = " + matrix.rotateX + ", rotateY = " + matrix.rotateY + ", rotateX = " + matrix.rotateX + ", rotateY = " + matrix.rotateY +
...@@ -85,7 +85,7 @@ struct Matrix2DScaleY { ...@@ -85,7 +85,7 @@ struct Matrix2DScaleY {
.fontWeight(FontWeight.Bold) .fontWeight(FontWeight.Bold)
Button("Set scaleY") Button("Set scaleY")
.onClick(() => { .onClick(() => {
var matrix : Matrix2D = new Matrix2D() let matrix : Matrix2D = new Matrix2D()
matrix.scaleY = 1 matrix.scaleY = 1
this.printMatrix(this.message, matrix) this.printMatrix(this.message, matrix)
}) })
...@@ -106,7 +106,7 @@ struct Matrix2DScaleY { ...@@ -106,7 +106,7 @@ struct Matrix2DScaleY {
struct Matrix2DRotateX { struct Matrix2DRotateX {
@State message: string = 'Matrix2D RotateX' @State message: string = 'Matrix2D RotateX'
printMatrix(title, matrix) { printMatrix(title: string, matrix: Matrix2D) {
console.log(title) console.log(title)
console.log("Matrix [scaleX = " + matrix.scaleX + ", scaleY = " + matrix.scaleY + console.log("Matrix [scaleX = " + matrix.scaleX + ", scaleY = " + matrix.scaleY +
", rotateX = " + matrix.rotateX + ", rotateY = " + matrix.rotateY + ", rotateX = " + matrix.rotateX + ", rotateY = " + matrix.rotateY +
...@@ -120,7 +120,7 @@ struct Matrix2DRotateX { ...@@ -120,7 +120,7 @@ struct Matrix2DRotateX {
.fontWeight(FontWeight.Bold) .fontWeight(FontWeight.Bold)
Button("Set rotateX") Button("Set rotateX")
.onClick(() => { .onClick(() => {
var matrix : Matrix2D = new Matrix2D() let matrix : Matrix2D = new Matrix2D()
matrix.rotateX = Math.sin(45 / Math.PI) matrix.rotateX = Math.sin(45 / Math.PI)
this.printMatrix(this.message, matrix) this.printMatrix(this.message, matrix)
}) })
...@@ -141,7 +141,7 @@ struct Matrix2DRotateX { ...@@ -141,7 +141,7 @@ struct Matrix2DRotateX {
struct Matrix2DRotateY { struct Matrix2DRotateY {
@State message: string = 'Matrix2D RotateY' @State message: string = 'Matrix2D RotateY'
printMatrix(title, matrix) { printMatrix(title: string, matrix: Matrix2D) {
console.log(title) console.log(title)
console.log("Matrix [scaleX = " + matrix.scaleX + ", scaleY = " + matrix.scaleY + console.log("Matrix [scaleX = " + matrix.scaleX + ", scaleY = " + matrix.scaleY +
", rotateX = " + matrix.rotateX + ", rotateY = " + matrix.rotateY + ", rotateX = " + matrix.rotateX + ", rotateY = " + matrix.rotateY +
...@@ -155,7 +155,7 @@ struct Matrix2DRotateY { ...@@ -155,7 +155,7 @@ struct Matrix2DRotateY {
.fontWeight(FontWeight.Bold) .fontWeight(FontWeight.Bold)
Button("Set rotateY") Button("Set rotateY")
.onClick(() => { .onClick(() => {
var matrix : Matrix2D = new Matrix2D() let matrix : Matrix2D = new Matrix2D()
matrix.rotateY = Math.cos(45 / Math.PI) matrix.rotateY = Math.cos(45 / Math.PI)
this.printMatrix(this.message, matrix) this.printMatrix(this.message, matrix)
}) })
...@@ -176,7 +176,7 @@ struct Matrix2DRotateY { ...@@ -176,7 +176,7 @@ struct Matrix2DRotateY {
struct Matrix2DTranslateX { struct Matrix2DTranslateX {
@State message: string = 'Matrix2D TranslateX' @State message: string = 'Matrix2D TranslateX'
printMatrix(title, matrix) { printMatrix(title: string, matrix: Matrix2D) {
console.log(title) console.log(title)
console.log("Matrix [scaleX = " + matrix.scaleX + ", scaleY = " + matrix.scaleY + console.log("Matrix [scaleX = " + matrix.scaleX + ", scaleY = " + matrix.scaleY +
", rotateX = " + matrix.rotateX + ", rotateY = " + matrix.rotateY + ", rotateX = " + matrix.rotateX + ", rotateY = " + matrix.rotateY +
...@@ -190,7 +190,7 @@ struct Matrix2DTranslateX { ...@@ -190,7 +190,7 @@ struct Matrix2DTranslateX {
.fontWeight(FontWeight.Bold) .fontWeight(FontWeight.Bold)
Button("Set translateX") Button("Set translateX")
.onClick(() => { .onClick(() => {
var matrix : Matrix2D = new Matrix2D() let matrix : Matrix2D = new Matrix2D()
matrix.translateX = 10 matrix.translateX = 10
this.printMatrix(this.message, matrix) this.printMatrix(this.message, matrix)
}) })
...@@ -211,7 +211,7 @@ struct Matrix2DTranslateX { ...@@ -211,7 +211,7 @@ struct Matrix2DTranslateX {
struct Matrix2DTranslateY { struct Matrix2DTranslateY {
@State message: string = 'Matrix2D TranslateY' @State message: string = 'Matrix2D TranslateY'
printMatrix(title, matrix) { printMatrix(title: string, matrix: Matrix2D) {
console.log(title) console.log(title)
console.log("Matrix [scaleX = " + matrix.scaleX + ", scaleY = " + matrix.scaleY + console.log("Matrix [scaleX = " + matrix.scaleX + ", scaleY = " + matrix.scaleY +
", rotateX = " + matrix.rotateX + ", rotateY = " + matrix.rotateY + ", rotateX = " + matrix.rotateX + ", rotateY = " + matrix.rotateY +
...@@ -225,7 +225,7 @@ struct Matrix2DTranslateY { ...@@ -225,7 +225,7 @@ struct Matrix2DTranslateY {
.fontWeight(FontWeight.Bold) .fontWeight(FontWeight.Bold)
Button("Set translateY") Button("Set translateY")
.onClick(() => { .onClick(() => {
var matrix : Matrix2D = new Matrix2D() let matrix : Matrix2D = new Matrix2D()
matrix.translateY = 10 matrix.translateY = 10
this.printMatrix(this.message, matrix) this.printMatrix(this.message, matrix)
}) })
...@@ -262,7 +262,7 @@ identity(): Matrix2D ...@@ -262,7 +262,7 @@ identity(): Matrix2D
struct Matrix2DIdentity { struct Matrix2DIdentity {
@State message: string = 'Matrix2D Identity' @State message: string = 'Matrix2D Identity'
printMatrix(title, matrix) { printMatrix(title: string, matrix: Matrix2D) {
console.log(title) console.log(title)
console.log("Matrix [scaleX = " + matrix.scaleX + ", scaleY = " + matrix.scaleY + console.log("Matrix [scaleX = " + matrix.scaleX + ", scaleY = " + matrix.scaleY +
", rotateX = " + matrix.rotateX + ", rotateY = " + matrix.rotateY + ", rotateX = " + matrix.rotateX + ", rotateY = " + matrix.rotateY +
...@@ -276,7 +276,7 @@ struct Matrix2DIdentity { ...@@ -276,7 +276,7 @@ struct Matrix2DIdentity {
.fontWeight(FontWeight.Bold) .fontWeight(FontWeight.Bold)
Button("matrix identity") Button("matrix identity")
.onClick(() => { .onClick(() => {
var matrix : Matrix2D = new Matrix2D() let matrix : Matrix2D = new Matrix2D()
matrix = matrix.identity() matrix = matrix.identity()
this.printMatrix(this.message, matrix) this.printMatrix(this.message, matrix)
}) })
...@@ -311,7 +311,7 @@ invert(): Matrix2D ...@@ -311,7 +311,7 @@ invert(): Matrix2D
struct Matrix2DInvert { struct Matrix2DInvert {
@State message: string = 'Matrix2D Invert' @State message: string = 'Matrix2D Invert'
printMatrix(title, matrix) { printMatrix(title: string, matrix: Matrix2D) {
console.log(title) console.log(title)
console.log("Matrix [scaleX = " + matrix.scaleX + ", scaleY = " + matrix.scaleY + console.log("Matrix [scaleX = " + matrix.scaleX + ", scaleY = " + matrix.scaleY +
", rotateX = " + matrix.rotateX + ", rotateY = " + matrix.rotateY + ", rotateX = " + matrix.rotateX + ", rotateY = " + matrix.rotateY +
...@@ -325,7 +325,7 @@ struct Matrix2DInvert { ...@@ -325,7 +325,7 @@ struct Matrix2DInvert {
.fontWeight(FontWeight.Bold) .fontWeight(FontWeight.Bold)
Button("matrix invert") Button("matrix invert")
.onClick(() => { .onClick(() => {
var matrix : Matrix2D = new Matrix2D() let matrix : Matrix2D = new Matrix2D()
matrix.scaleX = 2 matrix.scaleX = 2
matrix.scaleY = 1 matrix.scaleY = 1
matrix.rotateX = 0 matrix.rotateX = 0
...@@ -374,7 +374,7 @@ multiply(other?: Matrix2D): Matrix2D ...@@ -374,7 +374,7 @@ multiply(other?: Matrix2D): Matrix2D
struct Matrix2DMultiply { struct Matrix2DMultiply {
@State message: string = 'Matrix2D Multiply' @State message: string = 'Matrix2D Multiply'
printMatrix(title, matrix) { printMatrix(title: string, matrix: Matrix2D) {
console.log(title) console.log(title)
console.log("Matrix [scaleX = " + matrix.scaleX + ", scaleY = " + matrix.scaleY + console.log("Matrix [scaleX = " + matrix.scaleX + ", scaleY = " + matrix.scaleY +
", rotateX = " + matrix.rotateX + ", rotateY = " + matrix.rotateY + ", rotateX = " + matrix.rotateX + ", rotateY = " + matrix.rotateY +
...@@ -388,14 +388,14 @@ struct Matrix2DMultiply { ...@@ -388,14 +388,14 @@ struct Matrix2DMultiply {
.fontWeight(FontWeight.Bold) .fontWeight(FontWeight.Bold)
Button("matrix multiply") Button("matrix multiply")
.onClick(() => { .onClick(() => {
var matrix : Matrix2D = new Matrix2D() let matrix : Matrix2D = new Matrix2D()
matrix.scaleX = 1 matrix.scaleX = 1
matrix.scaleY = 1 matrix.scaleY = 1
matrix.rotateX = 0 matrix.rotateX = 0
matrix.rotateY = 0 matrix.rotateY = 0
matrix.translateX = 0 matrix.translateX = 0
matrix.translateY = 0 matrix.translateY = 0
var other: Matrix2D = new Matrix2D() let other: Matrix2D = new Matrix2D()
other.scaleX = 2 other.scaleX = 2
other.scaleY = 2 other.scaleY = 2
other.rotateX = 0 other.rotateX = 0
...@@ -445,7 +445,7 @@ rotate(rx?: number, ry?: number): Matrix2D ...@@ -445,7 +445,7 @@ rotate(rx?: number, ry?: number): Matrix2D
struct Matrix2DRotate { struct Matrix2DRotate {
@State message: string = 'Matrix2D Rotate' @State message: string = 'Matrix2D Rotate'
printMatrix(title, matrix) { printMatrix(title: string, matrix: Matrix2D) {
console.log(title) console.log(title)
console.log("Matrix [scaleX = " + matrix.scaleX + ", scaleY = " + matrix.scaleY + console.log("Matrix [scaleX = " + matrix.scaleX + ", scaleY = " + matrix.scaleY +
", rotateX = " + matrix.rotateX + ", rotateY = " + matrix.rotateY + ", rotateX = " + matrix.rotateX + ", rotateY = " + matrix.rotateY +
...@@ -459,7 +459,7 @@ struct Matrix2DRotate { ...@@ -459,7 +459,7 @@ struct Matrix2DRotate {
.fontWeight(FontWeight.Bold) .fontWeight(FontWeight.Bold)
Button("matrix rotate") Button("matrix rotate")
.onClick(() => { .onClick(() => {
var matrix : Matrix2D = new Matrix2D() let matrix : Matrix2D = new Matrix2D()
matrix.scaleX = 1 matrix.scaleX = 1
matrix.scaleY = 1 matrix.scaleY = 1
matrix.rotateX = 0 matrix.rotateX = 0
...@@ -508,7 +508,7 @@ rotate(degree: number, rx?: number, ry?: number): Matrix2D ...@@ -508,7 +508,7 @@ rotate(degree: number, rx?: number, ry?: number): Matrix2D
struct Matrix2DRotate { struct Matrix2DRotate {
@State message: string = 'Matrix2D Rotate' @State message: string = 'Matrix2D Rotate'
printMatrix(title, matrix) { printMatrix(title: string, matrix: Matrix2D) {
console.log(title) console.log(title)
console.log("Matrix [scaleX = " + matrix.scaleX + ", scaleY = " + matrix.scaleY + console.log("Matrix [scaleX = " + matrix.scaleX + ", scaleY = " + matrix.scaleY +
", rotateX = " + matrix.rotateX + ", rotateY = " + matrix.rotateY + ", rotateX = " + matrix.rotateX + ", rotateY = " + matrix.rotateY +
...@@ -522,7 +522,7 @@ struct Matrix2DRotate { ...@@ -522,7 +522,7 @@ struct Matrix2DRotate {
.fontWeight(FontWeight.Bold) .fontWeight(FontWeight.Bold)
Button("matrix rotate") Button("matrix rotate")
.onClick(() => { .onClick(() => {
var matrix : Matrix2D = new Matrix2D() let matrix : Matrix2D = new Matrix2D()
matrix.scaleX = 1 matrix.scaleX = 1
matrix.scaleY = 1 matrix.scaleY = 1
matrix.rotateX = 0 matrix.rotateX = 0
...@@ -570,7 +570,7 @@ translate(tx?: number, ty?: number): Matrix2D ...@@ -570,7 +570,7 @@ translate(tx?: number, ty?: number): Matrix2D
struct Matrix2DTranslate { struct Matrix2DTranslate {
@State message: string = 'Matrix2D Translate' @State message: string = 'Matrix2D Translate'
printMatrix(title, matrix) { printMatrix(title: string, matrix: Matrix2D) {
console.log(title) console.log(title)
console.log("Matrix [scaleX = " + matrix.scaleX + ", scaleY = " + matrix.scaleY + console.log("Matrix [scaleX = " + matrix.scaleX + ", scaleY = " + matrix.scaleY +
", rotateX = " + matrix.rotateX + ", rotateY = " + matrix.rotateY + ", rotateX = " + matrix.rotateX + ", rotateY = " + matrix.rotateY +
...@@ -584,7 +584,7 @@ struct Matrix2DTranslate { ...@@ -584,7 +584,7 @@ struct Matrix2DTranslate {
.fontWeight(FontWeight.Bold) .fontWeight(FontWeight.Bold)
Button("matrix translate") Button("matrix translate")
.onClick(() => { .onClick(() => {
var matrix : Matrix2D = new Matrix2D() let matrix : Matrix2D = new Matrix2D()
matrix.scaleX = 1 matrix.scaleX = 1
matrix.scaleY = 1 matrix.scaleY = 1
matrix.rotateX = 0 matrix.rotateX = 0
...@@ -632,7 +632,7 @@ scale(sx?: number, sy?: number): Matrix2D ...@@ -632,7 +632,7 @@ scale(sx?: number, sy?: number): Matrix2D
struct Matrix2DScale { struct Matrix2DScale {
@State message: string = 'Matrix2D Scale' @State message: string = 'Matrix2D Scale'
printMatrix(title, matrix) { printMatrix(title: string, matrix: Matrix2D) {
console.log(title) console.log(title)
console.log("Matrix [scaleX = " + matrix.scaleX + ", scaleY = " + matrix.scaleY + console.log("Matrix [scaleX = " + matrix.scaleX + ", scaleY = " + matrix.scaleY +
", rotateX = " + matrix.rotateX + ", rotateY = " + matrix.rotateY + ", rotateX = " + matrix.rotateX + ", rotateY = " + matrix.rotateY +
...@@ -646,7 +646,7 @@ struct Matrix2DScale { ...@@ -646,7 +646,7 @@ struct Matrix2DScale {
.fontWeight(FontWeight.Bold) .fontWeight(FontWeight.Bold)
Button("matrix scale") Button("matrix scale")
.onClick(() => { .onClick(() => {
var matrix : Matrix2D = new Matrix2D() let matrix : Matrix2D = new Matrix2D()
matrix.scaleX = 1 matrix.scaleX = 1
matrix.scaleY = 1 matrix.scaleY = 1
matrix.rotateX = 0 matrix.rotateX = 0
......
...@@ -55,10 +55,10 @@ struct OffscreenCanvasPage { ...@@ -55,10 +55,10 @@ struct OffscreenCanvasPage {
.borderColor('#00FF00') .borderColor('#00FF00')
.backgroundColor('#FFFFFF') .backgroundColor('#FFFFFF')
.onReady(() => { .onReady(() => {
var offContext = this.offCanvas.getContext("2d", this.settings) let offContext = this.offCanvas.getContext("2d", this.settings)
offContext.fillStyle = '#CDCDCD' offContext.fillStyle = '#CDCDCD'
offContext.fillRect(0, 0, this.offCanvas.width, 150) offContext.fillRect(0, 0, this.offCanvas.width, 150)
var image = this.offCanvas.transferToImageBitmap() let image = this.offCanvas.transferToImageBitmap()
this.context.setTransform(1, 0, 0, 1, 50, 200) this.context.setTransform(1, 0, 0, 1, 50, 200)
this.context.transferFromImageBitmap(image) this.context.transferFromImageBitmap(image)
}) })
...@@ -91,10 +91,10 @@ struct OffscreenCanvasPage { ...@@ -91,10 +91,10 @@ struct OffscreenCanvasPage {
.borderColor('#00FF00') .borderColor('#00FF00')
.backgroundColor('#FFFFFF') .backgroundColor('#FFFFFF')
.onReady(() => { .onReady(() => {
var offContext = this.offCanvas.getContext("2d", this.settings) let offContext = this.offCanvas.getContext("2d", this.settings)
offContext.fillStyle = '#CDCDCD' offContext.fillStyle = '#CDCDCD'
offContext.fillRect(0, 0, 100, this.offCanvas.height) offContext.fillRect(0, 0, 100, this.offCanvas.height)
var image = this.offCanvas.transferToImageBitmap() let image = this.offCanvas.transferToImageBitmap()
this.context.setTransform(1, 0, 0, 1, 50, 200) this.context.setTransform(1, 0, 0, 1, 50, 200)
this.context.transferFromImageBitmap(image) this.context.transferFromImageBitmap(image)
}) })
...@@ -142,13 +142,13 @@ struct OffscreenCanvasPage { ...@@ -142,13 +142,13 @@ struct OffscreenCanvasPage {
.borderColor('#00FF00') .borderColor('#00FF00')
.backgroundColor('#FFFFFF') .backgroundColor('#FFFFFF')
.onReady(() => { .onReady(() => {
var offContext = this.offCanvas.getContext("2d", this.settings) let offContext = this.offCanvas.getContext("2d", this.settings)
offContext.fillStyle = '#CDCDCD' offContext.fillStyle = '#CDCDCD'
offContext.fillRect(0, 0, 300, 500) offContext.fillRect(0, 0, 300, 500)
offContext.fillStyle = '#000000' offContext.fillStyle = '#000000'
offContext.font = '70px serif bold' offContext.font = '70px serif bold'
offContext.fillText("Offscreen : Hello World!", 20, 60) offContext.fillText("Offscreen : Hello World!", 20, 60)
var image = this.offCanvas.transferToImageBitmap() let image = this.offCanvas.transferToImageBitmap()
this.context.transferFromImageBitmap(image) this.context.transferFromImageBitmap(image)
}) })
} }
...@@ -197,7 +197,7 @@ struct OffscreenCanvasExamplePage { ...@@ -197,7 +197,7 @@ struct OffscreenCanvasExamplePage {
.height('100%') .height('100%')
.backgroundColor('#FFFFFF') .backgroundColor('#FFFFFF')
.onReady(() => { .onReady(() => {
var offContext = this.offscreenCanvas.getContext("2d", this.settings) let offContext = this.offscreenCanvas.getContext("2d", this.settings)
offContext.font = '70px sans-serif' offContext.font = '70px sans-serif'
offContext.fillText("Offscreen : Hello World!", 20, 60) offContext.fillText("Offscreen : Hello World!", 20, 60)
offContext.fillStyle = "#0000ff" offContext.fillStyle = "#0000ff"
...@@ -217,7 +217,7 @@ struct OffscreenCanvasExamplePage { ...@@ -217,7 +217,7 @@ struct OffscreenCanvasExamplePage {
offContext.stroke() offContext.stroke()
offContext.fillStyle = '#FF00FF' offContext.fillStyle = '#FF00FF'
offContext.fillRect(100, 100, 60, 60) offContext.fillRect(100, 100, 60, 60)
var imageData = this.offscreenCanvas.transferToImageBitmap() let imageData = this.offscreenCanvas.transferToImageBitmap()
this.context.transferFromImageBitmap(imageData) this.context.transferFromImageBitmap(imageData)
}) })
}.width('100%').height('100%') }.width('100%').height('100%')
......
...@@ -86,7 +86,7 @@ struct AlphabetIndexerSample { ...@@ -86,7 +86,7 @@ struct AlphabetIndexerSample {
Stack({ alignContent: Alignment.Start }) { Stack({ alignContent: Alignment.Start }) {
Row() { Row() {
List({ space: 20, initialIndex: 0 }) { List({ space: 20, initialIndex: 0 }) {
ForEach(this.arrayA, (item) => { ForEach(this.arrayA, (item: string) => {
ListItem() { ListItem() {
Text(item) Text(item)
.width('80%') .width('80%')
...@@ -94,9 +94,9 @@ struct AlphabetIndexerSample { ...@@ -94,9 +94,9 @@ struct AlphabetIndexerSample {
.fontSize(30) .fontSize(30)
.textAlign(TextAlign.Center) .textAlign(TextAlign.Center)
}.editable(true) }.editable(true)
}, item => item) }, (item: string) => item)
ForEach(this.arrayB, (item) => { ForEach(this.arrayB, (item: string) => {
ListItem() { ListItem() {
Text(item) Text(item)
.width('80%') .width('80%')
...@@ -104,9 +104,9 @@ struct AlphabetIndexerSample { ...@@ -104,9 +104,9 @@ struct AlphabetIndexerSample {
.fontSize(30) .fontSize(30)
.textAlign(TextAlign.Center) .textAlign(TextAlign.Center)
}.editable(true) }.editable(true)
}, item => item) }, (item: string) => item)
ForEach(this.arrayC, (item) => { ForEach(this.arrayC, (item: string) => {
ListItem() { ListItem() {
Text(item) Text(item)
.width('80%') .width('80%')
...@@ -114,9 +114,9 @@ struct AlphabetIndexerSample { ...@@ -114,9 +114,9 @@ struct AlphabetIndexerSample {
.fontSize(30) .fontSize(30)
.textAlign(TextAlign.Center) .textAlign(TextAlign.Center)
}.editable(true) }.editable(true)
}, item => item) }, (item: string) => item)
ForEach(this.arrayL, (item) => { ForEach(this.arrayL, (item: string) => {
ListItem() { ListItem() {
Text(item) Text(item)
.width('80%') .width('80%')
...@@ -124,7 +124,7 @@ struct AlphabetIndexerSample { ...@@ -124,7 +124,7 @@ struct AlphabetIndexerSample {
.fontSize(30) .fontSize(30)
.textAlign(TextAlign.Center) .textAlign(TextAlign.Center)
}.editable(true) }.editable(true)
}, item => item) }, (item: string) => item)
} }
.width('50%') .width('50%')
.height('100%') .height('100%')
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册