diff --git a/customappbar/interfaces/custom_app_bar.js b/customappbar/interfaces/custom_app_bar.js index b509c682656a58ab69b23440fb1e7545b2b5afb4..9cc6eb3db55d8f117b9736dd438c4a8c1e532f9c 100644 --- a/customappbar/interfaces/custom_app_bar.js +++ b/customappbar/interfaces/custom_app_bar.js @@ -148,8 +148,6 @@ export class CustomAppBar extends ViewPU { this.bundleName = ''; this.icon = { 'id': -1, 'type': 20000, params: ['sys.media.ohos_app_icon'], 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' }; this.fullContentMarginTop = 0; - this.windowWidth = 0; - this.windowHeight = 0; this.deviceBorderRadius = '0'; this.smListener = mediaquery.matchMediaSync('(0vp this.windowHeight ? this.windowHeight * LG_WIDTH_LIMIT : this.windowWidth * LG_WIDTH_LIMIT; + let displayData = display.getDefaultDisplaySync(); + let windowWidth = px2vp(displayData.width); + let windowHeight = px2vp(displayData.height); + this.containerWidth = windowWidth > windowHeight ? windowHeight * LG_WIDTH_LIMIT : windowWidth * LG_WIDTH_LIMIT; } } } diff --git a/customappbar/source/custom_app_bar.ets b/customappbar/source/custom_app_bar.ets index d094653fbb56c0e12a57f46f693b6b5be6f852ea..85966f9dea27ff21282d9fe72e3dba094ed24bbc 100644 --- a/customappbar/source/custom_app_bar.ets +++ b/customappbar/source/custom_app_bar.ets @@ -160,8 +160,6 @@ export struct CustomAppBar { @State labelName: string = ''; private icon: Resource | string | PixelMap = $r('sys.media.ohos_app_icon'); private fullContentMarginTop: number = 0; - private windowWidth: number = 0; - private windowHeight: number = 0; private deviceBorderRadius: string = '0'; private smListener: mediaquery.MediaQueryListener = mediaquery.matchMediaSync('(0vp this.windowHeight ? this.windowHeight * LG_WIDTH_LIMIT : this.windowWidth * LG_WIDTH_LIMIT; + let displayData = display.getDefaultDisplaySync(); + let windowWidth = px2vp(displayData.width); + let windowHeight = px2vp(displayData.height); + this.containerWidth = windowWidth > windowHeight ? windowHeight * LG_WIDTH_LIMIT : windowWidth * LG_WIDTH_LIMIT; } } }