1/* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16import router from '@system.router' 17import screenManager from '@ohos/base/src/main/ets/manager/ScreenManager' 18import { Constants } from '../../model/common/Constants' 19 20@Observed 21export class EditExitDialogCallback { 22 discardCallback: Function 23} 24 25@CustomDialog 26export struct EditExitDialog { 27 @Consume editExitDialogCallback: EditExitDialogCallback; 28 @StorageLink('isHorizontal') isHorizontal: boolean = screenManager.isHorizontal(); 29 @StorageLink('isSidebar') isSidebar: boolean = screenManager.isSidebar(); 30 @StorageLink('leftBlank') leftBlank: [number, number, number, number] = [0, 0, 0, 0]; 31 controller: CustomDialogController; 32 33 build() { 34 Column() { 35 Stack({ alignContent: Alignment.Center }) { 36 Text($r('app.string.edit_exit_dialog_context_text')) 37 .fontSize($r('sys.float.ohos_id_text_size_body1')) 38 .fontColor($r('sys.color.ohos_id_color_text_primary')) 39 }.width('100%') 40 .margin({ 41 top: $r('app.float.dialog_content_margin'), 42 bottom: $r('sys.float.ohos_id_text_paragraph_margin_s') 43 }) 44 45 Stack({ alignContent: Alignment.Top }) { 46 Row() { 47 Button() { 48 Text($r('app.string.save_dialog_cancel_text')) 49 .fontSize($r('sys.float.ohos_id_text_size_button1')) 50 .fontColor($r('app.color.color_control_highlight')) 51 .fontWeight(FontWeight.Medium) 52 .width('50%') 53 .textAlign(TextAlign.Center) 54 } 55 .margin({ 56 left: $r('app.float.details_dialog_button_margin_left'), 57 right: $r('app.float.details_dialog_button_margin_right') 58 }) 59 .backgroundColor($r('app.color.transparent')) 60 .height($r('app.float.details_dialog_button_height')) 61 .onClick(() => { 62 this.controller.close(); 63 }) 64 65 Row() { 66 Divider() 67 .vertical(true) 68 .height($r('app.float.dialog_divider_height')) 69 .color($r('app.color.divider_vertical_color')) 70 } 71 .height($r('app.float.details_dialog_button_height')) 72 .alignItems(VerticalAlign.Center) 73 74 Button() { 75 Text($r('app.string.edit_exit_dialog_discard_text')) 76 .fontSize($r('sys.float.ohos_id_text_size_button1')) 77 .fontColor($r('app.color.color_control_highlight')) 78 .fontWeight(FontWeight.Medium) 79 .width('50%') 80 .textAlign(TextAlign.Center) 81 } 82 .margin({ 83 left: $r('app.float.details_dialog_button_margin_left'), 84 right: $r('app.float.details_dialog_button_margin_right') 85 }) 86 .backgroundColor($r('app.color.transparent')) 87 .height($r('app.float.details_dialog_button_height')) 88 .onClick(() => { 89 this.controller.close(); 90 this.editExitDialogCallback && this.editExitDialogCallback.discardCallback(); 91 router.back() 92 }) 93 } 94 } 95 .width('100%') 96 .height($r('app.float.details_dialog_button_area_height')) 97 } 98 .borderRadius($r('app.float.dialog_border_radius')) 99 .width(screenManager.getColumnsWidth(4)) 100 .backgroundColor($r('app.color.white')) 101 .margin({ 102 right: $r('app.float.dialog_window_margin'), 103 left: $r('app.float.dialog_window_margin'), 104 bottom: this.isHorizontal || this.isSidebar ? 0 : Constants.DIALOG_BOTTOM_OFFSET + px2vp(this.leftBlank[3]) 105 }) 106 .padding({ left: $r('app.float.dialog_content_margin'), right: $r('app.float.dialog_content_margin') }) 107 .alignItems(HorizontalAlign.Start) 108 } 109}