• 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 ArkPanelComponent extends ArkComponent implements PanelAttribute {
18  constructor(nativePtr: KNode, classType?: ModifierType) {
19    super(nativePtr, classType);
20  }
21  mode(value: PanelMode): this {
22    modifierWithKey(this._modifiersWithKeys, PanelModeModifier.identity, PanelModeModifier, value);
23    return this;
24  }
25  type(value: PanelType): this {
26    modifierWithKey(this._modifiersWithKeys, PanelTypeModifier.identity, PanelTypeModifier, value);
27    return this;
28  }
29  dragBar(value: boolean): this {
30    modifierWithKey(this._modifiersWithKeys, DragBarModifier.identity, DragBarModifier, value);
31    return this;
32  }
33  customHeight(value: any): this {
34    modifierWithKey(this._modifiersWithKeys, PanelCustomHeightModifier.identity, PanelCustomHeightModifier, value);
35    return this;
36  }
37  fullHeight(value: string | number): this {
38    modifierWithKey(this._modifiersWithKeys, PanelFullHeightModifier.identity, PanelFullHeightModifier, value);
39    return this;
40  }
41  halfHeight(value: string | number): this {
42    modifierWithKey(this._modifiersWithKeys, PanelHalfHeightModifier.identity, PanelHalfHeightModifier, value);
43    return this;
44  }
45  miniHeight(value: string | number): this {
46    modifierWithKey(this._modifiersWithKeys, PanelMiniHeightModifier.identity, PanelMiniHeightModifier, value);
47    return this;
48  }
49  show(value: boolean): this {
50    modifierWithKey(this._modifiersWithKeys, ShowModifier.identity, ShowModifier, value);
51    return this;
52  }
53  backgroundMask(color: ResourceColor): this {
54    modifierWithKey(this._modifiersWithKeys, PanelBackgroundMaskModifier.identity, PanelBackgroundMaskModifier, color);
55    return this;
56  }
57  showCloseIcon(value: boolean): this {
58    modifierWithKey(this._modifiersWithKeys, ShowCloseIconModifier.identity, ShowCloseIconModifier, value);
59    return this;
60  }
61  onChange(event: (width: number, height: number, mode: PanelMode) => void): this {
62    throw new Error('Method not implemented.');
63  }
64  onHeightChange(callback: (value: number) => void): this {
65    throw new Error('Method not implemented.');
66  }
67}
68
69class PanelBackgroundMaskModifier extends ModifierWithKey<ResourceColor> {
70  constructor(value: ResourceColor) {
71    super(value);
72  }
73  static identity: Symbol = Symbol('panelBackgroundMask');
74  applyPeer(node: KNode, reset: boolean): void {
75    if (reset) {
76      getUINativeModule().panel.resetPanelBackgroundMask(node);
77    } else {
78      getUINativeModule().panel.setPanelBackgroundMask(node, this.value);
79    }
80  }
81
82  checkObjectDiff(): boolean {
83    return !isBaseOrResourceEqual(this.stageValue, this.value);
84  }
85}
86
87class PanelModeModifier extends ModifierWithKey<PanelMode> {
88  constructor(value: PanelMode) {
89    super(value);
90  }
91  static identity: Symbol = Symbol('panelMode');
92  applyPeer(node: KNode, reset: boolean): void {
93    if (reset) {
94      getUINativeModule().panel.resetPanelMode(node);
95    } else {
96      getUINativeModule().panel.setPanelMode(node, this.value);
97    }
98  }
99
100  checkObjectDiff(): boolean {
101    return !isBaseOrResourceEqual(this.stageValue, this.value);
102  }
103}
104
105class PanelTypeModifier extends ModifierWithKey<PanelType> {
106  constructor(value: PanelType) {
107    super(value);
108  }
109  static identity: Symbol = Symbol('panelType');
110  applyPeer(node: KNode, reset: boolean): void {
111    if (reset) {
112      getUINativeModule().panel.resetPanelType(node);
113    } else {
114      getUINativeModule().panel.setPanelType(node, this.value);
115    }
116  }
117
118  checkObjectDiff(): boolean {
119    return !isBaseOrResourceEqual(this.stageValue, this.value);
120  }
121}
122
123class PanelCustomHeightModifier extends ModifierWithKey<Dimension | PanelHeight> {
124  constructor(value: Dimension | PanelHeight) {
125    super(value);
126  }
127  static identity: Symbol = Symbol('panelCustomHeight');
128  applyPeer(node: KNode, reset: boolean): void {
129    if (reset) {
130      getUINativeModule().panel.resetPanelCustomHeight(node);
131    } else {
132      getUINativeModule().panel.setPanelCustomHeight(node, this.value);
133    }
134  }
135
136  checkObjectDiff(): boolean {
137    return !isBaseOrResourceEqual(this.stageValue, this.value);
138  }
139}
140
141class PanelFullHeightModifier extends ModifierWithKey<string | number> {
142  constructor(value: string | number) {
143    super(value);
144  }
145  static identity: Symbol = Symbol('panelFullHeight');
146  applyPeer(node: KNode, reset: boolean): void {
147    if (reset) {
148      getUINativeModule().panel.resetPanelFullHeight(node);
149    } else {
150      getUINativeModule().panel.setPanelFullHeight(node, this.value);
151    }
152  }
153
154  checkObjectDiff(): boolean {
155    return !isBaseOrResourceEqual(this.stageValue, this.value);
156  }
157}
158
159class PanelHalfHeightModifier extends ModifierWithKey<string | number> {
160  constructor(value: string | number) {
161    super(value);
162  }
163  static identity: Symbol = Symbol('panelHalfHeight');
164  applyPeer(node: KNode, reset: boolean): void {
165    if (reset) {
166      getUINativeModule().panel.resetPanelHalfHeight(node);
167    } else {
168      getUINativeModule().panel.setPanelHalfHeight(node, this.value);
169    }
170  }
171
172  checkObjectDiff(): boolean {
173    return !isBaseOrResourceEqual(this.stageValue, this.value);
174  }
175}
176
177class PanelMiniHeightModifier extends ModifierWithKey<string | number> {
178  constructor(value: string | number) {
179    super(value);
180  }
181  static identity: Symbol = Symbol('panelMiniHeight');
182  applyPeer(node: KNode, reset: boolean): void {
183    if (reset) {
184      getUINativeModule().panel.resetPanelMiniHeight(node);
185    } else {
186      getUINativeModule().panel.setPanelMiniHeight(node, this.value);
187    }
188  }
189
190  checkObjectDiff(): boolean {
191    return !isBaseOrResourceEqual(this.stageValue, this.value);
192  }
193}
194
195class ShowCloseIconModifier extends ModifierWithKey<boolean> {
196  constructor(value: boolean) {
197    super(value);
198  }
199  static identity: Symbol = Symbol('showCloseIcon');
200  applyPeer(node: KNode, reset: boolean) {
201    if (reset) {
202      getUINativeModule().panel.resetShowCloseIcon(node);
203    } else {
204      getUINativeModule().panel.setShowCloseIcon(node, this.value);
205    }
206  }
207
208  checkObjectDiff(): boolean {
209    return !isBaseOrResourceEqual(this.stageValue, this.value);
210  }
211}
212
213class DragBarModifier extends ModifierWithKey<boolean> {
214  constructor(value: boolean) {
215    super(value);
216  }
217  static identity: Symbol = Symbol('dragBar');
218  applyPeer(node: KNode, reset: boolean) {
219    if (reset) {
220      getUINativeModule().panel.resetDragBar(node);
221    } else {
222      getUINativeModule().panel.setDragBar(node, this.value);
223    }
224  }
225
226  checkObjectDiff(): boolean {
227    return !isBaseOrResourceEqual(this.stageValue, this.value);
228  }
229}
230
231class ShowModifier extends ModifierWithKey<boolean> {
232  constructor(value: boolean) {
233    super(value);
234  }
235  static identity: Symbol = Symbol('show');
236  applyPeer(node: KNode, reset: boolean) {
237    if (reset) {
238      getUINativeModule().panel.resetShow(node);
239    } else {
240      getUINativeModule().panel.setShow(node, this.value);
241    }
242  }
243
244  checkObjectDiff(): boolean {
245    return !isBaseOrResourceEqual(this.stageValue, this.value);
246  }
247}
248
249// @ts-ignore
250globalThis.Panel.attributeModifier = function (modifier: ArkComponent): void {
251  attributeModifierFunc.call(this, modifier, (nativePtr: KNode) => {
252    return new ArkPanelComponent(nativePtr);
253  }, (nativePtr: KNode, classType: ModifierType, modifierJS: ModifierJS) => {
254    return new modifierJS.PanelModifier(nativePtr, classType);
255  });
256};
257