• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2023 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 Constants from '../../util/Constants';
17
18@Preview
19@Component
20export struct RenderControlWithoutStack {
21  @State isVisible: boolean = true;
22  private data: number[] = [];
23
24  aboutToAppear() {
25    for (let i: number = 0; i < Constants.IMAGE_TOTAL_NUM; i++) {
26      this.data.push(i);
27    }
28  }
29
30  build() {
31    Column() {
32      Stack() {
33        Scroll() {
34          Column() { // 刷新范围会扩展到这一层
35            if (this.isVisible) { // 条件变化会触发创建和销毁该组件,影响到容器的布局,该容器内所有组件都会刷新
36              Text('New item').fontSize($r('app.integer.font_size_20'))
37            }
38            ForEach(this.data, (item: number) => {
39              Text(`Item value: ${item}`)
40                .fontSize($r('app.integer.font_size_20'))
41                .width($r('app.string.layout_100_percent'))
42                .textAlign(TextAlign.Center)
43            }, (item: number) => item.toString())
44          }
45        }
46      }.height($r('app.string.layout_90_percent'))
47
48      Button('Switch Hidden and Show').onClick(() => {
49        this.isVisible = !(this.isVisible);
50      })
51    }
52  }
53}
54