1/* 2 * Copyright (c) 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 16/** 17 * ...等待轮播 18 * 19 * @since 2022-07-07 20 */ 21@Component 22export struct CheckingDots { 23 @Prop @Watch('onDotTextPlayChange') 24 private dotTextPlay: boolean; 25 private newVersionDotText: string= '.'; 26 private checkingTid: number = null; 27 @State private dotNumber: number = 0; 28 29 aboutToDisappear() { 30 this.clearCheckingTid(); 31 } 32 33 aboutToAppear() { 34 this.onDotTextPlayChange(); 35 } 36 37 /** 38 * bind dotTextPlay 39 * change running play 40 */ 41 private onDotTextPlayChange() { 42 if (this.dotTextPlay) { 43 this.cycleDisplay(); 44 } else { 45 this.clearCheckingTid(); 46 } 47 } 48 49 private clearCheckingTid(): void { 50 if (this.checkingTid != null) { 51 clearInterval(this.checkingTid); 52 this.checkingTid = null; 53 } 54 } 55 56 /** 57 * loop newVersionDotText with CHECKING_DOTS array. 58 */ 59 private cycleDisplay(): void { 60 if (this.checkingTid == null) { 61 let index = 0; 62 this.dotNumber = index; 63 this.checkingTid = setInterval(() => { 64 this.dotNumber = index++%3; 65 }, 500); 66 } 67 } 68 69 @Builder dotText(visibility: Visibility) { 70 Text(this.newVersionDotText) 71 .fontSize($r('app.float.text_size_body')) 72 .fontColor(Color.Black) 73 .opacity(0.6) 74 .fontWeight(FontWeight.Regular) 75 .align(Alignment.Start) 76 .maxLines(1) 77 .textOverflow({ overflow: TextOverflow.None }) 78 .visibility(visibility) 79 } 80 81 build() { 82 Row() { 83 if (this.dotTextPlay) { 84 this.dotText(Visibility.Visible) 85 if (this.dotNumber >= 1) { 86 this.dotText(Visibility.Visible) 87 } else { 88 this.dotText(Visibility.Hidden) 89 } 90 if (this.dotNumber == 2) { 91 this.dotText(Visibility.Visible) 92 } else { 93 this.dotText(Visibility.Hidden) 94 } 95 } 96 } 97 } 98}