diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index 2e7fa74d83892f52636a94d46aedaf8a476a9a01..158c43a564e01160d79207f0d8fdf7446ffeda03 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -118,7 +118,7 @@ struct Index { .onClick((event?:ClickEvent) => { let path = 'pages/OtherApi' console.log("jump:" + path); - router.push({ + router.pushUrl({ url: path, }); }) diff --git a/entry/src/main/ets/pages/OtherApi.ets b/entry/src/main/ets/pages/OtherApi.ets index d6489900017e7558e639211fd09cc3df100448a5..ffaa660a42309362a04560583ca27247b8ee8233 100644 --- a/entry/src/main/ets/pages/OtherApi.ets +++ b/entry/src/main/ets/pages/OtherApi.ets @@ -17,7 +17,8 @@ import { SubsamplingScaleImageView} from '@ohos/subsampling-scale-image-view'; import prompt from '@system.prompt'; import router from '@ohos.router'; -let that:ESObject; +let model:SubsamplingScaleImageView.Model; +let mRotate: number @Entry @ComponentV2 struct OtherApi { @@ -34,25 +35,25 @@ struct OtherApi { onAccept(index:number) { if (index == 0) { - that.model.setZoomEnabled(false) + model.setZoomEnabled(false) } else if (index == 1) { - that.model.setZoomEnabled(true) + model.setZoomEnabled(true) } else if (index == 2) { - that.model.setQuickScaleEnabled(true) + model.setQuickScaleEnabled(true) }else if(index == 3){ prompt.showToast({ - message: 'Image width:'+that.model.getSWidth()+" height:"+that.model.getSHeight(), + message: 'Image width:'+model.getSWidth()+" height:"+model.getSHeight(), duration: 2000, }); }else if (index == 4) { - that.mRotate += 90; - that.model.setOrientation(that.mRotate) + mRotate += 90; + model.setOrientation(mRotate) } else if (index == 5) { - that.model.resetScaleAndCenter() + model.resetScaleAndCenter() }else if(index == 6) { - that.model.setPanEnabled(false) + model.setPanEnabled(false) }else if (index == 7) { - that.model.setPanEnabled(true) + model.setPanEnabled(true) } } @@ -60,14 +61,15 @@ struct OtherApi { console.debug('Click the callback in the blank area') } aboutToAppear() { - that = this; + model = this.model; + mRotate = this.mRotate this.model.setImage($r('app.media.sanmartino')).setScale(1).setMaxScale(3).setTileBackgroundColor(0XFF090909); } onPageShow(){ setTimeout(()=>{ - console.debug("SubsamplingScaleImageView isImageLoaded:"+that.model.isImageLoaded()) - console.debug("SubsamplingScaleImageView state:"+JSON.stringify(that.model.getState())) + console.debug("SubsamplingScaleImageView isImageLoaded:"+ model.isImageLoaded()) + console.debug("SubsamplingScaleImageView state:"+JSON.stringify(model.getState())) },1000) } @@ -106,7 +108,7 @@ struct OtherApi { @CustomDialog struct CustomDialogExample { controller: CustomDialogController = new CustomDialogController({builder:()=>{}}); - confirm: ESObject|null = null; + confirm?: (num: number) => void build() { Column() { @@ -128,7 +130,7 @@ struct CustomDialogExample { .margin({ top: 10 }) .onClick(() => { if(!!this.controller) this.controller.close() - this.confirm(1) + if(!!this.confirm) this.confirm(1) }) Text('ENABLE QuickScale') .width('100%') @@ -138,7 +140,7 @@ struct CustomDialogExample { .margin({ top: 10 }) .onClick(() => { if(!!this.controller) this.controller.close() - this.confirm(2) + if(!!this.confirm) this.confirm(2) }) Text('Image width/height') .width('100%') @@ -148,7 +150,7 @@ struct CustomDialogExample { .margin({ top: 10 }) .onClick(() => { if(!!this.controller) this.controller.close() - this.confirm(3) + if(!!this.confirm) this.confirm(3) }) Text('Rotate') .width('100%') @@ -158,7 +160,7 @@ struct CustomDialogExample { .margin({ top: 10 }) .onClick(() => { if(!!this.controller) this.controller.close() - this.confirm(4) + if(!!this.confirm) this.confirm(4) }) Text('Reset Scale') .width('100%') @@ -168,7 +170,7 @@ struct CustomDialogExample { .margin({ top: 10 }) .onClick(() => { if(!!this.controller) this.controller.close() - this.confirm(5) + if(!!this.confirm) this.confirm(5) }) Text('Disable Pan') .width('100%') @@ -178,7 +180,7 @@ struct CustomDialogExample { .margin({ top: 10 }) .onClick(() => { if(!!this.controller) this.controller.close() - this.confirm(6) + if(!!this.confirm) this.confirm(6) }) Text('Enable Pan') .width('100%') @@ -188,7 +190,7 @@ struct CustomDialogExample { .margin({ top: 10 }) .onClick(() => { if(!!this.controller) this.controller.close() - this.confirm(7) + if(!!this.confirm) this.confirm(7) }) }.backgroundColor(0x3d3d3d) }