• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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' />
17class BlankColorModifier extends ModifierWithKey<ResourceColor> {
18  constructor(value: ResourceColor) {
19    super(value);
20  }
21  static identity: Symbol = Symbol('blankColor');
22  applyPeer(node: KNode, reset: boolean): void {
23    if (reset) {
24      getUINativeModule().blank.resetColor(node);
25    } else {
26      getUINativeModule().blank.setColor(node, this.value!);
27    }
28  }
29  checkObjectDiff(): boolean {
30    return !isBaseOrResourceEqual(this.stageValue, this.value);
31  }
32}
33
34class BlankHeightModifier extends ModifierWithKey<Length> {
35  constructor(value: ResourceColor) {
36    super(value);
37  }
38  static identity: Symbol = Symbol('blankHeight');
39  applyPeer(node: KNode, reset: boolean): void {
40    if (reset) {
41      getUINativeModule().blank.resetBlankHeight(node);
42    } else {
43      getUINativeModule().blank.setBlankHeight(node, this.value!);
44    }
45  }
46  checkObjectDiff(): boolean {
47    return !isBaseOrResourceEqual(this.stageValue, this.value);
48  }
49}
50
51
52class BlankMinModifier extends ModifierWithKey<number | string> {
53  constructor(value: number | string) {
54    super(value);
55  }
56  static identity: Symbol = Symbol('blankMin');
57  applyPeer(node: KNode, reset: boolean): void {
58    if (reset) {
59      getUINativeModule().blank.resetBlankMin(node);
60    } else {
61      getUINativeModule().blank.setBlankMin(node, this.value!);
62    }
63  }
64  checkObjectDiff(): boolean {
65    return !isBaseOrResourceEqual(this.stageValue, this.value);
66  }
67}
68
69class ArkBlankComponent extends ArkComponent implements CommonMethod<BlankAttribute> {
70  constructor(nativePtr: KNode, classType?: ModifierType) {
71    super(nativePtr, classType);
72  }
73  color(value: ResourceColor): BlankAttribute {
74    modifierWithKey(this._modifiersWithKeys, BlankColorModifier.identity, BlankColorModifier, value);
75    return this;
76  }
77  height(value: Length): this {
78    modifierWithKey(this._modifiersWithKeys, BlankHeightModifier.identity, BlankHeightModifier, value);
79    return this;
80  }
81
82  initialize(value : Object[]): BlankAttribute{
83    if (value[0] !== undefined){
84      modifierWithKey(this._modifiersWithKeys, BlankMinModifier.identity, BlankMinModifier, value[0]);
85    }
86    return this;
87  }
88
89  allowChildCount(): number {
90    return 0;
91  }
92}
93
94// @ts-ignore
95globalThis.Blank.attributeModifier = function (modifier: ArkComponent): void {
96  attributeModifierFunc.call(this, modifier, (nativePtr: KNode) => {
97    return new ArkBlankComponent(nativePtr);
98  }, (nativePtr: KNode, classType: ModifierType, modifierJS: ModifierJS) => {
99    return new modifierJS.BlankModifier(nativePtr, classType);
100  });
101};
102