• 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/**
17 * @file
18 * @kit ArkUI
19 */
20
21import type { Callback } from './@ohos.base';
22import type UIAbilityContext from './application/UIAbilityContext';
23
24/**
25 * Register callbacks to observe ArkUI behavior.
26 *
27 * @namespace uiObserver
28 * @syscap SystemCapability.ArkUI.ArkUI.Full
29 * @crossplatform
30 * @since 11
31 */
32declare namespace uiObserver {
33  /**
34   * NavDestination state.
35   *
36   * @enum { number }
37   * @syscap SystemCapability.ArkUI.ArkUI.Full
38   * @crossplatform
39   * @since 11
40   * @form
41   */
42  export enum NavDestinationState {
43    /**
44     * When the NavDestination show.
45     *
46     * @syscap SystemCapability.ArkUI.ArkUI.Full
47     * @crossplatform
48     * @since 11
49     * @form
50     */
51    ON_SHOWN = 0,
52
53    /**
54     * When the NavDestination hidden.
55     *
56     * @syscap SystemCapability.ArkUI.ArkUI.Full
57     * @crossplatform
58     * @since 11
59     * @form
60     */
61    ON_HIDDEN = 1
62  }
63
64  /**
65   * Router page state.
66   *
67   * @enum { number }
68   * @syscap SystemCapability.ArkUI.ArkUI.Full
69   * @crossplatform
70   * @since 11
71   */
72  export enum RouterPageState {
73    /**
74     * When the router page create.
75     *
76     * @syscap SystemCapability.ArkUI.ArkUI.Full
77     * @crossplatform
78     * @since 11
79     */
80    ABOUT_TO_APPEAR = 0,
81
82    /**
83     * When the router page destroy.
84     *
85     * @syscap SystemCapability.ArkUI.ArkUI.Full
86     * @crossplatform
87     * @since 11
88     */
89    ABOUT_TO_DISAPPEAR = 1,
90
91    /**
92     * When the router page show.
93     *
94     * @syscap SystemCapability.ArkUI.ArkUI.Full
95     * @crossplatform
96     * @since 11
97     */
98    ON_PAGE_SHOW = 2,
99
100    /**
101     * When the router page hide.
102     *
103     * @syscap SystemCapability.ArkUI.ArkUI.Full
104     * @crossplatform
105     * @since 11
106     */
107    ON_PAGE_HIDE = 3,
108
109    /**
110     * When back press event happened in the router page.
111     *
112     * @syscap SystemCapability.ArkUI.ArkUI.Full
113     * @crossplatform
114     * @since 11
115     */
116    ON_BACK_PRESS = 4
117  }
118
119  /**
120   * NavDestination info.
121   *
122   * @interface NavDestinationInfo
123   * @syscap SystemCapability.ArkUI.ArkUI.Full
124   * @crossplatform
125   * @since 11
126   */
127  export interface NavDestinationInfo {
128    /**
129     * Navigation id.
130     *
131     * @type { ResourceStr }
132     * @syscap SystemCapability.ArkUI.ArkUI.Full
133     * @crossplatform
134     * @since 11
135     */
136    navigationId: ResourceStr,
137
138    /**
139     * Changed NavDestination name.
140     *
141     * @type { ResourceStr }
142     * @syscap SystemCapability.ArkUI.ArkUI.Full
143     * @crossplatform
144     * @since 11
145     */
146    name: ResourceStr,
147
148    /**
149     * Changed NavDestination state.
150     *
151     * @type { NavDestinationState }
152     * @syscap SystemCapability.ArkUI.ArkUI.Full
153     * @crossplatform
154     * @since 11
155     */
156    state: NavDestinationState
157  }
158
159  /**
160   * Router page info.
161   *
162   * @syscap SystemCapability.ArkUI.ArkUI.Full
163   * @crossplatform
164   * @since 11
165   */
166  export class RouterPageInfo {
167    /**
168     * The context of the changed router page.
169     *
170     * @type { UIAbilityContext | UIContext }
171     * @syscap SystemCapability.ArkUI.ArkUI.Full
172     * @crossplatform
173     * @since 11
174     */
175    context: UIAbilityContext | UIContext;
176
177    /**
178     * The index of the changed router page in router stack.
179     *
180     * @type { number }
181     * @syscap SystemCapability.ArkUI.ArkUI.Full
182     * @crossplatform
183     * @since 11
184     */
185    index: number;
186
187    /**
188     * The name of the changed router page.
189     *
190     * @type { string }
191     * @syscap SystemCapability.ArkUI.ArkUI.Full
192     * @crossplatform
193     * @since 11
194     */
195    name: string;
196
197    /**
198     * The path of the changed router page.
199     *
200     * @type { string }
201     * @syscap SystemCapability.ArkUI.ArkUI.Full
202     * @crossplatform
203     * @since 11
204     */
205    path: string;
206
207    /**
208     * The state of the changed router page.
209     *
210     * @type { RouterPageState }
211     * @syscap SystemCapability.ArkUI.ArkUI.Full
212     * @crossplatform
213     * @since 11
214     */
215    state: RouterPageState;
216  }
217
218  /**
219   * Registers a callback function to be called when the navigation destination is updated.
220   *
221   * @param { 'navDestinationUpdate' } type - The type of event to listen for. Must be 'navDestinationUpdate'.
222   * @param { object } options - The options object.
223   * @param { Callback<NavDestinationInfo> } callback - The callback function to be called when the navigation destination is updated.
224   * @syscap SystemCapability.ArkUI.ArkUI.Full
225   * @crossplatform
226   * @since 11
227   */
228  export function on(type: 'navDestinationUpdate', options: { navigationId: ResourceStr }, callback: Callback<NavDestinationInfo>): void;
229
230  /**
231   * Removes a callback function that was previously registered with `on()`.
232   *
233   * @param { 'navDestinationUpdate' } type - The type of event to remove the listener for. Must be 'navDestinationUpdate'.
234   * @param { object } options - The options object.
235   * @param { Callback<NavDestinationInfo> } callback - The callback function to remove. If not provided, all callbacks for the given event type and
236   *                                                    navigation ID will be removed.
237   * @syscap SystemCapability.ArkUI.ArkUI.Full
238   * @crossplatform
239   * @since 11
240   */
241  export function off(type: 'navDestinationUpdate', options: { navigationId: ResourceStr }, callback?: Callback<NavDestinationInfo>): void;
242
243  /**
244   * Registers a callback function to be called when the navigation destination is updated.
245   *
246   * @param { 'navDestinationUpdate' } type - The type of event to listen for. Must be 'navDestinationUpdate'.
247   * @param { Callback<NavDestinationInfo> } callback - The callback function to be called when the navigation destination is updated.
248   * @syscap SystemCapability.ArkUI.ArkUI.Full
249   * @crossplatform
250   * @since 11
251   */
252  export function on(type: 'navDestinationUpdate', callback: Callback<NavDestinationInfo>): void;
253
254  /**
255   * Removes a callback function that was previously registered with `on()`.
256   *
257   * @param { 'navDestinationUpdate'} type - The type of event to remove the listener for. Must be 'navDestinationUpdate'.
258   * @param { Callback<NavDestinationInfo> } [callback] - The callback function to remove. If not provided, all callbacks for the given event type
259   *                                                      will be removed.
260   * @syscap SystemCapability.ArkUI.ArkUI.Full
261   * @crossplatform
262   * @since 11
263   */
264  export function off(type: 'navDestinationUpdate', callback?: Callback<NavDestinationInfo>): void;
265
266  /**
267   * Registers a callback function to be called when the router page is updated.
268   *
269   * @param { 'routerPageUpdate' } type - The type of event to listen for. Must be 'routerPageUpdate'.
270   * @param { UIAbilityContext | UIContext } context - The context scope of the observer.
271   * @param { Callback<RouterPageInfo> } callback - The callback function to be called when the router page is updated.
272   * @syscap SystemCapability.ArkUI.ArkUI.Full
273   * @crossplatform
274   * @since 11
275   */
276  export function on(type: 'routerPageUpdate', context: UIAbilityContext | UIContext, callback: Callback<RouterPageInfo>): void;
277
278  /**
279   * Removes a callback function that was previously registered with `on()`.
280   *
281   * @param { 'routerPageUpdate' } type - The type of event to remove the listener for. Must be 'routerPageUpdate'.
282   * @param { UIAbilityContext | UIContext } context - The context scope of the observer.
283   * @param { Callback<RouterPageInfo> } [callback] - The callback function to remove. If not provided, all callbacks for the given event type
284   *                                                               will be removed.
285   * @syscap SystemCapability.ArkUI.ArkUI.Full
286   * @crossplatform
287   * @since 11
288   */
289  export function off(type: 'routerPageUpdate', context: UIAbilityContext | UIContext, callback?: Callback<RouterPageInfo>): void;
290}
291
292export default uiObserver;
293