• 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' />
17
18class ArkNavigatorComponent extends ArkComponent implements NavigatorAttribute {
19  constructor(nativePtr: KNode, classType?: ModifierType) {
20    super(nativePtr, classType);
21  }
22  active(value: boolean): this {
23    modifierWithKey(this._modifiersWithKeys, ActiveModifier.identity, ActiveModifier, value);
24    return this;
25  }
26  type(value: NavigationType): this {
27    modifierWithKey(this._modifiersWithKeys, TypeModifier.identity, TypeModifier, value);
28    return this;
29  }
30  target(value: string): this {
31    modifierWithKey(this._modifiersWithKeys, TargetModifier.identity, TargetModifier, value);
32    return this;
33  }
34  params(value: object): this {
35    modifierWithKey(this._modifiersWithKeys, ParamsModifier.identity, ParamsModifier, JSON.stringify(value));
36    return this;
37  }
38}
39
40class ParamsModifier extends ModifierWithKey<string> {
41  constructor(value: string) {
42    super(value);
43  }
44  static identity: Symbol = Symbol('params');
45
46  applyPeer(node: KNode, reset: boolean): void {
47    if (reset) {
48      getUINativeModule().navigator.resetParams(node);
49    } else {
50      getUINativeModule().navigator.setParams(node, this.value);
51    }
52  }
53}
54
55class TypeModifier extends ModifierWithKey<number> {
56  constructor(value: number) {
57    super(value);
58  }
59  static identity: Symbol = Symbol('type');
60
61  applyPeer(node: KNode, reset: boolean): void {
62    if (reset) {
63      getUINativeModule().navigator.resetType(node);
64    } else {
65      getUINativeModule().navigator.setType(node, this.value);
66    }
67  }
68}
69
70class ActiveModifier extends ModifierWithKey<boolean> {
71  constructor(value: boolean) {
72    super(value);
73  }
74  static identity: Symbol = Symbol('active');
75
76  applyPeer(node: KNode, reset: boolean): void {
77    if (reset) {
78      getUINativeModule().navigator.resetActive(node);
79    } else {
80      getUINativeModule().navigator.setActive(node, this.value);
81    }
82  }
83}
84
85class TargetModifier extends ModifierWithKey<string> {
86  constructor(value: string) {
87    super(value);
88  }
89  static identity: Symbol = Symbol('target');
90
91  applyPeer(node: KNode, reset: boolean): void {
92    if (reset) {
93      getUINativeModule().navigator.resetTarget(node);
94    } else {
95      getUINativeModule().navigator.setTarget(node, this.value);
96    }
97  }
98}
99
100// @ts-ignore
101globalThis.Navigator.attributeModifier = function (modifier: ArkComponent): void {
102  attributeModifierFunc.call(this, modifier, (nativePtr: KNode) => {
103    return new ArkNavigatorComponent(nativePtr);
104  }, (nativePtr: KNode, classType: ModifierType, modifierJS: ModifierJS) => {
105    return new modifierJS.NavigatorModifier(nativePtr, classType);
106  });
107};
108