100aff185Sopenharmony_ci/* 200aff185Sopenharmony_ci * Copyright (c) 2022-2023 Huawei Device Co., Ltd. 300aff185Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 400aff185Sopenharmony_ci * you may not use this file except in compliance with the License. 500aff185Sopenharmony_ci * You may obtain a copy of the License at 600aff185Sopenharmony_ci * 700aff185Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 800aff185Sopenharmony_ci * 900aff185Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1000aff185Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1100aff185Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1200aff185Sopenharmony_ci * See the License for the specific language governing permissions and 1300aff185Sopenharmony_ci * limitations under the License. 1400aff185Sopenharmony_ci */ 1500aff185Sopenharmony_ci 1600aff185Sopenharmony_ciimport { Log } from '../utils/Log'; 1700aff185Sopenharmony_ci 1800aff185Sopenharmony_ciconst TAG: string = 'common_GridScrollBar'; 1900aff185Sopenharmony_ci 2000aff185Sopenharmony_ci@Component 2100aff185Sopenharmony_ciexport struct GridScrollBar { 2200aff185Sopenharmony_ci scroller: Scroller | null = null; 2300aff185Sopenharmony_ci @State isClickScrollBar: boolean = false; 2400aff185Sopenharmony_ci 2500aff185Sopenharmony_ci build() { 2600aff185Sopenharmony_ci ScrollBar({ scroller: this.scroller as Scroller, direction: ScrollBarDirection.Vertical, 2700aff185Sopenharmony_ci state: BarState.Auto }) { 2800aff185Sopenharmony_ci Row() { 2900aff185Sopenharmony_ci if (this.isClickScrollBar) { 3000aff185Sopenharmony_ci Image($r('app.media.scroll_press_light')) 3100aff185Sopenharmony_ci .width($r('app.float.scroll_bar_big_width')) 3200aff185Sopenharmony_ci .height($r('app.float.scroll_bar_big_height')) 3300aff185Sopenharmony_ci } else { 3400aff185Sopenharmony_ci Image($r('app.media.scroll_light')) 3500aff185Sopenharmony_ci .width($r('app.float.scroll_bar_small_width')) 3600aff185Sopenharmony_ci .height($r('app.float.scroll_bar_small_height')) 3700aff185Sopenharmony_ci .borderRadius(25) 3800aff185Sopenharmony_ci } 3900aff185Sopenharmony_ci } 4000aff185Sopenharmony_ci } 4100aff185Sopenharmony_ci .width(this.isClickScrollBar ? $r('app.float.scroll_bar_margin_small') : $r('app.float.scroll_bar_small_width')) 4200aff185Sopenharmony_ci .height('100%') 4300aff185Sopenharmony_ci .hitTestBehavior(HitTestMode.Transparent) 4400aff185Sopenharmony_ci .position({ x: '100%', y: 0 }) 4500aff185Sopenharmony_ci .markAnchor({ 4600aff185Sopenharmony_ci x: this.isClickScrollBar ? $r('app.float.scroll_bar_big_width') : $r('app.float.scroll_bar_small_width'), 4700aff185Sopenharmony_ci y: 0 4800aff185Sopenharmony_ci }) 4900aff185Sopenharmony_ci .onTouch((event?: TouchEvent) => { 5000aff185Sopenharmony_ci if (event?.type == TouchType.Move && !this.isClickScrollBar) { 5100aff185Sopenharmony_ci Log.debug(TAG, `scrollBar first TouchType.Move`); 5200aff185Sopenharmony_ci this.isClickScrollBar = true; 5300aff185Sopenharmony_ci } else if (event?.type == TouchType.Up || event?.type == TouchType.Cancel) { 5400aff185Sopenharmony_ci Log.debug(TAG, `scrollBar TouchType.Up or Cancel. type=${event?.type}`); 5500aff185Sopenharmony_ci this.isClickScrollBar = false; 5600aff185Sopenharmony_ci } 5700aff185Sopenharmony_ci }) 5800aff185Sopenharmony_ci } 5900aff185Sopenharmony_ci}