• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
16@Component
17export struct GridScrollBar {
18    scroller: Scroller;
19    @State isClickScrollBar: boolean = false;
20    @Link isHideScrollBar: boolean;
21
22    build() {
23        ScrollBar({ scroller: this.scroller, direction: ScrollBarDirection.Vertical,
24            state: this.isHideScrollBar ? BarState.Off : BarState.Auto }) {
25            Row() {
26                if (this.isClickScrollBar) {
27                    Image($r("app.media.scroll_press_light"))
28                        .width($r('app.float.scroll_bar_big_width'))
29                        .height($r('app.float.scroll_bar_big_height'))
30                } else {
31                    Image($r("app.media.scroll_light"))
32                        .width($r('app.float.scroll_bar_small_width'))
33                        .height($r('app.float.scroll_bar_small_height'))
34                }
35            }
36        }
37        .hitTestBehavior(HitTestMode.Transparent)
38        .height('100%')
39        .width(this.isClickScrollBar
40            ? $r('app.float.scroll_bar_margin_small') : $r('app.float.scroll_bar_small_width'),)
41        .position({ x: '100%', y: 0 })
42        .markAnchor({
43            x: this.isClickScrollBar ? $r('app.float.scroll_bar_big_width') : $r('app.float.scroll_bar_small_width'),
44            y: 0
45        })
46        .onTouch((event: TouchEvent) => {
47            if (event.type == TouchType.Down) {
48                this.isClickScrollBar = true;
49            } else if (event.type == TouchType.Up) {
50                this.isClickScrollBar = false;
51            }
52        })
53    }
54}