From d291ec217ded6960dff61e903e02c88a70655c72 Mon Sep 17 00:00:00 2001 From: Lince Liu <353627866@qq.com> Date: Fri, 14 Nov 2025 01:57:55 +0000 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20entry/sr?= =?UTF-8?q?c/main/ets/view/SliderComponent?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entry/src/main/ets/view/SliderComponent | 102 ------------------------ 1 file changed, 102 deletions(-) delete mode 100644 entry/src/main/ets/view/SliderComponent diff --git a/entry/src/main/ets/view/SliderComponent b/entry/src/main/ets/view/SliderComponent deleted file mode 100644 index 9315939..0000000 --- a/entry/src/main/ets/view/SliderComponent +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the 'License'); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an 'AS IS' BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -@Component -export struct SliderComponent { - @State x: number = 0; - @State positionX: number = 0; - @State offsetX: number = 0; - @State trackWidth: number = 350 - @State blockSize: number = 20 - @Link @Watch('onReturnChange') returnValue: number - @State @Watch('onChange') value: number = this.trackWidth / 2 - - aboutToAppear(): void { - this.value = this.returnValue * this.trackWidth / 200 + this.trackWidth / 2 - } - - onChange() { - let value = (this.value - this.trackWidth / 2) / (this.trackWidth / 200) - if (value > 100) { - this.returnValue = 100 - } else if (value < -100) { - this.returnValue = -100 - } else { - this.returnValue = Math.floor(value) - } - } - - onReturnChange() { - this.value = this.trackWidth / 2 + this.returnValue * (this.trackWidth / 200) - } - - build() { - Column() { - Stack({ alignContent: Alignment.Start }) { - Row() - .height(6) - .width('100%') - .backgroundColor('#1C1C1D') - .borderRadius(3) - - Row() - .height(6) - .width((this.value < 0 || this.value > this.trackWidth) ? this.trackWidth / 2 : - Math.abs(this.value - this.trackWidth / 2)) - .margin({ - left: this.value < 0 ? 0 : this.value > this.trackWidth ? this.trackWidth / 2 : - (this.value - this.trackWidth / 2) > 0 ? this.trackWidth / 2 : this.value - }) - .borderRadius(3) - .backgroundColor($r('sys.color.brand_font')) - - Row() - .height(this.blockSize) - .width(this.blockSize) - .borderRadius(this.blockSize / 2) - .backgroundColor(Color.White) - .margin({ - left: this.value < 0 ? 0 - this.blockSize / 2 : - this.value > this.trackWidth ? this.trackWidth - this.blockSize / 2 : this.value - this.blockSize / 2 - }) - .gesture( - PanGesture() - .onActionStart(() => { - this.x = this.value - }) - .onActionUpdate((event: GestureEvent | undefined) => { - if (event) { - this.offsetX = this.positionX + event.offsetX; - this.value = this.x + event.offsetX - } - }) - .onActionEnd(() => { - this.x = this.value - this.positionX = this.offsetX; - }) - ) - } - .gesture( - TapGesture({ count: 1 }) - .onAction((event: GestureEvent | undefined) => { - if (event) { - this.value = event.fingerList[0].localX; - } - })) - .height(this.blockSize) - .width(this.trackWidth) - } - } -} -- Gitee