• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2024 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/// <reference path='./import.ts' />
17
18class ClipContentModifier extends ModifierWithKey<ContentClipMode | RectShape> {
19    constructor(value: ContentClipMode | RectShape) {
20        super(value);
21    }
22    static identity: Symbol = Symbol('clipContent');
23    applyPeer(node: KNode, reset: boolean): void {
24        if (reset) {
25            getUINativeModule().scrollable.resetContentClip(node);
26        } else {
27            getUINativeModule().scrollable.setContentClip(node, this.value);
28        }
29    }
30}
31
32class OnReachStartModifier extends ModifierWithKey<() => void> {
33    constructor(value: () => void) {
34        super(value);
35    }
36    static identity: Symbol = Symbol('onReachStart');
37    applyPeer(node: KNode, reset: boolean): void {
38        if (reset) {
39            getUINativeModule().scrollable.resetOnReachStart(node);
40        } else {
41            getUINativeModule().scrollable.setOnReachStart(node, this.value);
42        }
43    }
44}
45
46class BackToTopModifier extends ModifierWithKey<boolean> {
47  constructor(value: boolean) {
48    super(value);
49  }
50  static identity: Symbol = Symbol('backToTop');
51  applyPeer(node: KNode, reset: boolean): void {
52    if (reset) {
53      getUINativeModule().scrollable.resetBackToTop(node);
54    } else {
55      getUINativeModule().scrollable.setBackToTop(node, this.value);
56    }
57  }
58}
59
60class OnReachEndModifier extends ModifierWithKey<() => void> {
61    constructor(value: () => void) {
62        super(value);
63    }
64    static identity: Symbol = Symbol('onReachEnd');
65    applyPeer(node: KNode, reset: boolean): void {
66        if (reset) {
67            getUINativeModule().scrollable.resetOnReachEnd(node);
68        } else {
69            getUINativeModule().scrollable.setOnReachEnd(node, this.value);
70        }
71    }
72}
73
74/**
75 * base class of Grid, Scroll, List, and WaterFlow.
76 */
77export class ArkScrollable<T> extends ArkComponent implements ScrollableCommonMethod<T> {
78    constructor(nativePtr: KNode, classType?: ModifierType) {
79      super(nativePtr, classType);
80    }
81    clipContent(clip: ContentClipMode | RectShape): T {
82        modifierWithKey(this._modifiersWithKeys, ClipContentModifier.identity, ClipContentModifier, clip);
83        return this;
84    }
85    onReachStart(event: () => void): this {
86        modifierWithKey(this._modifiersWithKeys, OnReachStartModifier.identity, OnReachStartModifier, event);
87        return this;
88    }
89
90    onReachEnd(event: () => void): this {
91        modifierWithKey(this._modifiersWithKeys, OnReachEndModifier.identity, OnReachEndModifier, event);
92        return this;
93    }
94    backToTop(value: boolean): this {
95      modifierWithKey(this._modifiersWithKeys, BackToTopModifier.identity, BackToTopModifier, value);
96      return this;
97    }
98}