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 OnReachEndModifier extends ModifierWithKey<() => void> { 47 constructor(value: () => void) { 48 super(value); 49 } 50 static identity: Symbol = Symbol('onReachEnd'); 51 applyPeer(node: KNode, reset: boolean): void { 52 if (reset) { 53 getUINativeModule().scrollable.resetOnReachEnd(node); 54 } else { 55 getUINativeModule().scrollable.setOnReachEnd(node, this.value); 56 } 57 } 58} 59 60/** 61 * base class of Grid, Scroll, List, and WaterFlow. 62 */ 63export class ArkScrollable<T> extends ArkComponent implements ScrollableCommonMethod<T> { 64 constructor(nativePtr: KNode, classType?: ModifierType) { 65 super(nativePtr, classType); 66 } 67 clipContent(clip: ContentClipMode | RectShape): T { 68 modifierWithKey(this._modifiersWithKeys, ClipContentModifier.identity, ClipContentModifier, clip); 69 return this; 70 } 71 onReachStart(event: () => void): this { 72 modifierWithKey(this._modifiersWithKeys, OnReachStartModifier.identity, OnReachStartModifier, event); 73 return this; 74 } 75 76 onReachEnd(event: () => void): this { 77 modifierWithKey(this._modifiersWithKeys, OnReachEndModifier.identity, OnReachEndModifier, event); 78 return this; 79 } 80}