• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2025 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
16import router from "@ohos/router";
17import { ArkUIGeneratedNativeModule } from "#components"
18import { InteropNativeModule } from "@koalaui/interop/InteropNativeModule";
19import { KPointer } from "@koalaui/interop/InteropTypes";
20import { runtimeType, RuntimeType } from "@koalaui/interop";
21import { int32, int8 } from "@koalaui/common";
22import { Serializer } from "../component/peers/Serializer";
23
24export class RouterExtender {
25    public static routerPush(options: router.RouterOptions): KPointer {
26        const url = options.url as (string)
27        const retVal = ArkUIGeneratedNativeModule._RouterExtender_RouterPush1attribute(url)
28        return retVal
29    }
30
31    public static routerReplace(options: router.RouterOptions, finishCallback: () => void): KPointer {
32        const thisSerializer : Serializer = Serializer.hold()
33        const url = options.url as (string)
34        thisSerializer.writeString(url)
35        let value_type : int32 = RuntimeType.UNDEFINED
36        value_type = runtimeType(finishCallback)
37        thisSerializer.writeInt8(value_type as int32)
38        if ((RuntimeType.UNDEFINED) != (value_type)) {
39            const value_value  = finishCallback! as (() => void)
40            thisSerializer.holdAndWriteCallback(value_value)
41        }
42        const retVal = ArkUIGeneratedNativeModule._RouterExtender_RouterReplace1attribute(thisSerializer.asBuffer(), thisSerializer.length())
43        thisSerializer.release()
44        return retVal
45    }
46
47    public static routerPushUrl(options: router.RouterOptions): Promise<void> {
48        return new Promise<void>(() => {})
49    }
50
51    public static routerBack(options?: router.RouterOptions): void {
52        if (options) {
53            const url = options.url as (string)
54        } else {
55            ArkUIGeneratedNativeModule._RouterExtender_RouterBack0attribute()
56        }
57    }
58
59    public static routerClear(): void {
60        ArkUIGeneratedNativeModule._RouterExtender_RouterClear()
61    }
62
63    public static routerRunPage(options: router.RouterOptions): KPointer {
64        const url = options.url as (string)
65        const retVal = ArkUIGeneratedNativeModule._RouterExtender_RouterRunPage(url)
66        return retVal
67    }
68
69    public static moveCommonUnderPageNode(commonNode: KPointer, pageNode: KPointer): void {
70        ArkUIGeneratedNativeModule._RouterExtender_MoveCommonUnderPageNode(commonNode, pageNode)
71    }
72}