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 { memo, __memo_context_type, __memo_id_type } from "@ohos.arkui.stateManagement" // should be insert by ui-plugins 17import { Text, TextAttribute, Column, Component, Button, ButtonAttribute, ClickEvent, UserView } from "@ohos.arkui.component" // TextAttribute should be insert by ui-plugins 18import { State, Link, StateDecoratedVariable, LinkDecoratedVariable,MutableState, stateOf, observableProxy } from "@ohos.arkui.stateManagement" // should be insert by ui-plugins 19import hilog from '@ohos.hilog' 20 21function ArkUICompatible(init:(elmtId: number, instance: ESObject) => void, update: ((elmtId: number, instance: ESObject) => void)) { 22 23} 24 25@Component 26struct MyStateSample { 27 @State stateVar: string = "Parent"; 28 message: string = "var"; 29 changeValue() { 30 this.stateVar+="~"; 31 } 32 build() { 33 Column(undefined) { 34 Button("ParentChange").backgroundColor("#FFFF00FF") 35 .onClick((e: ClickEvent) => { 36 hilog.info(0x0000, 'testTag', 'On Click'); 37 this.changeValue(); 38 }) 39 Text(this.stateVar).fontSize(20) 40 ChildLink({stateVar: this.stateVar, stateVar1: this.stateVar, stateVar2: ""} as __Options_ChildLink) 41 } 42 } 43} 44 45@Component 46struct ChildLink { 47 @Link stateVar: string = "Child"; 48 @State stateVar1: string = "Child"; 49 @Link stateVar2: string = "Child"; 50 changeValue() { 51 this.stateVar+="~"; 52 } 53 build() { 54 Button("ChildChange").backgroundColor("#FFFF00FF") 55 .onClick((e: ClickEvent) => { 56 hilog.info(0x0000, 'testTag', 'On Click'); 57 this.changeValue(); 58 }) 59 Text(this.stateVar).fontSize(50) 60 } 61} 62 63export class ComExampleTrivialApplication extends UserView { 64 getBuilder() { 65 hilog.info(0x0000, 'testTag', 'getBuilder'); 66 let wrapper = @memo () => { 67 hilog.info(0x0000, 'testTag', 'MyStateSample'); 68 MyStateSample(undefined); 69 } 70 return wrapper; 71 } 72}