• 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
16
17//  ArkTS1.2
18import { memo, __memo_context_type, __memo_id_type } from "@ohos.arkui.stateManagement" // should be insert by ui-plugins
19import { ArkUICompatible, InteropComponent, Text, TextAttribute, Column, Component, Button, ButtonAttribute, ClickEvent, UserView, } from "@ohos.arkui.component" // TextAttribute should be insert by ui-plugins
20import { State, StateDecoratedVariable, MutableState, stateOf, observableProxy, Observed, Track, Provide, Consume } from "@ohos.arkui.stateManagement" // should be insert by ui-plugins
21import { MyText } from 'har2/src/main/ets/components/MainPage'
22import { Child1 } from 'har1'
23
24
25@Component
26struct MyStateSample {
27    @State stateVar: new MyText();
28    build() {
29        Column() {
30            Button(this.stateVar.text)
31                .onClick((e: ClickEvent) => {
32                    this.stateVar.text += '~';
33                })
34            Child1({stateVar: this.stateVar, text: this.stateVar})
35        }
36    }
37}
38
39class MyText {
40    text: string = 'MyText';
41}
42
43
44//ArkT1.1
45import { MyText } from 'har2/src/main/ets/components/MainPage'
46
47@Component
48export struct Child1{
49    @Link stateVar: MyText;
50    @Link text: MyText;
51    build() {
52        Column() {
53            Button(this.stateVar.text)
54                .onClick(() => {
55                    this.stateVar.text += '~';
56                })
57            Button(this.text.text)
58                .onClick(() => {
59                    this.text.text = 'ArkTS1.1';
60                })
61        }
62    }
63}
64
65
66//transform 1.1struct 'Child1' to ArkUICompatible
67
68ArkUICompatible(__memo_context, ((__memo_id) + (252133223)), (() => {
69    let global = ESValue.getGlobal();
70    let param = ESValue.instantiateEmptyObject();
71    let createState = global.getProperty("createStateVariable");
72    let stateVar_SetSource = ((value: B) => {
73        (this).stateVar = value;
74    });
75    let stateVar_ProxyState = createState.invoke(ESValue.wrap((this).stateVar), ESValue.wrap(stateVar_SetSource));
76    (this).__backing_stateVar!.setProxy(stateVar_ProxyState);
77    let stateVar_SetProxy = ((value: B) => {
78        stateVar_ProxyState.invokeMethod("set", ESValue.wrap(value));
79    });
80    (this).__backing_stateVar!.setProxyValue = stateVar_SetProxy;
81    let stateVar_NotifyCallback = ((propertyName: string) => {
82        stateVar_ProxyState.invokeMethod("notifyPropertyHasChangedPU");
83    });
84    (this).__backing_stateVar!.setNotifyCallback(stateVar_NotifyCallback);
85    param.setProperty("stateVar", stateVar_ProxyState);
86    param.setProperty("text", stateVar_ProxyState);
87    let extraInfo = ESValue.instantiateEmptyObject();
88    extraInfo.setProperty("page", "har1/src/main/ets/components/MainPage");
89    let esundefined = ESValue.wrap(undefined);
90    let blank = (() => {});
91    let esblank = ESValue.wrap((blank as object));
92    let viewStackProcessor = global.getProperty("ViewStackProcessor");
93    let createId = viewStackProcessor.getProperty("AllocateNewElmetIdForNextComponent");
94    let elmtId = createId.invoke();
95    let har1 = ESValue.load("@normalized:N&entry&com.example.Interop2use1&har1/src/main/ets/components/MainPage&1.0.0");
96    let structObject = har1.getProperty("Child1");
97    let component = structObject.instantiate(esundefined, param, esundefined, elmtId, esblank, extraInfo);
98    let create = structObject.getProperty("create");
99    create.invoke(component);
100    return {
101        component: component,
102        name: "Child1",
103    };
104}), ((instance: ESValue) => {}));