ts-universal-attributes-visibility.md 1.6 KB
Newer Older
Z
zengyawen 已提交
1
# Visibility
Z
zengyawen 已提交
2

E
ester.zhou 已提交
3
The visibility attribute controls whether a component is visible.
Z
zengyawen 已提交
4

E
ester.zhou 已提交
5 6 7
> **NOTE**
>
> This event is supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version.
Z
zengyawen 已提交
8 9 10


## Required Permissions
Z
zengyawen 已提交
11 12 13

None

Z
zengyawen 已提交
14

Z
zengyawen 已提交
15 16 17
## Attributes


E
ester.zhou 已提交
18
| Name| Type| Default Value| Description|
Z
zengyawen 已提交
19
| -------- | -------- | -------- | -------- |
E
esterzhou 已提交
20
| visibility | [Visibility](ts-appendix-enums.md#visibility) | Visibility.Visible | Whether the component is visible. Note that even if a component is hidden, it needs to be re-created when the page is refreshed. Therefore, you are advised to use [conditional rendering](../../ui/ts-rending-control-syntax-if-else.md) instead under scenarios where consistently high performance is required. |
Z
zengyawen 已提交
21 22 23 24


## Example

E
ester.zhou 已提交
25 26
```ts
// xxx.ets
Z
zengyawen 已提交
27 28 29 30 31 32 33 34 35 36
@Entry
@Component
struct VisibilityExample {
  build() {
    Column() {
      Column() {
        Text('Visible').fontSize(9).width('90%').fontColor(0xCCCCCC)
        Row().visibility(Visibility.Visible).width('90%').height(80).backgroundColor(0xAFEEEE)

        Text('None').fontSize(9).width('90%').fontColor(0xCCCCCC)
E
ester.zhou 已提交
37
        // The component is hidden, and no placeholder is used.
Z
zengyawen 已提交
38 39 40
        Row().visibility(Visibility.None).width('90%').height(80).backgroundColor(0xAFEEEE)

        Text('Hidden').fontSize(9).width('90%').fontColor(0xCCCCCC)
E
ester.zhou 已提交
41
        // The component is hidden, and a placeholder is used for it in the layout.
Z
zengyawen 已提交
42 43 44 45 46 47 48
        Row().visibility(Visibility.Hidden).width('90%').height(80).backgroundColor(0xAFEEEE)
      }.width('90%').border({ width: 1 })
    }.width('100%').margin({ top: 5 })
  }
}
```

Z
zengyawen 已提交
49
![en-us_image_0000001257058421](figures/en-us_image_0000001257058421.gif)