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 constructor(value: string | number | FontWeight) { 143 super(value); 144 } 145 static identity: Symbol = Symbol('fontWeight'); 146 applyPeer(node: KNode, reset: boolean): void { 147 if (reset) { 148 getUINativeModule().marquee.resetFontWeight(node); 149 } else { 150 getUINativeModule().marquee.setFontWeight(node, this.value); 151 } 152 } 153 checkObjectDiff(): boolean { 154 return this.stageValue !== this.value; 155 } 156} 157class MarqueeFontFamilyModifier extends ModifierWithKey<string> { 158 constructor(value: string) { 159 super(value); 160 } 161 static identity: Symbol = Symbol('fontFamily'); 162 applyPeer(node: KNode, reset: boolean): void { 163 if (reset) { 164 getUINativeModule().marquee.resetFontFamily(node); 165 } else { 166 getUINativeModule().marquee.setFontFamily(node, this.value); 167 } 168 } 169} 170 171class MarqueeUpdateStrategyModifier extends ModifierWithKey<MarqueeUpdateStrategy> { 172 constructor(value: MarqueeUpdateStrategy) { 173 super(value); 174 } 175 static identity: Symbol = Symbol('marqueeUpdateStrategy'); 176 applyPeer(node: KNode, reset: boolean): void { 177 if (reset) { 178 getUINativeModule().marquee.resetMarqueeUpdateStrategy(node); 179 } else { 180 getUINativeModule().marquee.setMarqueeUpdateStrategy(node, this.value); 181 } 182 } 183} 184 185class MarqueeOnStartModifier extends ModifierWithKey<() => void> { 186 constructor(value: () => void) { 187 super(value); 188 } 189 static identity: Symbol = Symbol('marqueeOnStart'); 190 applyPeer(node: KNode, reset: boolean): void { 191 if (reset) { 192 getUINativeModule().marquee.resetMarqueeOnStart(node); 193 } else { 194 getUINativeModule().marquee.setMarqueeOnStart(node, this.value); 195 } 196 } 197} 198 199class MarqueeOnBounceModifier extends ModifierWithKey<() => void> { 200 constructor(value: () => void) { 201 super(value); 202 } 203 static identity: Symbol = Symbol('marqueeOnBounce'); 204 applyPeer(node: KNode, reset: boolean): void { 205 if (reset) { 206 getUINativeModule().marquee.resetMarqueeOnBounce(node); 207 } else { 208 getUINativeModule().marquee.setMarqueeOnBounce(node, this.value); 209 } 210 } 211} 212 213class MarqueeOnFinishModifier extends ModifierWithKey<() => void> { 214 constructor(value: () => void) { 215 super(value); 216 } 217 static identity: Symbol = Symbol('marqueeOnFinish'); 218 applyPeer(node: KNode, reset: boolean): void { 219 if (reset) { 220 getUINativeModule().marquee.resetMarqueeOnFinish(node); 221 } else { 222 getUINativeModule().marquee.setMarqueeOnFinish(node, this.value); 223 } 224 } 225} 226 227// @ts-ignore 228globalThis.Marquee.attributeModifier = function (modifier: ArkComponent): void { 229 attributeModifierFunc.call(this, modifier, (nativePtr: KNode) => { 230 return new ArkMarqueeComponent(nativePtr); 231 }, (nativePtr: KNode, classType: ModifierType, modifierJS: ModifierJS) => { 232 return new modifierJS.MarqueeModifier(nativePtr, classType); 233 }); 234}; 235