source stringlengths 14 113 | code stringlengths 10 21.3k |
|---|---|
application-dev\ui\ndk-access-the-arkts-page.md | import { NodeContent } from '@kit.ArkUI';
import nativeNode from 'libentry.so';
@Entry
@Component
struct Index {
// Initialize the NodeContent object.
private rootSlot = new NodeContent();
@State @Watch('changeNativeFlag') showNative: boolean = false;
changeNativeFlag(): void {
if (t... |
application-dev\ui\ndk-access-the-arkts-page.md | import nativeNode from 'libentry.so';
import { NodeContent } from '@kit.ArkUI';
@Entry
@Component
struct Index {
// Initialize the NodeContent object.
private rootSlot = new NodeContent();
@State @Watch('changeNativeFlag') showNative: boolean = false;
changeNativeFlag(): void {
... |
application-dev\ui\ndk-access-the-arkts-page.md | // entry/src/main/cpp/types/libentry/Index.d.ts
export const createNativeRoot: (content: Object) => void;
export const destroyNativeRoot: () => void; |
application-dev\ui\ndk-embed-arkts-components.md | // MixedModule.ets
// Create ArkTS components using the ComponentContent capability.
import { NodeContent, UIContext, RefreshModifier, ComponentContent } from '@kit.ArkUI';
// Define the data object for interaction between the native side and ArkTS.
interface NativeRefreshAttribute {
isRefresh... |
application-dev\ui\ndk-embed-arkts-components.md | // entry.ets
import nativeNode from 'libentry.so';
import { NodeContent } from '@kit.ArkUI';
import { createMixedRefresh, updateMixedRefresh } from './MixedModule'
@Entry
@Component
struct Index {
private rootSlot = new NodeContent();
@State @Watch('changeNativeFlag') showNative: boolean... |
application-dev\ui\ndk-use-animation.md | // createNativeNode is an API exposed on the native side.
nativeNode.createNativeNode("xcomponentId", this.getUIContext()); |
application-dev\ui\theme_skinning.md | import { CustomColors, CustomTheme } from '@kit.ArkUI'
export class AppColors implements CustomColors {
// Custom theme colors
brand: ResourceColor = '#FF75D9';
}
export class AppTheme implements CustomTheme {
public colors: AppColors = new AppColors()
}
export let gAppTheme... |
application-dev\ui\theme_skinning.md | import { Theme, ThemeControl } from '@kit.ArkUI'
import { gAppTheme } from './AppTheme'
// Execute ThemeControl before the page builds.
ThemeControl.setDefaultTheme(gAppTheme)
@Entry
@Component
struct DisplayPage {
@State menuItemColor: ResourceColor = $r('sys.color.background_primar... |
application-dev\ui\theme_skinning.md | import {AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
import { window, CustomColors, ThemeControl } from '@kit.ArkUI';
class AppColors implements CustomColors {
fontPrimary = 0xFFD53032
iconOnPrimary = 0xFFD53032
iconFourth... |
application-dev\ui\theme_skinning.md | import { CustomColors, CustomTheme, Theme } from '@kit.ArkUI'
class AppColors implements CustomColors {
fontPrimary: ResourceColor = $r('app.color.brand_purple')
backgroundEmphasize: ResourceColor = $r('app.color.brand_purple')
}
class AppColorsSec implements CustomColors {
fontPrima... |
application-dev\ui\theme_skinning.md | {
"color": [
{
"name": "start_window_background",
"value": "#FFFFFF"
}
]
} |
application-dev\ui\theme_skinning.md | @Entry
@Component
struct DisplayPage {
@State message: string = 'Hello World';
@State colorMode: ThemeColorMode = ThemeColorMode.DARK;
build() {
WithTheme({ colorMode: this.colorMode }) {
Row() {
Column() {
Text(this.message)
.fontSi... |
application-dev\ui\ui-dark-light-color-adaptation.md | Text('Use system-defined colors')
.fontColor($r('sys.color.ohos_id_color_text_primary')) |
application-dev\ui\ui-dark-light-color-adaptation.md | Image($r('app.media.pic_svg'))
.width(50)
.fillColor($r('sys.color.ohos_id_color_text_primary')) |
application-dev\ui\ui-dark-light-color-adaptation.md | onCreate(): void {
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate');
AppStorage.setOrCreate('currentColorMode', this.context.config.colorMode);
} |
application-dev\ui\ui-dark-light-color-adaptation.md | onConfigurationUpdate(newConfig: Configuration): void {
AppStorage.setOrCreate('currentColorMode', newConfig.colorMode);
hilog.info(0x0000, 'testTag', 'the newConfig.colorMode is %{public}s', JSON.stringify(AppStorage.get('currentColorMode')) ?? '');
} |
application-dev\ui\ui-dark-light-color-adaptation.md | @StorageProp('currentColorMode') @Watch('onColorModeChange') currentMode: number = ConfigurationConstant.ColorMode.COLOR_MODE_LIGHT; |
application-dev\ui\ui-dark-light-color-adaptation.md | aboutToAppear(): void {
if (this.currentMode == ConfigurationConstant.ColorMode.COLOR_MODE_LIGHT) {
// Light mode initialization logic
}else {
// Dark mode initialization logic
}
} |
application-dev\ui\ui-dark-light-color-adaptation.md | onColorModeChange(): void {
if (this.currentMode == ConfigurationConstant.ColorMode.COLOR_MODE_LIGHT) {
// Light mode initialization logic
} else {
// Dark mode initialization logic
}
} |
application-dev\ui\ui-dark-light-color-adaptation.md | onCreate(): void {
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate');
this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_DARK);
} |
application-dev\ui\ui-dark-light-color-adaptation.md | onCreate(): void {
this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET);
} |
application-dev\ui\state-management\arkts-animatable-extend.md | @AnimatableExtend(UIComponentName) function functionName(value: typeName) {
.propertyName(value)
} |
application-dev\ui\state-management\arkts-animatable-extend.md | @AnimatableExtend(Text)
function animatableWidth(width: number) {
.width(width)
}
@Entry
@Component
struct AnimatablePropertyExample {
@State textWidth: number = 80;
build() {
Column() {
Text("AnimatableProperty")
.animatableWidth(this.textWidth)
.animation({ duration: 2000, curve: Cur... |
application-dev\ui\state-management\arkts-animatable-extend.md | class Point {
x: number
y: number
constructor(x: number, y: number) {
this.x = x
this.y = y
}
plus(rhs: Point): Point {
return new Point(this.x + rhs.x, this.y + rhs.y)
}
subtract(rhs: Point): Point {
return new Point(this.x - rhs.x, this.y - rhs.y)
}
multiply(scale: number): Point... |
application-dev\ui\state-management\arkts-appstorage.md | AppStorage.setOrCreate('PropA', 47);
// Incorrect format. An error is reported during compilation.
@StorageProp() storageProp: number = 1;
@StorageLink() storageLink: number = 2;
// Correct format.
@StorageProp('PropA') storageProp: number = 1;
@StorageLink('PropA') storageLink: number = 2; |
application-dev\ui\state-management\arkts-appstorage.md | AppStorage.setOrCreate('PropA', 47);
let storage: LocalStorage = new LocalStorage();
storage.setOrCreate('PropA',17);
let propA: number | undefined = AppStorage.get('PropA') // propA in AppStorage == 47, propA in LocalStorage == 17
let link1: SubscribedAbstractProperty<number> = AppStorage.link('PropA'); // link1.get(... |
application-dev\ui\state-management\arkts-appstorage.md | class Data {
code: number;
constructor(code: number) {
this.code = code;
}
}
AppStorage.setOrCreate('PropA', 47);
AppStorage.setOrCreate('PropB', new Data(50));
let storage = new LocalStorage();
storage.setOrCreate('LinkA', 48);
storage.setOrCreate('LinkB', new Data(100));
@Entry(storage)
@Component
struct... |
application-dev\ui\state-management\arkts-appstorage.md | // xxx.ets
class ViewData {
title: string;
uri: Resource;
color: Color = Color.Black;
constructor(title: string, uri: Resource) {
this.title = title;
this.uri = uri
}
}
@Entry
@Component
struct Gallery {
// 'app.media.icon' is only an example. Replace it with the actual one in use. Otherwise, the ... |
application-dev\ui\state-management\arkts-appstorage.md | // xxx.ets
import { emitter } from '@kit.BasicServicesKit';
let NextID: number = 0;
class ViewData {
title: string;
uri: Resource;
color: Color = Color.Black;
id: number;
constructor(title: string, uri: Resource) {
this.title = title;
this.uri = uri
this.id = NextID++;
}
}
@Entry
@Component
... |
application-dev\ui\state-management\arkts-appstorage.md | // xxx.ets
class ViewData {
title: string;
uri: Resource;
color: Color = Color.Black;
constructor(title: string, uri: Resource) {
this.title = title;
this.uri = uri
}
}
@Entry
@Component
struct Gallery {
// 'app.media.icon' is only an example. Replace it with the actual one in use. Otherwise, the ... |
application-dev\ui\state-management\arkts-appstorage.md | @Component
struct StorLink {
@StorageLink("LinkA") LinkA: number | null = null;
@StorageLink("LinkB") LinkB: number | undefined = undefined;
build() {
Column() {
Text("@StorageLink initialization, @StorageLink value")
Text(this.LinkA + "").fontSize(20).onClick(() => {
this.LinkA ? this.Li... |
application-dev\ui\state-management\arkts-appstorage.md | @Entry
@Component
struct DateSample {
@StorageLink("date") selectedDate: Date = new Date('2021-08-08');
build() {
Column() {
Button('set selectedDate to 2023-07-08')
.margin(10)
.onClick(() => {
AppStorage.setOrCreate("date", new Date('2023-07-08'));
})
Button('inc... |
application-dev\ui\state-management\arkts-appstorage.md | @Entry
@Component
struct MapSample {
@StorageLink("map") message: Map<number, string> = new Map([[0, "a"], [1, "b"], [3, "c"]]);
build() {
Row() {
Column() {
ForEach(Array.from(this.message.entries()), (item: [number, string]) => {
Text(`${item[0]}`).fontSize(30)
Text(`${item[... |
application-dev\ui\state-management\arkts-appstorage.md | @Entry
@Component
struct SetSample {
@StorageLink("set") memberSet: Set<number> = new Set([0, 1, 2, 3, 4]);
build() {
Row() {
Column() {
ForEach(Array.from(this.memberSet.entries()), (item: [number, string]) => {
Text(`${item[0]}`)
.fontSize(30)
Divider()
}... |
application-dev\ui\state-management\arkts-appstorage.md | AppStorage.setOrCreate('PropA', false);
@Entry
@Component
struct Index {
@StorageProp('PropA') @Watch('onChange') propA: boolean = false;
onChange() {
console.log(`propA change`);
}
aboutToAppear(): void {
this.propA = true;
}
build() {
Column() {
Text(`${this.propA}`)
Button('ch... |
application-dev\ui\state-management\arkts-builder.md | @Entry
@Component
struct BuilderDemo {
@Builder
showTextBuilder() {
Text('Hello World')
.fontSize(30)
.fontWeight(FontWeight.Bold)
}
@Builder
showTextValueBuilder(param: string) {
Text(param)
.fontSize(30)
.fontWeight(FontWeight.Bold)
}
build() {
Column() {
// Wit... |
application-dev\ui\state-management\arkts-builder.md | this.showTextBuilder() |
application-dev\ui\state-management\arkts-builder.md | @Builder
function showTextBuilder() {
Text('Hello World')
.fontSize(30)
.fontWeight(FontWeight.Bold)
}
@Entry
@Component
struct BuilderDemo {
build() {
Column() {
showTextBuilder()
}
}
} |
application-dev\ui\state-management\arkts-builder.md | showTextBuilder() |
application-dev\ui\state-management\arkts-builder.md | @Builder function overBuilder(paramA1: string) {
Row() {
Text(`UseStateVarByValue: ${paramA1} `)
}
}
@Entry
@Component
struct Parent {
@State label: string = 'Hello';
build() {
Column() {
overBuilder(this.label)
}
}
} |
application-dev\ui\state-management\arkts-builder.md | class Tmp {
paramA1: string = '';
}
@Builder function overBuilder(params: Tmp) {
Row() {
Text(`UseStateVarByReference: ${params.paramA1} `)
}
}
@Entry
@Component
struct Parent {
@State label: string = 'Hello';
build() {
Column() {
// When the overBuilder component is called in the parent compon... |
application-dev\ui\state-management\arkts-builder.md | @Entry
@Component
struct PrivateBuilder {
@State builder_value: string = 'Hello';
@Builder builder() {
Column(){
Text(this.builder_value)
.fontSize(30)
.fontWeight(FontWeight.Bold)
}
}
aboutToAppear(): void {
setTimeout(() => {
this.builder_value = 'Hello World';
},... |
application-dev\ui\state-management\arkts-builder.md | class ChildTmp {
val: number = 1;
}
class Tmp {
str_value: string = 'Hello';
num_value: number = 0;
tmp_value: ChildTmp = new ChildTmp();
arrayTmp_value: Array<ChildTmp> = [];
}
@Builder function overBuilder(param: Tmp) {
Column() {
Text(`str_value: ${param.str_value}`)
Text(`num_value: ${param.nu... |
application-dev\ui\state-management\arkts-builder.md | class Tmp {
str_value: string = 'Hello';
}
@Entry
@Component
struct Parent {
@State objParam: Tmp = new Tmp();
@State label: string = 'World';
@Builder privateBuilder() {
Column() {
Text(`wrapBuilder str_value: ${this.objParam.str_value}`)
Text(`wrapBuilder num: ${this.label}`)
}
}
bu... |
application-dev\ui\state-management\arkts-builder.md | @Builder
function overBuilder() {
Row() {
Text('Global Builder')
.fontSize(30)
.fontWeight(FontWeight.Bold)
}
}
@Entry
@Component
struct customBuilderDemo {
@State arr: number[] = [0, 1, 2, 3, 4];
@Builder
privateBuilder() {
Row() {
Text('Local Builder')
.fontSize(30)
... |
application-dev\ui\state-management\arkts-builder.md | class Tmp {
paramA1: string = '';
}
@Builder function parentBuilder($$: Tmp) {
Row() {
Column() {
Text(`parentBuilder===${$$.paramA1}`)
.fontSize(30)
.fontWeight(FontWeight.Bold)
HelloComponent({message: $$.paramA1})
childBuilder({paramA1: $$.paramA1})
}
}
}
@Component
... |
application-dev\ui\state-management\arkts-builder.md | @ObservedV2
class Info {
@Trace name: string = '';
@Trace age: number = 0;
}
@Builder
function overBuilder(param: Info) {
Column() {
Text('Global @Builder name :${param.name}`)
.fontSize(30)
.fontWeight(FontWeight.Bold)
Text('Global @Builder age :${param.age}`)
.fontSize(30)
.font... |
application-dev\ui\state-management\arkts-builder.md | class GlobalTmp {
str_value: string = 'Hello';
}
@Builder function overBuilder(param: GlobalTmp, num: number) {
Column() {
Text(`str_value: ${param.str_value}`)
Text(`num: ${num}`)
}
}
@Entry
@Component
struct Parent {
@State objParam: GlobalTmp = new GlobalTmp();
@State num: number = 0;
build() {... |
application-dev\ui\state-management\arkts-builder.md | class GlobalTmp {
str_value: string = 'Hello';
}
class SecondTmp {
num_value: number = 0;
}
@Builder function overBuilder(param: GlobalTmp, num: SecondTmp) {
Column() {
Text(`str_value: ${param.str_value}`)
Text(`num: ${num.num_value}`)
}
}
@Entry
@Component
struct Parent {
@State strParam: GlobalTmp... |
application-dev\ui\state-management\arkts-builder.md | class GlobalTmp {
str_value: string = 'Hello';
num_value: number = 0;
}
@Builder function overBuilder(param: GlobalTmp) {
Column() {
Text(`str_value: ${param.str_value}`)
Text(`num: ${param.num_value}`)
}
}
@Entry
@Component
struct Parent {
@State objParam: GlobalTmp = new GlobalTmp();
build() {
... |
application-dev\ui\state-management\arkts-builder.md | @ObservedV2
class ParamTmp {
@Trace count : number = 0;
}
@Builder
function renderNumber(paramNum: number) {
Text(`paramNum : ${paramNum}`)
.fontSize(30)
.fontWeight(FontWeight.Bold)
}
@Entry
@ComponentV2
struct PageBuilder {
@Local class_value: ParamTmp = new ParamTmp();
// Using simple data type can... |
application-dev\ui\state-management\arkts-builder.md | @ObservedV2
class ParamTmp {
@Trace count : number = 0;
}
@Builder
function renderText(param: ParamTmp) {
Column() {
Text(`param : ${param.count}`)
.fontSize(20)
.fontWeight(FontWeight.Bold)
}
}
@Builder
function renderMap(paramMap: Map<string,number>) {
Text(`paramMap : ${paramMap.get('name')... |
application-dev\ui\state-management\arkts-builder.md | interface Temp {
paramA: string;
}
@Builder function overBuilder(param: Temp) {
Row() {
Column() {
Button(`overBuilder === ${param.paramA}`)
.onClick(() => {
// Incorrect format. Parameter values cannot be changed in the function decorated by @Builder.
param.paramA = 'Yes';
... |
application-dev\ui\state-management\arkts-builder.md | interface Temp {
paramA: string;
}
@Builder function overBuilder(param: Temp) {
Row() {
Column() {
Button(`overBuilder === ${param.paramA}`)
}
}
}
@Entry
@Component
struct Parent {
@State label: string = 'Hello';
build() {
Column() {
overBuilder({paramA: this.label})
Button('c... |
application-dev\ui\state-management\arkts-builderparam.md | @Builder function overBuilder() {}
@Component
struct Child {
@Builder doNothingBuilder() {};
// Use the custom builder function of the custom component for @BuilderParam initialization.
@BuilderParam customBuilderParam: () => void = this.doNothingBuilder;
// Use the global custom builder function f... |
application-dev\ui\state-management\arkts-builderparam.md | @Component
struct Child {
@Builder customBuilder() {};
@BuilderParam customBuilderParam: () => void = this.customBuilder;
build() {
Column() {
this.customBuilderParam()
}
}
}
@Entry
@Component
struct Parent {
@Builder componentBuilder() {
Text(`Parent builder `)... |
application-dev\ui\state-management\arkts-builderparam.md | @Component
struct Child {
label: string = 'Child';
@Builder customBuilder() {};
@Builder customChangeThisBuilder() {};
@BuilderParam customBuilderParam: () => void = this.customBuilder;
@BuilderParam customChangeThisBuilderParam: () => void = this.customChangeThisBuilder;
build(... |
application-dev\ui\state-management\arkts-builderparam.md | class Tmp{
label: string = '';
}
@Builder function overBuilder($$: Tmp) {
Text($$.label)
.width(400)
.height(50)
.backgroundColor(Color.Green)
}
@Component
struct Child {
label: string = 'Child';
@Builder customBuilder() {};
// Without parameters. The pointed customBuilder does not carry paramet... |
application-dev\ui\state-management\arkts-builderparam.md | @Component
struct CustomContainer {
@Prop header: string = '';
@Builder closerBuilder(){};
// Use the trailing closure {} (@Builder decorated method) of the parent component for @BuilderParam initialization.
@BuilderParam closer: () => void = this.closerBuilder;
build() {
Column() {
Text(this.heade... |
application-dev\ui\state-management\arkts-builderparam.md | @ComponentV2
struct ChildPage {
@Require @Param message: string = "";
@Builder customBuilder() {};
@BuilderParam customBuilderParam: () => void = this.customBuilder;
build() {
Column() {
Text(this.message)
.fontSize(30)
.fontWeight(FontWeight.Bold)
this.customBuilderParam()
... |
application-dev\ui\state-management\arkts-builderparam.md | @Component
struct ChildPage {
label: string = 'Child Page';
@Builder customBuilder() {};
@BuilderParam customBuilderParam: () => void = this.customBuilder;
@BuilderParam customChangeThisBuilderParam: () => void = this.customBuilder;
build() {
Column() {
this.customBuilderParam()
this.customCh... |
application-dev\ui\state-management\arkts-builderparam.md | @ComponentV2
struct ChildPage {
@Param label: string = 'Child Page';
@Builder customBuilder() {};
@BuilderParam customBuilderParam: () => void = this.customBuilder;
@BuilderParam customChangeThisBuilderParam: () => void = this.customBuilder;
build() {
Column() {
this.customBuilderParam()
this... |
application-dev\ui\state-management\arkts-builderparam.md | @Component
struct ChildPage {
@State label: string = 'Child Page';
@Builder customBuilder() {};
@BuilderParam customChangeThisBuilderParam: () => void = this.customBuilder;
build() {
Column() {
this.customChangeThisBuilderParam()
}
}
}
@Entry
@Component
struct ParentPage {
@State label: stri... |
application-dev\ui\state-management\arkts-builderparam.md | @Component
struct ChildPage {
@State label: string = 'Child Page';
@Builder customBuilder() {};
@BuilderParam customChangeThisBuilderParam: () => void = this.customBuilder;
build() {
Column() {
this.customChangeThisBuilderParam()
}
}
}
@Entry
@Component
struct ParentPage {
@State label: stri... |
application-dev\ui\state-management\arkts-builderparam.md | @Builder function globalBuilder() {
Text('Hello World')
}
@Entry
@Component
struct customBuilderDemo {
build() {
Column() {
// No value is assigned to ChildBuilder. An error is reported during compilation or editing.
ChildPage()
}
}
}
@Component
struct ChildPage {
@Require @BuilderParam Ch... |
application-dev\ui\state-management\arkts-builderparam.md | @Builder function globalBuilder() {
Text('Hello World')
}
@Entry
@Component
struct customBuilderDemo {
build() {
Column() {
ChildPage({ChildBuilder: globalBuilder})
}
}
}
@Component
struct ChildPage {
@Require @BuilderParam ChildBuilder: () => void = globalBuilder;
build() {
Column() {
... |
application-dev\ui\state-management\arkts-builderparam.md | @Builder function globalBuilder() {
Text('Hello World')
}
@Entry
@Component
struct customBuilderDemo {
@State message: string = "";
build() {
Column() {
// ChildBuilder receives the variable decorated by @State. An error is reported during compilation or editing.
ChildPage({ChildBuilder: this.mess... |
application-dev\ui\state-management\arkts-builderparam.md | @Builder function globalBuilder() {
Text('Hello World')
}
@Entry
@Component
struct customBuilderDemo {
build() {
Column() {
ChildPage({ChildBuilder: globalBuilder})
}
}
}
@Component
struct ChildPage {
@BuilderParam ChildBuilder: () => void = globalBuilder;
build() {
Column() {
this.Ch... |
application-dev\ui\state-management\arkts-create-custom-components.md | @Component
struct HelloComponent {
@State message: string = 'Hello, World!';
build() {
// The HelloComponent custom component combines the <Row> and <Text> built-in components.
Row() {
Text(this.message)
.onClick(() => {
// The change of the state variable message drives the UI to b... |
application-dev\ui\state-management\arkts-create-custom-components.md | @Entry
@Component
struct ParentComponent {
build() {
Column() {
Text('ArkUI message')
HelloComponent({ message: 'Hello World!' });
Divider()
HelloComponent({message: 'Hello, World!'});
}
}
} |
application-dev\ui\state-management\arkts-create-custom-components.md | @Component
struct MyComponent {
} |
application-dev\ui\state-management\arkts-create-custom-components.md | @Component({ freezeWhenInactive: true })
struct MyComponent {
} |
application-dev\ui\state-management\arkts-create-custom-components.md | @Component
struct MyComponent {
build() {
}
} |
application-dev\ui\state-management\arkts-create-custom-components.md | @Entry
@Component
struct MyComponent {
} |
application-dev\ui\state-management\arkts-create-custom-components.md | @Entry({ routeName : 'myPage' })
@Component
struct MyComponent {
} |
application-dev\ui\state-management\arkts-create-custom-components.md | @Reusable
@Component
struct MyComponent {
} |
application-dev\ui\state-management\arkts-create-custom-components.md | @Component
struct MyComponent {
private countDownFrom: number = 0;
private color: Color = Color.Blue;
build() {
}
}
@Entry
@Component
struct ParentComponent {
private someColor: Color = Color.Pink;
build() {
Column() {
// Create an instance of MyComponent and initialize its countDownFrom variab... |
application-dev\ui\state-management\arkts-create-custom-components.md | @Entry
@Component
struct Parent {
@State cnt: number = 0
submit: () => void = () => {
this.cnt++;
}
build() {
Column() {
Text(`${this.cnt}`)
Son({ submitArrow: this.submit })
}
}
}
@Component
struct Son {
submitArrow?: () => void
build() {
Row() {
Button('add')
... |
application-dev\ui\state-management\arkts-create-custom-components.md | @Entry
@Component
struct MyComponent {
build() {
// Exactly one root component is required, and it must be a container component.
Row() {
ChildComponent()
}
}
}
@Component
struct ChildComponent {
build() {
// Exactly one root component is required, and it is not... |
application-dev\ui\state-management\arkts-create-custom-components.md | build() {
// Avoid: declaring a local variable.
let num: number = 1;
} |
application-dev\ui\state-management\arkts-create-custom-components.md | build() {
// Avoid: using console.info directly in UI description.
console.info('print debug log');
} |
application-dev\ui\state-management\arkts-create-custom-components.md | build() {
// Avoid: creating a local scope.
{
// ...
}
} |
application-dev\ui\state-management\arkts-create-custom-components.md | @Component
struct ParentComponent {
doSomeCalculations() {
}
calcTextValue(): string {
return 'Hello World';
}
@Builder doSomeRender() {
Text(`Hello World`)
}
build() {
Column() {
// Avoid: calling a method not decorated by @Builder.
this.doSomeCalculat... |
application-dev\ui\state-management\arkts-create-custom-components.md | build() {
Column() {
// Avoid: using the switch syntax.
switch (expression) {
case 1:
Text('...')
break;
case 2:
Image('...')
break;
default:
Text('...')
break;
}
// Correct usage: Use if.
if(expression... |
application-dev\ui\state-management\arkts-create-custom-components.md | build() {
Column() {
// Avoid: expressions.
(this.aVar > 10) ? Text('...') : Image('...')
// Positive example: Use if for judgment.
if(this.aVar > 10) {
Text('...')
} else {
Image('...')
}
}
} |
application-dev\ui\state-management\arkts-create-custom-components.md | @Component
struct MyComponent {
@State textColor: Color = Color.Yellow;
@State columnColor: Color = Color.Green;
@State count: number = 1;
build() {
Column() {
// Avoid: directly changing the value of count in the <Text> component.
Text(`${this.count++}`)
.width(50)
... |
application-dev\ui\state-management\arkts-create-custom-components.md | // Avoid the usage below.
@State arr : Array<...> = [ ... ];
ForEach(this.arr.sort().filter(...),
item => {
// ...
})
// Prefer: Call filter before sort() to return a new array. In this way, sort() does not change this.arr.
ForEach(this.arr.filter(...).sort(),
item => {
/... |
application-dev\ui\state-management\arkts-create-custom-components.md | @Component
struct ChildComponent {
build() {
Button(`Hello World`)
}
}
@Entry
@Component
struct MyComponent {
build() {
Row() {
ChildComponent()
.width(200)
.height(300)
.backgroundColor(Color.Red)
}
}
} |
application-dev\ui\state-management\arkts-custom-components-access-restrictions.md | @Entry
@Component
struct AccessRestrictions {
@Builder
buildTest() {
Text("Parent builder")
}
build() {
Column() {
ComponentsChild({
state_value: "Hello",
prop_value: "Hello",
provide_value: "Hello",
builder_value: this.buildTest,
regular_value: "Hello"
... |
application-dev\ui\state-management\arkts-custom-components-access-restrictions.md | Property 'state_value' is private and can not be initialized through the component constructor.
Property 'prop_value' is private and can not be initialized through the component constructor.
Property 'provide_value' is private and can not be initialized through the component constructor.
Property 'builder_value' is pri... |
application-dev\ui\state-management\arkts-custom-components-access-restrictions.md | @Entry
@Component
struct AccessRestrictions {
@Builder
buildTest() {
Text("Parent builder")
}
build() {
Column() {
ComponentsChild({
state_value: "Hello",
prop_value: "Hello",
provide_value: "Hello",
builder_value: this.buildTest,
regular_value: "Hello"
... |
application-dev\ui\state-management\arkts-custom-components-access-restrictions.md | @Entry
@Component
struct AccessRestrictions {
@Provide consume_value: string = "Hello";
build() {
Column() {
ComponentChild()
}
.width('100%')
}
}
@Component
struct ComponentChild {
// The public access is not allowed and an alarm is reported.
@LocalStorageProp("sessionLocalProp") public lo... |
application-dev\ui\state-management\arkts-custom-components-access-restrictions.md | Property 'local_prop_value' can not be decorated with both @LocalStorageProp and public.
Property 'local_link_value' can not be decorated with both @LocalStorageLink and public.
Property 'storage_prop_value' can not be decorated with both @StorageProp and public.
Property 'storage_link_value' can not be decorated with ... |
application-dev\ui\state-management\arkts-custom-components-access-restrictions.md | @Entry
@Component
struct AccessRestrictions {
@Provide consume_value: string = "Hello";
build() {
Column() {
ComponentChild()
}
.width('100%')
}
}
@Component
struct ComponentChild {
@LocalStorageProp("sessionLocalProp") local_prop_value: string = "Hello";
@LocalStorageLink("sessionLocalLink... |
application-dev\ui\state-management\arkts-custom-components-access-restrictions.md | @Entry
@Component
struct AccessRestrictions {
@State link_value: string = "Hello";
@State objectLink_value: ComponentObj = new ComponentObj();
build() {
Column() {
ComponentChild({link_value: this.link_value, objectLink_value: this.objectLink_value})
}
.width('100%')
}
}
@Observed
class Compo... |
application-dev\ui\state-management\arkts-custom-components-access-restrictions.md | Property 'link_value' can not be decorated with both @Link and private.
Property 'objectLink_value' can not be decorated with both @ObjectLink and private. |
application-dev\ui\state-management\arkts-custom-components-access-restrictions.md | @Entry
@Component
struct AccessRestrictions {
@State link_value: string = "Hello";
@State objectLink_value: ComponentObj = new ComponentObj();
build() {
Column() {
ComponentChild({link_value: this.link_value, objectLink_value: this.objectLink_value})
}
.width('100%')
}
}
@Observed
class Compo... |
application-dev\ui\state-management\arkts-custom-components-access-restrictions.md | @Entry
@Component
struct AccessRestrictions {
build() {
Column() {
ComponentChild({regular_value: "Hello"})
}
.width('100%')
}
}
@Component
struct ComponentChild {
// The protected access is not allowed and an alarm is reported.
protected regular_value: string = "Hello";
build() {
Colum... |
application-dev\ui\state-management\arkts-custom-components-access-restrictions.md | The member attributes of a struct can not be protected. |
application-dev\ui\state-management\arkts-custom-components-access-restrictions.md | @Entry
@Component
struct AccessRestrictions {
build() {
Column() {
ComponentChild({regular_value: "Hello"})
}
.width('100%')
}
}
@Component
struct ComponentChild {
regular_value: string = "Hello";
build() {
Column() {
Text("Hello")
.fontSize(50)
.fontWeight(FontWeigh... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.