添加Layout页面
This commit is contained in:
parent
aa78ceba6a
commit
c1387d9104
@ -1,17 +1,51 @@
|
|||||||
import { ComponentConst, TitleBar } from '@devwiki/common_ui';
|
import { ComponentConst, ScreenUtil, TitleBar } from '@devwiki/common_ui';
|
||||||
import { TitleBarMenuType } from '@devwiki/common_ui/src/main/ets/component/TitleBar';
|
import { TitleBarMenuType } from '@devwiki/common_ui/src/main/ets/component/TitleBar';
|
||||||
import { router } from '@kit.ArkUI';
|
import { router } from '@kit.ArkUI';
|
||||||
import { PageRouter } from './PageRouter';
|
import { PageRouter } from './PageRouter';
|
||||||
|
import { WebPage } from './WebPage';
|
||||||
|
|
||||||
|
@CustomDialog
|
||||||
|
struct WebViewDialog {
|
||||||
|
|
||||||
|
aboutToAppear(): void {
|
||||||
|
ScreenUtil.getInstance().initScreenSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
dialogController: CustomDialogController = new CustomDialogController({
|
||||||
|
builder: WebViewDialog({})
|
||||||
|
});
|
||||||
|
|
||||||
|
build() {
|
||||||
|
WebPage().height('100%').width('50%')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Entry
|
@Entry
|
||||||
@Component
|
@Component
|
||||||
struct Index {
|
struct Index {
|
||||||
@State title: string = "Home";
|
@State title: string = "Home";
|
||||||
|
dialogController: CustomDialogController = new CustomDialogController({
|
||||||
|
builder: WebViewDialog(),
|
||||||
|
alignment: DialogAlignment.CenterEnd,
|
||||||
|
customStyle: true
|
||||||
|
})
|
||||||
|
|
||||||
onTitleBarLeftClick(_event: ClickEvent) {
|
onTitleBarLeftClick(_event: ClickEvent) {
|
||||||
this.getUIContext().getRouter().back();
|
this.getUIContext().getRouter().back();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
onButtonClicked() {
|
||||||
|
this.dialogController.open();
|
||||||
|
|
||||||
|
// router.pushUrl({
|
||||||
|
// // 两种方式都可以加载Page, 一个是和 resources/base/profile/main_pages.ets中的配置相同
|
||||||
|
// // 一个是绝对路径
|
||||||
|
// // url: "pages/WebPage",
|
||||||
|
// url: PageRouter.WebPage
|
||||||
|
// }, router.RouterMode.Single);
|
||||||
|
}
|
||||||
|
|
||||||
build() {
|
build() {
|
||||||
Column() {
|
Column() {
|
||||||
RelativeContainer() {
|
RelativeContainer() {
|
||||||
@ -24,29 +58,28 @@ struct Index {
|
|||||||
.alignRules({
|
.alignRules({
|
||||||
top: { anchor: ComponentConst.ContainerId, align: VerticalAlign.Top },
|
top: { anchor: ComponentConst.ContainerId, align: VerticalAlign.Top },
|
||||||
left: { anchor: ComponentConst.ContainerId, align: HorizontalAlign.Start }
|
left: { anchor: ComponentConst.ContainerId, align: HorizontalAlign.Start }
|
||||||
}).id("title_bar");
|
}).id("title_bar"); //必须要设置id 否则不显示
|
||||||
|
|
||||||
Divider().alignRules({
|
Divider().alignRules({
|
||||||
top: { anchor: "title_bar", align: VerticalAlign.Bottom },
|
top: { anchor: "title_bar", align: VerticalAlign.Bottom },
|
||||||
left: { anchor: ComponentConst.ContainerId, align: HorizontalAlign.Start }
|
left: { anchor: ComponentConst.ContainerId, align: HorizontalAlign.Start }
|
||||||
}).width('100%').id("divider")
|
}).width('100%').id("divider") //必须要设置id 否则不显示
|
||||||
|
|
||||||
Column() {
|
Column({ space: 8 }) {
|
||||||
Button("WebPage").align(Alignment.Center).height(36).width(80).onClick(() => {
|
Row({ space: 8 }) {
|
||||||
router.pushUrl({
|
Button("WebPage").type(ButtonType.Capsule).align(Alignment.Center).height(36).width(80).onClick(() => {
|
||||||
// 两种方式都可以加载Page, 一个是和 resources/base/profile/main_pages.ets中的配置相同
|
this.onButtonClicked();
|
||||||
// 一个是绝对路径
|
})
|
||||||
// url: "pages/WebPage",
|
}.width(36);
|
||||||
url: PageRouter.WebPage
|
Row().height(36);
|
||||||
}, router.RouterMode.Single);
|
Row().width(36);
|
||||||
})
|
|
||||||
}
|
}
|
||||||
.width('100%')
|
.width('100%')
|
||||||
.alignRules({
|
.alignRules({
|
||||||
top: { anchor: "divider", align: VerticalAlign.Bottom },
|
top: { anchor: "divider", align: VerticalAlign.Bottom },
|
||||||
left: { anchor: ComponentConst.ContainerId, align: HorizontalAlign.Start },
|
left: { anchor: ComponentConst.ContainerId, align: HorizontalAlign.Start },
|
||||||
bottom: { anchor: ComponentConst.ContainerId, align: VerticalAlign.Bottom }
|
bottom: { anchor: ComponentConst.ContainerId, align: VerticalAlign.Bottom }
|
||||||
}).id("host_web")
|
}).id("host_web") //必须要设置id 否则不显示
|
||||||
}.width('100%').height('100%')
|
}.width('100%').height('100%')
|
||||||
}.width('100%').height('100%')
|
}.width('100%').height('100%')
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
|
|
||||||
export class PageRouter{
|
export class PageRouter{
|
||||||
static readonly WebPage: string = "@bundle:net.devwiki.hm4demo/app/ets/pages/WebPage"
|
static readonly WebPage: string = "@bundle:net.devwiki.hm4demo/app/ets/pages/WebPage"
|
||||||
}
|
}
|
||||||
|
@ -5,3 +5,4 @@ export { Emitter } from './src/main/ets/event/Emitter'
|
|||||||
export { WebView, WebViewController } from './src/main/ets/component/web/WebView'
|
export { WebView, WebViewController } from './src/main/ets/component/web/WebView'
|
||||||
|
|
||||||
export { CommonRes } from './src/main/ets/utils/CommonRes'
|
export { CommonRes } from './src/main/ets/utils/CommonRes'
|
||||||
|
export { ScreenUtil } from './src/main/ets/utils/ScreenUtil'
|
||||||
|
@ -73,20 +73,20 @@ export struct TitleBar {
|
|||||||
if (this.titleVisible == Visibility.Visible) {
|
if (this.titleVisible == Visibility.Visible) {
|
||||||
Text(this.title)
|
Text(this.title)
|
||||||
.textAlign(this.titleTextAlign)
|
.textAlign(this.titleTextAlign)
|
||||||
.margin({
|
.backgroundColor(0xFFFFFF)
|
||||||
left: this.leftMenuType != TitleBarMenuType.None ? this.barHeight : 0,
|
.padding({
|
||||||
right: this.leftMenuType != TitleBarMenuType.None ? this.barHeight : 0
|
left: this.leftMenuType != TitleBarMenuType.None ? 0 : this.menuPadding,
|
||||||
|
right: this.rightMenuType != TitleBarMenuType.None ? 0 : this.menuPadding
|
||||||
})
|
})
|
||||||
.padding({left: this.leftMenuType != TitleBarMenuType.None ? 0 : this.menuPadding})
|
|
||||||
.alignRules({
|
.alignRules({
|
||||||
top: { anchor: ComponentConst.ContainerId, align: VerticalAlign.Top },
|
top: { anchor: ComponentConst.ContainerId, align: VerticalAlign.Top },
|
||||||
left: {
|
left: {
|
||||||
anchor: this.leftMenuType != TitleBarMenuType.None ? "left_menu" : ComponentConst.ContainerId,
|
anchor: this.leftMenuType != TitleBarMenuType.None ? "left_menu" : ComponentConst.ContainerId,
|
||||||
align: HorizontalAlign.Start
|
align: this.leftMenuType != TitleBarMenuType.None ? HorizontalAlign.End : HorizontalAlign.Start
|
||||||
},
|
},
|
||||||
right: {
|
right: {
|
||||||
anchor: this.leftMenuType != TitleBarMenuType.None ? "right_menu" : ComponentConst.ContainerId,
|
anchor: this.leftMenuType != TitleBarMenuType.None ? "right_menu" : ComponentConst.ContainerId,
|
||||||
align: HorizontalAlign.End
|
align: this.leftMenuType != TitleBarMenuType.None ? HorizontalAlign.Start : HorizontalAlign.End
|
||||||
},
|
},
|
||||||
bottom: { anchor: ComponentConst.ContainerId, align: VerticalAlign.Bottom }
|
bottom: { anchor: ComponentConst.ContainerId, align: VerticalAlign.Bottom }
|
||||||
})
|
})
|
||||||
|
16
common_ui/src/main/ets/pages/layout/LinearLayoutPage.ets
Normal file
16
common_ui/src/main/ets/pages/layout/LinearLayoutPage.ets
Normal 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%')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
101
common_ui/src/main/ets/utils/ScreenUtil.ets
Normal file
101
common_ui/src/main/ets/utils/ScreenUtil.ets
Normal file
@ -0,0 +1,101 @@
|
|||||||
|
import window from '@ohos.window';
|
||||||
|
|
||||||
|
export class ScreenUtil {
|
||||||
|
// TODO: 工具待抽离, key统一定义
|
||||||
|
static readonly isPortraitKey: string = "xy_screen_is_portrait";
|
||||||
|
private static instance: ScreenUtil;
|
||||||
|
public width: number = 0
|
||||||
|
public height: number = 0
|
||||||
|
public statusBarHeight: number = 0
|
||||||
|
public bottomSafeHeight: number = 0
|
||||||
|
public contentHeight: number = 0;
|
||||||
|
|
||||||
|
public layoutWidth: number = 0
|
||||||
|
public layoutHeight: number = 0
|
||||||
|
|
||||||
|
|
||||||
|
public static getInstance(): ScreenUtil {
|
||||||
|
if (!ScreenUtil.instance) {
|
||||||
|
ScreenUtil.instance = new ScreenUtil();
|
||||||
|
}
|
||||||
|
return ScreenUtil.instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
initScreenSize(): void {
|
||||||
|
window.getLastWindow(getContext(this))
|
||||||
|
.then((windowClass: window.Window) => {
|
||||||
|
let type = window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR; // 以导航条避让为例
|
||||||
|
let avoidArea = windowClass.getWindowAvoidArea(type);
|
||||||
|
this.bottomSafeHeight = px2vp(avoidArea.bottomRect.height); // 获取到导航条区域的高度
|
||||||
|
type = window.AvoidAreaType.TYPE_SYSTEM;
|
||||||
|
avoidArea = windowClass.getWindowAvoidArea(type);
|
||||||
|
this.statusBarHeight = px2vp(avoidArea.topRect.height);
|
||||||
|
this.width = px2vp(windowClass.getWindowProperties().windowRect.width);
|
||||||
|
this.height = px2vp(windowClass.getWindowProperties().windowRect.height);
|
||||||
|
this.layoutWidth = this.width;
|
||||||
|
this.layoutHeight = this.height - this.statusBarHeight - this.bottomSafeHeight;
|
||||||
|
})
|
||||||
|
.catch((error: Error) => {
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
setPreferredOrientation(orientation: window.Orientation): void {
|
||||||
|
window.getLastWindow(getContext(this))
|
||||||
|
.then((windowClass: window.Window) => {
|
||||||
|
windowClass.setPreferredOrientation(orientation);
|
||||||
|
AppStorage.setOrCreate(ScreenUtil.isPortraitKey, orientation == window.Orientation.PORTRAIT || orientation == window.Orientation.PORTRAIT_INVERTED);
|
||||||
|
})
|
||||||
|
.catch((error: Error) => {
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
setPreferredOrientationCallBack(orientation: window.Orientation, callback: ()=>void): void{
|
||||||
|
window.getLastWindow(getContext(this))
|
||||||
|
.then((windowClass: window.Window) => {
|
||||||
|
windowClass.setPreferredOrientation(orientation,callback);
|
||||||
|
AppStorage.setOrCreate(ScreenUtil.isPortraitKey, orientation == window.Orientation.PORTRAIT || orientation == window.Orientation.PORTRAIT_INVERTED);
|
||||||
|
})
|
||||||
|
.catch((error: Error) => {
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
setWindowLayoutFullScreen(isLayoutFullScreen: boolean): void {
|
||||||
|
window.getLastWindow(getContext(this))
|
||||||
|
.then((windowClass: window.Window) => {
|
||||||
|
windowClass.setWindowLayoutFullScreen(isLayoutFullScreen);
|
||||||
|
windowClass.setSpecificSystemBarEnabled('status', !isLayoutFullScreen);
|
||||||
|
})
|
||||||
|
.catch((error: Error) => {
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
setWindowSystemBarProperties(systemBarProperties: window.SystemBarProperties): void {
|
||||||
|
window.getLastWindow(getContext(this))
|
||||||
|
.then((windowClass: window.Window) => {
|
||||||
|
windowClass.setWindowSystemBarProperties(systemBarProperties, (err) => {
|
||||||
|
if (err.code) {
|
||||||
|
console.error('Failed to set the system bar properties. Cause: ' + JSON.stringify(err));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
console.info('Succeeded in setting the system bar properties.');
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch((error: Error) => {
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
setWindowSystemBarEnable(names:Array<'status' | 'navigation'>){
|
||||||
|
window.getLastWindow(getContext(this))
|
||||||
|
.then((windowClass: window.Window) => {
|
||||||
|
windowClass.setWindowSystemBarEnable(names, (err) => {
|
||||||
|
if (err.code) {
|
||||||
|
console.error('Failed to set the system bar properties. Cause: ' + JSON.stringify(err));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
console.info('Succeeded in setting the system bar properties.');
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch((error: Error) => {
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user