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 EdgeEffectModifier extends ModifierWithKey<ArkEdgeEffect> { 33 constructor(value: ArkEdgeEffect) { 34 super(value); 35 } 36 static identity: Symbol = Symbol('edgeEffect'); 37 applyPeer(node: KNode, reset: boolean): void { 38 if (reset) { 39 getUINativeModule().scrollable.resetEdgeEffect(node); 40 } else { 41 getUINativeModule().scrollable.setEdgeEffect(node, this.value?.value, this.value.options?.alwaysEnabled, 42 this.value.options?.effectEdge); 43 } 44 } 45 46 checkObjectDiff(): boolean { 47 return !((this.stageValue.value === this.value.value) && 48 (this.stageValue.options === this.value.options)); 49 } 50} 51 52class ScrollableFadingEdgeModifier extends ModifierWithKey<ArkFadingEdge> { 53 constructor(value: ArkFadingEdge) { 54 super(value); 55 } 56 static identity: Symbol = Symbol('scrollableFadingEdge'); 57 applyPeer(node: KNode, reset: boolean): void { 58 if (reset) { 59 getUINativeModule().scrollable.resetFadingEdge(node); 60 } else { 61 getUINativeModule().scrollable.setFadingEdge(node, this.value.value!, this.value.options?.fadingEdgeLength); 62 } 63 } 64 checkObjectDiff(): boolean { 65 return !((this.stageValue.value === this.value.value) && 66 (this.stageValue.options === this.value.options)); 67 } 68} 69 70class OnReachStartModifier extends ModifierWithKey<() => void> { 71 constructor(value: () => void) { 72 super(value); 73 } 74 static identity: Symbol = Symbol('onReachStart'); 75 applyPeer(node: KNode, reset: boolean): void { 76 if (reset) { 77 getUINativeModule().scrollable.resetOnReachStart(node); 78 } else { 79 getUINativeModule().scrollable.setOnReachStart(node, this.value); 80 } 81 } 82} 83 84class BackToTopModifier extends ModifierWithKey<boolean> { 85 constructor(value: boolean) { 86 super(value); 87 } 88 static identity: Symbol = Symbol('backToTop'); 89 applyPeer(node: KNode, reset: boolean): void { 90 if (reset) { 91 getUINativeModule().scrollable.resetBackToTop(node); 92 } else { 93 getUINativeModule().scrollable.setBackToTop(node, this.value); 94 } 95 } 96} 97 98class OnReachEndModifier extends ModifierWithKey<() => void> { 99 constructor(value: () => void) { 100 super(value); 101 } 102 static identity: Symbol = Symbol('onReachEnd'); 103 applyPeer(node: KNode, reset: boolean): void { 104 if (reset) { 105 getUINativeModule().scrollable.resetOnReachEnd(node); 106 } else { 107 getUINativeModule().scrollable.setOnReachEnd(node, this.value); 108 } 109 } 110} 111 112/** 113 * base class of Grid, Scroll, List, and WaterFlow. 114 */ 115export class ArkScrollable<T> extends ArkComponent implements ScrollableCommonMethod<T> { 116 constructor(nativePtr: KNode, classType?: ModifierType) { 117 super(nativePtr, classType); 118 } 119 clipContent(clip: ContentClipMode | RectShape): T { 120 modifierWithKey(this._modifiersWithKeys, ClipContentModifier.identity, ClipContentModifier, clip); 121 return this; 122 } 123 edgeEffect(value: EdgeEffect, options?: EdgeEffectOptions | undefined): T { 124 let effect: ArkEdgeEffect = new ArkEdgeEffect(); 125 effect.value = value; 126 effect.options = options; 127 modifierWithKey(this._modifiersWithKeys, EdgeEffectModifier.identity, EdgeEffectModifier, effect); 128 return this; 129 } 130 fadingEdge(value: boolean, options?: FadingEdgeOptions | undefined): T { 131 let fadingEdge: ArkFadingEdge = new ArkFadingEdge(); 132 fadingEdge.value = value; 133 fadingEdge.options = options; 134 modifierWithKey(this._modifiersWithKeys, ScrollableFadingEdgeModifier.identity, ScrollableFadingEdgeModifier, fadingEdge); 135 return this; 136 } 137 onReachStart(event: () => void): this { 138 modifierWithKey(this._modifiersWithKeys, OnReachStartModifier.identity, OnReachStartModifier, event); 139 return this; 140 } 141 142 onReachEnd(event: () => void): this { 143 modifierWithKey(this._modifiersWithKeys, OnReachEndModifier.identity, OnReachEndModifier, event); 144 return this; 145 } 146 backToTop(value: boolean): this { 147 modifierWithKey(this._modifiersWithKeys, BackToTopModifier.identity, BackToTopModifier, value); 148 return this; 149 } 150}