• 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  Component,
17  Button,
18  ButtonAttribute,
19  ClickEvent,
20  UserView,
21  NavDestination,
22  NavPathStack,
23  NavDestinationContext,
24  Callback
25} from '@ohos.arkui.component'  // TextAttribute should be insert by ui-plugins
26
27import hilog from '@ohos.hilog'
28import { UIContext, FrameCallback } from '@ohos.arkui.UIContext'
29import common from '@ohos.app.ability.common';
30import { FrameNode } from '@ohos.arkui.node';
31import { Size } from '@ohos.arkui.node';
32import { Router } from '@ohos.arkui.UIContext';
33
34@Component
35export struct GetHostContextTest {
36  @State stateVar: string = 'state var';
37  message: string = 'var';
38  changeValue() {
39    this.stateVar+='~'
40  }
41  build() {
42    NavDestination() {
43      Column(undefined) {
44        Button('getHostContext功能测试')
45          .backgroundColor('#FFFF00FF')
46          .onClick((e: ClickEvent) => {
47            let uicontext = this.getUIContext();
48            if (uicontext) {
49              let host_context = uicontext.getHostContext()
50              if (host_context) {
51                let context = host_context! as common.UIAbilityContext;
52                if (context) {
53                  hilog.info(0x0000, 'testTag', 'wll context' + context?.filesDir);
54                } else {
55                  hilog.info(0x0000, 'testTag', 'wll context null ');
56                }
57              }
58            }
59          })
60      }
61    }
62    .title('getHostContext功能测试')
63  }
64}
65
66@Component
67struct Child {
68  @State stateVar: string = 'Child';
69  build() {
70    Text(this.stateVar).fontSize(50)
71  }
72}