@@ -15,24 +15,30 @@ import { WebNodeHandleWindow } from 'web_engine';
1515import { NativeContext } from 'web_engine/src/main/ets/interface/CommonInterface';
1616import JsBindingUtils from 'web_engine/src/main/ets/utils/JsBindingUtils';
1717import { ContextType } from 'web_engine/src/main/ets/common/Constants';
18+ import { uiObserver } from '@kit.ArkUI';
1819
19- @Entry
20+ let storage = LocalStorage.getShared();
21+ @Entry(storage)
2022@Component
2123struct NodeHandleWindow {
2224 @LocalStorageLink('xcomponentId') xComponentId: string = '';
2325 @LocalStorageProp('statusBarHeight') statusBarHeight: number = 0;
26+ @State density: number = 0;
2427 private nativeContext: NativeContext =
2528 JsBindingUtils.getNativeContext(ContextType.kMainProcess);
2629
2730 aboutToAppear(): void {
28- // WebNodeHandleWindow and the native context are managed by web_engine.
29- // No manual initialization needed here.
31+ uiObserver.on('densityUpdate', this.getUIContext(), (info: uiObserver.DensityInfo) => {
32+ this.density = info.density;
33+ });
34+ }
35+
36+ aboutToDisappear(): void {
37+ uiObserver.off('densityUpdate', this.getUIContext());
3038 }
3139
3240 onBackPress(): boolean {
33- if (this.nativeContext) {
34- this.nativeContext.OnBackToLastPage(this.xComponentId);
35- }
41+ this.nativeContext.OnBackToLastPage(this.xComponentId);
3642 return true;
3743 }
3844
@@ -42,5 +48,12 @@ struct NodeHandleWindow {
4248 }
4349 .width('100%')
4450 .height('100%')
51+ .padding({
52+ top: this.getStatusBarHeight(),
53+ })
54+ }
55+
56+ getStatusBarHeight(): number {
57+ return this.getUIContext().px2vp(this.statusBarHeight);
4558 }
4659}
0 commit comments