1/* 2 * Copyright (c) 2022-2023 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 { BroadCast, Constants } from '@ohos/common'; 17 18@Component 19export struct ActionButton { 20 src: Resource = $r('app.media.alt_placeholder'); 21 text: Resource | null = null; 22 textSize: number | Resource = $r('app.float.buttonActionTextSize_default'); 23 isActive: boolean = false; 24 actionID: number = Constants.NEGATIVE_1; 25 sizeDefault: number | Resource = $r('app.float.ic_size_default'); 26 heightOfActionButton: number | Resource = $r('app.float.actionButton_default'); 27 widthOfActionButton: number | Resource = $r('app.float.actionButton_default'); 28 isCropStyleButton: boolean = false; 29 @Consume broadCast: BroadCast; 30 componentKey: string = ''; 31 32 aboutToAppear() { 33 if (this.text == undefined) { 34 this.heightOfActionButton = $r('app.float.buttonWithoutText'); 35 this.widthOfActionButton = $r('app.float.buttonWithoutText'); 36 } 37 } 38 39 build() { 40 Flex({ 41 direction: FlexDirection.Column, 42 justifyContent: FlexAlign.Center, 43 alignItems: ItemAlign.Center 44 }) { 45 if (this.text != undefined) { 46 // 图标+文字的ActionButton 47 Image(this.src) 48 .width(this.sizeDefault) 49 .height(this.sizeDefault) 50 .fillColor(this.isActive ? $r('app.color.photo_edit_active_color') : $r('app.color.default_white_color')) 51 Row() { 52 Text(this.text) 53 .fontSize(this.textSize) 54 .fontColor(this.isActive 55 ? $r('app.color.photo_edit_active_color') : $r('app.color.default_white_color')) 56 } 57 .margin({ 58 top: $r('app.float.actionBar_margin'), 59 left: $r('app.float.actionBar_margin'), 60 right: $r('app.float.actionBar_margin') 61 }) 62 } else { 63 Image(this.src) 64 .width(this.sizeDefault) 65 .height(this.sizeDefault) 66 .objectFit(ImageFit.Contain) 67 .fillColor(this.isActive ? $r('app.color.photo_edit_active_color') : $r('app.color.default_white_color')) 68 69 } 70 } 71 .height(this.text != undefined ? this.heightOfActionButton : this.sizeDefault) 72 .width(this.text != undefined ? this.widthOfActionButton : this.sizeDefault) 73 .key('ActionButton' + this.componentKey) 74 .onClick(() => { 75 this.broadCast.emit(Constants.UPDATE_MENU, [this.actionID]); 76 }) 77 } 78}