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