1/* 2 * Copyright (c) 2023 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 ArkMarqueeComponent extends ArkComponent implements MarqueeAttribute { 19 constructor(nativePtr: KNode, classType?: ModifierType) { 20 super(nativePtr, classType); 21 } 22 allowChildCount(): number { 23 return 0; 24 } 25 initialize(value: Object[]): this { 26 if (value.length === 1 && isObject(value[0])) { 27 modifierWithKey(this._modifiersWithKeys, MarqueeInitializeModifier.identity, MarqueeInitializeModifier, value[0]); 28 } else { 29 modifierWithKey(this._modifiersWithKeys, MarqueeInitializeModifier.identity, MarqueeInitializeModifier, undefined); 30 } 31 return this; 32 } 33 fontSize(value: Length): this { 34 modifierWithKey(this._modifiersWithKeys, MarqueeFontSizeModifier.identity, MarqueeFontSizeModifier, value); 35 return this; 36 } 37 fontColor(value: ResourceColor): this { 38 modifierWithKey(this._modifiersWithKeys, MarqueeFontColorModifier.identity, MarqueeFontColorModifier, value); 39 return this; 40 } 41 allowScale(value: boolean): this { 42 modifierWithKey(this._modifiersWithKeys, MarqueeAllowScaleModifier.identity, MarqueeAllowScaleModifier, value); 43 return this; 44 } 45 fontWeight(value: string | number | FontWeight): this { 46 modifierWithKey(this._modifiersWithKeys, MarqueeFontWeightModifier.identity, MarqueeFontWeightModifier, value); 47 return this; 48 } 49 fontFamily(value: any): this { 50 modifierWithKey(this._modifiersWithKeys, MarqueeFontFamilyModifier.identity, MarqueeFontFamilyModifier, value as string); 51 return this; 52 } 53 onStart(event: () => void): this { 54 modifierWithKey(this._modifiersWithKeys, MarqueeOnStartModifier.identity, MarqueeOnStartModifier, event); 55 return this; 56 } 57 onBounce(event: () => void): this { 58 modifierWithKey(this._modifiersWithKeys, MarqueeOnBounceModifier.identity, MarqueeOnBounceModifier, event); 59 return this; 60 } 61 onFinish(event: () => void): this { 62 modifierWithKey(this._modifiersWithKeys, MarqueeOnFinishModifier.identity, MarqueeOnFinishModifier, event); 63 return this; 64 } 65 marqueeUpdateStrategy(value: MarqueeUpdateStrategy): this { 66 modifierWithKey(this._modifiersWithKeys, MarqueeUpdateStrategyModifier.identity, MarqueeUpdateStrategyModifier, value); 67 return this; 68 } 69} 70 71class MarqueeInitializeModifier extends ModifierWithKey<Object> { 72 constructor(value: Object) { 73 super(value); 74 } 75 static identity: Symbol = Symbol('marqueeInitialize'); 76 applyPeer(node: KNode, reset: boolean): void { 77 if (reset) { 78 getUINativeModule().marquee.setInitialize(node, undefined, undefined, undefined, undefined, undefined); 79 } else { 80 getUINativeModule().marquee.setInitialize(node, this.value?.start, this.value?.step, this.value?.loop, 81 this.value?.fromStart, this.value?.src); 82 } 83 } 84 85 checkObjectDiff(): boolean { 86 return !isBaseOrResourceEqual(this.stageValue?.start, this.value?.start) || 87 !isBaseOrResourceEqual(this.stageValue?.step, this.value?.step) || 88 !isBaseOrResourceEqual(this.stageValue?.loop, this.value?.loop) || 89 !isBaseOrResourceEqual(this.stageValue?.fromStart, this.value?.fromStart) || 90 !isBaseOrResourceEqual(this.stageValue?.src, this.value?.src); 91 } 92} 93 94class MarqueeFontColorModifier extends ModifierWithKey<ResourceColor> { 95 constructor(value: ResourceColor) { 96 super(value); 97 } 98 static identity: Symbol = Symbol('fontColor'); 99 applyPeer(node: KNode, reset: boolean): void { 100 if (reset) { 101 getUINativeModule().marquee.resetFontColor(node); 102 } else { 103 getUINativeModule().marquee.setFontColor(node, this.value); 104 } 105 } 106 107 checkObjectDiff(): boolean { 108 return !isBaseOrResourceEqual(this.stageValue, this.value); 109 } 110} 111class MarqueeFontSizeModifier extends ModifierWithKey<Length> { 112 constructor(value: Length) { 113 super(value); 114 } 115 static identity: Symbol = Symbol('fontSize'); 116 applyPeer(node: KNode, reset: boolean): void { 117 if (reset) { 118 getUINativeModule().marquee.resetFontSize(node); 119 } else { 120 getUINativeModule().marquee.setFontSize(node, this.value); 121 } 122 } 123 124 checkObjectDiff(): boolean { 125 return !isBaseOrResourceEqual(this.stageValue, this.value); 126 } 127} 128class MarqueeAllowScaleModifier extends ModifierWithKey<boolean> { 129 constructor(value: boolean) { 130 super(value); 131 } 132 static identity: Symbol = Symbol('allowScale'); 133 applyPeer(node: KNode, reset: boolean): void { 134 if (reset) { 135 getUINativeModule().marquee.resetAllowScale(node); 136 } else { 137 getUINativeModule().marquee.setAllowScale(node, this.value); 138 } 139 } 140} 141class MarqueeFontWeightModifier extends ModifierWithKey<string | number | FontWeight> { 142 static identity: Symbol = Symbol('fontWeight'); 143 applyPeer(node: KNode, reset: boolean): void { 144 if (reset) { 145 getUINativeModule().marquee.resetFontWeight(node); 146 } else { 147 getUINativeModule().marquee.setFontWeight(node, this.value); 148 } 149 } 150 checkObjectDiff(): boolean { 151 return this.stageValue !== this.value; 152 } 153} 154class MarqueeFontFamilyModifier extends ModifierWithKey<string> { 155 constructor(value: string) { 156 super(value); 157 } 158 static identity: Symbol = Symbol('fontFamily'); 159 applyPeer(node: KNode, reset: boolean): void { 160 if (reset) { 161 getUINativeModule().marquee.resetFontFamily(node); 162 } else { 163 getUINativeModule().marquee.setFontFamily(node, this.value); 164 } 165 } 166} 167 168class MarqueeUpdateStrategyModifier extends ModifierWithKey<MarqueeUpdateStrategy> { 169 constructor(value: MarqueeUpdateStrategy) { 170 super(value); 171 } 172 static identity: Symbol = Symbol('marqueeUpdateStrategy'); 173 applyPeer(node: KNode, reset: boolean): void { 174 if (reset) { 175 getUINativeModule().marquee.resetMarqueeUpdateStrategy(node); 176 } else { 177 getUINativeModule().marquee.setMarqueeUpdateStrategy(node, this.value); 178 } 179 } 180} 181 182class MarqueeOnStartModifier extends ModifierWithKey<() => void> { 183 constructor(value: () => void) { 184 super(value); 185 } 186 static identity: Symbol = Symbol('marqueeOnStart'); 187 applyPeer(node: KNode, reset: boolean): void { 188 if (reset) { 189 getUINativeModule().marquee.resetMarqueeOnStart(node); 190 } else { 191 getUINativeModule().marquee.setMarqueeOnStart(node, this.value); 192 } 193 } 194} 195 196class MarqueeOnBounceModifier extends ModifierWithKey<() => void> { 197 constructor(value: () => void) { 198 super(value); 199 } 200 static identity: Symbol = Symbol('marqueeOnBounce'); 201 applyPeer(node: KNode, reset: boolean): void { 202 if (reset) { 203 getUINativeModule().marquee.resetMarqueeOnBounce(node); 204 } else { 205 getUINativeModule().marquee.setMarqueeOnBounce(node, this.value); 206 } 207 } 208} 209 210class MarqueeOnFinishModifier extends ModifierWithKey<() => void> { 211 constructor(value: () => void) { 212 super(value); 213 } 214 static identity: Symbol = Symbol('marqueeOnFinish'); 215 applyPeer(node: KNode, reset: boolean): void { 216 if (reset) { 217 getUINativeModule().marquee.resetMarqueeOnFinish(node); 218 } else { 219 getUINativeModule().marquee.setMarqueeOnFinish(node, this.value); 220 } 221 } 222} 223 224// @ts-ignore 225globalThis.Marquee.attributeModifier = function (modifier: ArkComponent): void { 226 attributeModifierFunc.call(this, modifier, (nativePtr: KNode) => { 227 return new ArkMarqueeComponent(nativePtr); 228 }, (nativePtr: KNode, classType: ModifierType, modifierJS: ModifierJS) => { 229 return new modifierJS.MarqueeModifier(nativePtr, classType); 230 }); 231}; 232