• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1import {
2  memo,
3  __memo_context_type,
4  __memo_id_type,
5  State,
6  StateDecoratedVariable,
7  MutableState,
8  stateOf,
9  observableProxy
10} from '@ohos.arkui.stateManagement' // should be insert by ui-plugins
11
12import {
13  Text,
14  TextAttribute,
15  Column,
16  Row,
17  Component,
18  Button,
19  ButtonAttribute,
20  ClickEvent,
21  UserView,
22  animateTo,
23  Curve,
24  $r,
25  Entry,
26  NodeContainer,
27  NavDestination,
28  NavPathStack,
29  NavDestinationContext,
30  Callback
31} from '@ohos.arkui.component' // TextAttribute should be insert by ui-plugins
32
33import hilog from '@ohos.hilog'
34import { UIContext } from '@ohos.arkui.UIContext'
35import { NodeController, FrameNode } from '@ohos.arkui.node'
36
37class MyNodeController extends NodeController {
38  makeNode(uiContext: UIContext): FrameNode | null {
39    let node = new FrameNode(uiContext);
40    return node;
41  }
42  onWillBind(): void{
43    console.log('kkk myButton aboutToAppear')
44  }
45
46  onWillUnbind(): void{
47    console.log('kkk myButton onWillUnbind')
48  }
49
50  aboutToAppear(): void {
51    console.log('kkk myButton aboutToAppear')
52  }
53
54  aboutToDisappear(): void {
55    console.log('kkk myButton aboutToDisappear');
56  }
57
58  onBind(containerId: number): void {
59    console.log('kkk myButton on bind: ' + containerId);
60  }
61
62  onUnbind(containerId: number): void {
63    console.log('kkk myButton on unbind: ' + containerId);
64  }
65
66  onAttach(): void {
67    console.log('kkk myButton on attach');
68  }
69
70  onDetach(): void {
71    console.log('kkk myButton on detach');
72  }
73}
74
75@Entry
76@Component
77export struct ResourceTest {
78  @State isShow: boolean = true
79  @State index_: number = 0
80  private controller: MyNodeController = new MyNodeController()  // 运行正常
81  private controllerNull: null = null;
82  private controllerArray: Array<MyNodeController | null> = [this.controller, this.controllerNull]
83
84
85
86  build() {
87    NavDestination() {
88      Column(undefined) {
89        Text('Hello World').fontSize(60)
90        Text($r('app.string.app_name'))
91        Text('' + this.isShow)
92
93        Button('切换上下树')
94          .onClick((e: ClickEvent) => {
95            this.isShow = !this.isShow
96          })
97        Button('上树')
98          .onClick((e: ClickEvent) => {
99            this.isShow = true
100          })
101        Button('下树')
102          .onClick((e: ClickEvent) => {
103            this.isShow = false
104          })
105
106        if (this.isShow) {
107          NodeContainer(this.controller)
108        }
109
110      }
111    }
112    .title('$r使用资源测试')
113  }
114}