添加横竖屏切换及监听

This commit is contained in:
2024-04-07 23:50:37 +08:00
parent a8af14eb3c
commit 5e4df7785f
4 changed files with 30 additions and 15 deletions

View File

@@ -1,40 +1,48 @@
import { ComponentConst, ScreenUtil, TitleBar } from '@devwiki/common_ui';
import { TitleBarMenuType } from '@devwiki/common_ui/src/main/ets/component/TitleBar';
import { router } from '@kit.ArkUI';
import { PageRouter } from './PageRouter';
import { WebPage } from './WebPage';
import { window } from '@kit.ArkUI';
@CustomDialog
struct WebViewDialog {
aboutToAppear(): void {
ScreenUtil.getInstance().initScreenSize();
}
showHeight: Length = '50%';
dialogController: CustomDialogController = new CustomDialogController({
builder: WebViewDialog({})
});
build() {
WebPage().height('100%').width('50%')
WebPage({onTitleBarLeftClick: ()=> {
this.dialogController.close();
}}).height(this.showHeight).width('100%')
}
}
@Entry
@Component
struct Index {
@State title: string = "Home";
@StorageLink(ScreenUtil.isPortraitKey)isPortrait: boolean = true;
dialogController: CustomDialogController = new CustomDialogController({
builder: WebViewDialog(),
alignment: DialogAlignment.CenterEnd,
builder: WebViewDialog({showHeight: this.isPortrait ? '95%' : '50%'}),
alignment: DialogAlignment.BottomEnd,
customStyle: true
})
aboutToAppear(): void {
ScreenUtil.getInstance().initScreenSize();
}
onPageShow(): void {
ScreenUtil.getInstance().setPreferredOrientation(window.Orientation.AUTO_ROTATION_PORTRAIT);
}
onTitleBarLeftClick(_event: ClickEvent) {
this.getUIContext().getRouter().back();
}
onButtonClicked() {
this.dialogController.open();
@@ -72,7 +80,7 @@ struct Index {
GridItem() {
Button("WebPage").type(ButtonType.Capsule).height(32).width(80)
.onClick(() => { });
.onClick(() => { this.dialogController.open() });
}.rowStart(0).rowEnd(0).columnStart(1).columnEnd(1)
GridItem() {

View File

@@ -11,9 +11,7 @@ export struct WebPage {
this.webViewController = new WebPageController(this.viewModel);
}
onTitleBarLeftClick(event: ClickEvent) {
this.getUIContext().getRouter().back();
}
onTitleBarLeftClick?: Function;
onTitleBarRightClick(event: ClickEvent) {
this.webViewController?.refresh();

View File

@@ -0,0 +1,16 @@
@Entry
@Component
struct LinearLayoutPage {
@State space: number = 10;
build() {
Column({ space: this.space }) {
Text(`space:${this.space}`)
Row().width('90%')
Row().width('90%')
Row().width('90%')
}
}
}