diff --git a/display/entry/src/main/ets/pages/ConfirmDialog.ets b/display/entry/src/main/ets/pages/ConfirmDialog.ets index 5d5cd6e50ed773357223a58eed0f9c8354353d40..93269fa1221cdd98e541f0b2fccb7e44a4d74a0a 100644 --- a/display/entry/src/main/ets/pages/ConfirmDialog.ets +++ b/display/entry/src/main/ets/pages/ConfirmDialog.ets @@ -58,9 +58,9 @@ struct ConfirmCustomDialog { @State isProxy: boolean = false; @State appDataList: AppData[] = []; @State selectedAppDataList: AppSendData[] = []; - @State isFoldable: boolean = display.isFoldable(); - @State isFolded: display.FoldStatus = display.getFoldStatus(); - @State mLocalHeight: number = display.getDefaultDisplaySync().height; + @State isFoldable: boolean = false; + @State isFolded: display.FoldStatus = display.FoldStatus.FOLD_STATUS_UNKNOWN; + @State mLocalHeight: number = 1; @State currentOrientation: window.Orientation = window.Orientation.UNSPECIFIED; @State marginValue: number = 0; @State fontSizeScale: number = AppStorage.get('fontSizeScale') as number; @@ -95,6 +95,24 @@ struct ConfirmCustomDialog { } aboutToAppear() { + try { + this.isFoldable = display.isFoldable(); + } catch (err) { + console.error('Failed to get isFoldable:', err); + } + + try { + this.isFolded = display.getFoldStatus(); + } catch (err) { + console.error('Failed to get FoldStatus:', err); + } + + try { + this.mLocalHeight = display.getDefaultDisplaySync().height; + } catch (err) { + console.error('Failed to get display height:', err); + } + this.updateOrientation(); this.getDeviceType(); this.appDataList = this.getAppDataList(); @@ -179,18 +197,30 @@ struct ConfirmCustomDialog { this.listener.on('change', () => { this.updateOrientation(); - this.mLocalHeight = display.getDefaultDisplaySync().height; - }); - display.on('foldDisplayModeChange', () => { - this.updateFoldState(); + try { + this.mLocalHeight = display.getDefaultDisplaySync().height; + } catch (err) { + console.error('Failed to get display height:', err); + } }); + try { + display.on('foldDisplayModeChange', () => { + this.updateFoldState(); + }); + } catch (err) { + console.error('Failed to register event listener:', err); + } } aboutToDisappear() { if (this.listener) { this.listener.off('change'); } - display.off('foldDisplayModeChange'); + try { + display.off('foldDisplayModeChange'); + } catch (err) { + console.error('Failed to remove foldDisplayModeChange listener:', err); + } clearInterval(this.times); }