• 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 ArkPluginComponent extends ArkComponent implements PluginComponentAttribute {
18  constructor(nativePtr: KNode, classType?: ModifierType) {
19    super(nativePtr, classType);
20  }
21  onComplete(callback: () => void): this {
22    throw new Error('Method not implemented.');
23  }
24  onError(callback: (info: { errcode: number; msg: string; }) => void): this {
25    throw new Error('Method not implemented.');
26  }
27  size(value: SizeOptions): this {
28    modifierWithKey(this._modifiersWithKeys, PluginSizeModifier.identity, PluginSizeModifier, value);
29    return this;
30  }
31  width(value: Length): this {
32    modifierWithKey(this._modifiersWithKeys, PluginWidthModifier.identity, PluginWidthModifier, value);
33    return this;
34  }
35
36  height(value: Length): this {
37    modifierWithKey(this._modifiersWithKeys, PluginHeightModifier.identity, PluginHeightModifier, value);
38    return this;
39  }
40}
41
42class PluginWidthModifier extends ModifierWithKey<Length> {
43  constructor(value: Length) {
44    super(value);
45  }
46  static identity: Symbol = Symbol('pluginWidth');
47  applyPeer(node: KNode, reset: boolean): void {
48    if (reset) {
49      getUINativeModule().plugin.resetWidth(node);
50    } else {
51      getUINativeModule().plugin.setWidth(node, this.value);
52    }
53  }
54
55  checkObjectDiff(): boolean {
56    if (isResource(this.stageValue) && isResource(this.value)) {
57      return !isResourceEqual(this.stageValue, this.value);
58    } else {
59      return true;
60    }
61  }
62}
63
64class PluginHeightModifier extends ModifierWithKey<Length> {
65  constructor(value: Length) {
66    super(value);
67  }
68  static identity: Symbol = Symbol('pluginHeight');
69  applyPeer(node: KNode, reset: boolean): void {
70    if (reset) {
71      getUINativeModule().plugin.resetHeight(node);
72    } else {
73      getUINativeModule().plugin.setHeight(node, this.value);
74    }
75  }
76
77  checkObjectDiff(): boolean {
78    if (isResource(this.stageValue) && isResource(this.value)) {
79      return !isResourceEqual(this.stageValue, this.value);
80    } else {
81      return true;
82    }
83  }
84}
85
86class PluginSizeModifier extends ModifierWithKey<SizeOptions> {
87  constructor(value: SizeOptions) {
88    super(value);
89  }
90  static identity: Symbol = Symbol('size');
91  applyPeer(node: KNode, reset: boolean): void {
92    if (reset) {
93      getUINativeModule().plugin.resetSize(node);
94    } else {
95      getUINativeModule().plugin.setSize(node, this.value.width, this.value.height);
96    }
97  }
98
99  checkObjectDiff(): boolean {
100    return !isBaseOrResourceEqual(this.stageValue.width, this.value.width) ||
101      !isBaseOrResourceEqual(this.stageValue.height, this.value.height);
102  }
103}
104
105// @ts-ignore
106globalThis.PluginComponent.attributeModifier = function (modifier: ArkComponent): void {
107  attributeModifierFunc.call(this, modifier, (nativePtr: KNode) => {
108    return new ArkPluginComponent(nativePtr);
109  }, (nativePtr: KNode, classType: ModifierType, modifierJS: ModifierJS) => {
110    return new modifierJS.PluginComponentModifier(nativePtr, classType);
111  });
112};
113