Custom component built-in APIs are APIs predefined on the base class of custom components in the ArkUI framework. You can call these APIs on the instance of a custom component to obtain information, such as the UI context, about the instance.
The initial APIs of this module are supported since API version 11. Newly added APIs will be marked with a superscript to indicate their earliest API version.
getUIContext(): UIContext
Obtains the UIContext instance.
Atomic service API: This API can be used in atomic services since API version 12.
System capability: SystemCapability.ArkUI.ArkUI.Full
Return value
| Type | Description |
|---|---|
| UIContext | UIContext instance obtained. |
Example
import { UIContext } from '@kit.ArkUI';
@Entry
@Component
struct MyComponent {
aboutToAppear() {
let uiContext: UIContext = this.getUIContext();
}
build() {
// ...
}
} getUniqueId(): number
Obtains the unique ID of this component. This unique ID is assigned by the system to each component. If this API is called before the component's corresponding node is created or after it has been destroyed, an invalid unique ID, which is -1, will be returned.
Atomic service API: This API can be used in atomic services since API version 12.
System capability: SystemCapability.ArkUI.ArkUI.Full
Return value
| Type | Description |
|---|---|
| number | Unique ID of the current Component. |
Example
@Entry
@Component
struct MyComponent {
aboutToAppear() {
let uniqueId: number = this.getUniqueId();
}
build() {
// ...
}
} queryRouterPageInfo(): RouterPageInfo | undefined;
Obtains a RouterPageInfo instance.
Atomic service API: This API can be used in atomic services since API version 12.
System capability: SystemCapability.ArkUI.ArkUI.Full
Return value
| Type | Description |
|---|---|
| RouterPageInfo | undefined | RouterPageInfo instance obtained. |
Example
import { uiObserver } from '@kit.ArkUI'
@Entry
@Component
struct MyComponent {
aboutToAppear() {
let info: uiObserver.RouterPageInfo | undefined = this.queryRouterPageInfo();
}
build() {
// ...
}
}