• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2022 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/// <reference path="./ArkCommonShape.ts" />
18class RectRadiusWidthModifier extends ModifierWithKey<string | number> {
19  constructor(value: string | number) {
20    super(value);
21  }
22  static identity: Symbol = Symbol('rectRadiusWidth');
23  applyPeer(node: KNode, reset: boolean): void {
24    if (reset) {
25      getUINativeModule().rect.resetRectRadiusWidth(node);
26    } else {
27      getUINativeModule().rect.setRectRadiusWidth(node, this.value);
28    }
29  }
30}
31class RectRadiusHeightModifier extends ModifierWithKey<string | number> {
32  constructor(value: string | number) {
33    super(value);
34  }
35  static identity: Symbol = Symbol('rectRadiusHeight');
36  applyPeer(node: KNode, reset: boolean): void {
37    if (reset) {
38      getUINativeModule().rect.resetRectRadiusHeight(node);
39    } else {
40      getUINativeModule().rect.setRectRadiusHeight(node, this.value);
41    }
42  }
43}
44class RectRadiusModifier extends ModifierWithKey<string | number | Array<any>> {
45  constructor(value: string | number | Array<any>) {
46    super(value);
47  }
48  static identity: Symbol = Symbol('rectRadius');
49  applyPeer(node: KNode, reset: boolean): void {
50    if (reset) {
51      getUINativeModule().rect.resetRectRadius(node);
52    } else {
53      getUINativeModule().rect.setRectRadius(node, this.value);
54    }
55  }
56
57  checkObjectDiff(): boolean {
58    return !(this.stageValue === this.value);
59  }
60}
61class ArkRectComponent extends ArkCommonShapeComponent implements RectAttribute {
62  constructor(nativePtr: KNode, classType?: ModifierType) {
63    super(nativePtr, classType);
64  }
65  radiusWidth(value: string | number): this {
66    modifierWithKey(this._modifiersWithKeys, RectRadiusWidthModifier.identity, RectRadiusWidthModifier, value);
67    return this;
68  }
69  radiusHeight(value: string | number): this {
70    modifierWithKey(this._modifiersWithKeys, RectRadiusHeightModifier.identity, RectRadiusHeightModifier, value);
71    return this;
72  }
73  radius(value: string | number | Array<any>): this {
74    modifierWithKey(this._modifiersWithKeys, RectRadiusModifier.identity, RectRadiusModifier, value);
75    return this;
76  }
77}
78
79// @ts-ignore
80globalThis.Rect.attributeModifier = function (modifier: ArkComponent): void {
81  attributeModifierFunc.call(this, modifier, (nativePtr: KNode) => {
82    return new ArkRectComponent(nativePtr);
83  }, (nativePtr: KNode, classType: ModifierType, modifierJS: ModifierJS) => {
84    return new modifierJS.RectModifier(nativePtr, classType);
85  });
86};
87