1/* 2 * Copyright (c) 2023-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 17/// <reference path='./import.ts' /> 18class ArkRefreshComponent extends ArkComponent implements RefreshAttribute { 19 constructor(nativePtr: KNode, classType?: ModifierType) { 20 super(nativePtr, classType); 21 } 22 onStateChange(callback: (state: RefreshStatus) => void): this { 23 throw new Error('Method not implemented.'); 24 } 25 onRefreshing(callback: () => void): this { 26 throw new Error('Method not implemented.'); 27 } 28 refreshOffset(value: number): this { 29 modifierWithKey(this._modifiersWithKeys, RefreshOffsetModifier.identity, RefreshOffsetModifier, value); 30 return this; 31 } 32 pullToRefresh(value: boolean): this { 33 modifierWithKey(this._modifiersWithKeys, PullToRefreshModifier.identity, PullToRefreshModifier, value); 34 return this; 35 } 36 pullDownRatio(value: number): this { 37 modifierWithKey(this._modifiersWithKeys, PullDownRatioModifier.identity, PullDownRatioModifier, value); 38 return this; 39 } 40} 41 42class RefreshOffsetModifier extends ModifierWithKey<number> { 43 constructor(value: number) { 44 super(value); 45 } 46 static identity: Symbol = Symbol('refreshOffset'); 47 applyPeer(node: KNode, reset: boolean): void { 48 if (reset) { 49 getUINativeModule().refresh.resetRefreshOffset(node); 50 } else { 51 getUINativeModule().refresh.setRefreshOffset(node, this.value); 52 } 53 } 54} 55class PullToRefreshModifier extends ModifierWithKey<boolean> { 56 constructor(value: boolean) { 57 super(value); 58 } 59 static identity: Symbol = Symbol('pullToRefresh'); 60 applyPeer(node: KNode, reset: boolean): void { 61 if (reset) { 62 getUINativeModule().refresh.resetPullToRefresh(node); 63 } else { 64 getUINativeModule().refresh.setPullToRefresh(node, this.value); 65 } 66 } 67} 68class PullDownRatioModifier extends ModifierWithKey<number> { 69 constructor(value: number) { 70 super(value); 71 } 72 static identity: Symbol = Symbol('pullDownRatio'); 73 applyPeer(node: KNode, reset: boolean): void { 74 if (reset) { 75 getUINativeModule().refresh.resetPullDownRatio(node); 76 } else { 77 getUINativeModule().refresh.setPullDownRatio(node, this.value); 78 } 79 } 80 checkObjectDiff(): boolean { 81 return !isBaseOrResourceEqual(this.stageValue, this.value); 82 } 83} 84// @ts-ignore 85globalThis.Refresh.attributeModifier = function (modifier: ArkComponent): void { 86 attributeModifierFunc.call(this, modifier, (nativePtr: KNode) => { 87 return new ArkRefreshComponent(nativePtr); 88 }, (nativePtr: KNode, classType: ModifierType, modifierJS: ModifierJS) => { 89 return new modifierJS.RefreshModifier(nativePtr, classType); 90 }); 91}; 92