source stringlengths 14 113 | code stringlengths 10 21.3k |
|---|---|
application-dev\ui\state-management\arkts-rendering-control-lazyforeach.md | /** For details about the BasicDataSource code of the StringData array, see the sample code at the end of this topic. **/
class MyDataSource extends BasicDataSource {
private dataArray: StringData[] = [];
public totalCount(): number {
return this.dataArray.length;
}
public getData(index: number): StringD... |
application-dev\ui\state-management\arkts-rendering-control-lazyforeach.md | /** For details about the BasicDataSource code of the StringData array, see the sample code at the end of this topic. **/
class MyDataSource extends BasicDataSource {
private dataArray: StringData[] = [];
public totalCount(): number {
return this.dataArray.length;
}
public getData(index: number): StringD... |
application-dev\ui\state-management\arkts-rendering-control-lazyforeach.md | /** For details about the BasicDataSource code of the StringData array, see the sample code at the end of this topic. **/
class MyDataSource extends BasicDataSource {
private dataArray: StringData[] = [];
public totalCount(): number {
return this.dataArray.length;
}
public getData(index: number): StringD... |
application-dev\ui\state-management\arkts-rendering-control-lazyforeach.md | /** For details about the BasicDataSource code of the StringData array, see the sample code at the end of this topic. **/
class MyDataSource extends BasicDataSource {
private dataArray: StringData[] = [];
public totalCount(): number {
return this.dataArray.length;
}
public getData(index: number): StringD... |
application-dev\ui\state-management\arkts-rendering-control-lazyforeach.md | /** For details about the BasicDataSource code of the string array, see the sample code at the end of this topic. **/
class MyDataSource extends BasicDataSource {
private dataArray: string[] = [];
public totalCount(): number {
return this.dataArray.length;
}
public getData(index: number): string {
re... |
application-dev\ui\state-management\arkts-rendering-control-lazyforeach.md | /** For details about the BasicDataSource code of the string array, see the sample code at the end of this topic. **/
class MyDataSource extends BasicDataSource {
private dataArray: string[] = [];
public totalCount(): number {
return this.dataArray.length;
}
public getData(index: number): string {
re... |
application-dev\ui\state-management\arkts-rendering-control-lazyforeach.md | /** For details about the BasicDataSource code of the string array, see the sample code at the end of this topic. **/
class MyDataSource extends BasicDataSource {
private dataArray: string[] = [];
public totalCount(): number {
return this.dataArray.length;
}
public getData(index: number): string {
re... |
application-dev\ui\state-management\arkts-rendering-control-lazyforeach.md | /** For details about the BasicDataSource code of the StringData array, see the sample code at the end of this topic. **/
class MyDataSource extends BasicDataSource {
private dataArray: StringData[] = [];
public totalCount(): number {
return this.dataArray.length;
}
public getData(index: number): StringD... |
application-dev\ui\state-management\arkts-rendering-control-lazyforeach.md | /** For details about the BasicDataSource code of the StringData array, see the sample code at the end of this topic. **/
class MyDataSource extends BasicDataSource {
private dataArray: StringData[] = [];
public totalCount(): number {
return this.dataArray.length;
}
public getData(index: number): StringD... |
application-dev\ui\state-management\arkts-rendering-control-lazyforeach.md | /** For details about the BasicDataSource code of the StringData array, see the sample code at the end of this topic. **/
class MyDataSource extends BasicDataSource {
private dataArray: StringData[] = [];
public totalCount(): number {
return this.dataArray.length;
}
public getData(index: number): StringD... |
application-dev\ui\state-management\arkts-rendering-control-lazyforeach.md | /** For details about the BasicDataSource code of the StringData array, see the sample code at the end of this topic. **/
class MyDataSource extends BasicDataSource {
private dataArray: StringData[] = [];
public totalCount(): number {
return this.dataArray.length;
}
public getData(index: number): StringD... |
application-dev\ui\state-management\arkts-rendering-control-lazyforeach.md | /** For details about the BasicDataSource code of the string array, see the sample code at the end of this topic. **/
class MyDataSource extends BasicDataSource {
private dataArray: string[] = [];
public totalCount(): number {
return this.dataArray.length;
}
public getData(index: number): string {
re... |
application-dev\ui\state-management\arkts-rendering-control-lazyforeach.md | /** For details about the BasicDataSource code of the string array, see the sample code at the end of this topic. **/
class MyDataSource extends BasicDataSource {
private dataArray: string[] = [];
public totalCount(): number {
return this.dataArray.length;
}
public getData(index: number): string {
re... |
application-dev\ui\state-management\arkts-rendering-control-lazyforeach.md | /** For details about the BasicDataSource code of the StringData array, see the sample code at the end of this topic. **/
class MyDataSource extends BasicDataSource {
private dataArray: StringData[] = [];
public totalCount(): number {
return this.dataArray.length;
}
public getData(index: number): StringD... |
application-dev\ui\state-management\arkts-rendering-control-lazyforeach.md | /** For details about the BasicDataSource code of the string array, see the sample code at the end of this topic. **/
class MyDataSource extends BasicDataSource {
private dataArray: string[] = [];
public totalCount(): number {
return this.dataArray.length;
}
public getData(index: number): string {
re... |
application-dev\ui\state-management\arkts-rendering-control-lazyforeach.md | LazyForEach(this.data, (item: string) => {
ListItem() {
Text(item).fontSize(50)
}
}, (item: string) => item) // Define a function for key generation. |
application-dev\ui\state-management\arkts-rendering-control-lazyforeach.md | // BasicDataSource implements the IDataSource API to manage listeners and notify LazyForEach of data updates.
class BasicDataSource implements IDataSource {
private listeners: DataChangeListener[] = [];
private originDataArray: string[] = [];
public totalCount(): number {
return 0;
}
public getData(inde... |
application-dev\ui\state-management\arkts-rendering-control-lazyforeach.md | class BasicDataSource implements IDataSource {
private listeners: DataChangeListener[] = [];
private originDataArray: StringData[] = [];
public totalCount(): number {
return 0;
}
public getData(index: number): StringData {
return this.originDataArray[index];
}
registerDataChangeListener(listene... |
application-dev\ui\state-management\arkts-require.md | @Entry
@Component
struct Index {
@State message: string = 'Hello World';
@Builder buildTest() {
Row() {
Text('Hello, world')
.fontSize(30)
}
}
build() {
Row() {
Child({ regular_value: this.message, state_value: this.message, provide_value: this.message, initMessage: this.messag... |
application-dev\ui\state-management\arkts-require.md | @ObservedV2
class Info {
@Trace name: string = '';
@Trace age: number = 0;
}
@ComponentV2
struct ChildPage {
@Require @Param childInfo: Info = new Info();
@Require @Param state_value: string = "Hello";
build() {
Column() {
Text(`ChildPage childInfo name :${this.childInfo.name}`)
.fontSize(2... |
application-dev\ui\state-management\arkts-require.md | @Entry
@Component
struct Index {
message: string = 'Hello World';
build() {
Column() {
Child({ message: this.message })
}
}
}
@Component
struct Child {
@Require @State message: string;
build() {
Column() {
Text(this.message) // Compilation succeeds since API version 16.
}
}
} |
application-dev\ui\state-management\arkts-require.md | @Entry
@Component
struct Index {
@State message: string = 'Hello World';
@Builder buildTest() {
Row() {
Text('Hello, world')
.fontSize(30)
}
}
build() {
Row() {
Child()
}
}
}
@Component
struct Child {
@Builder buildFunction() {
Column() {
Text('initBuilderPar... |
application-dev\ui\state-management\arkts-reusable.md | import { ComponentContent } from "@kit.ArkUI";
// An error is reported when @Builder is used together with @Reusable.
// @Reusable
@Builder
function buildCreativeLoadingDialog(closedClick: () => void) {
Crash()
}
@Component
export struct Crash {
build() {
Column() {
Text("Crash")
.fontSize(12)
... |
application-dev\ui\state-management\arkts-reusable.md | import { ComponentContent } from "@kit.ArkUI";
@Builder
function buildCreativeLoadingDialog(closedClick: () => void) {
Crash()
}
// If @Reusable is commented out, the dialog box displays properly; if @Reusable is added, the project crashes.
@Reusable
@Component
export struct Crash {
build() {
Column() {
... |
application-dev\ui\state-management\arkts-reusable.md | @Entry
@Component
struct Index {
@State isPlaying: boolean = false;
@State isPlaying02: boolean = true;
@State isPlaying01: boolean = false;
build() {
Column() {
if (this.isPlaying02) {
// Initial state of the button: shown
Text("Default shown childbutton")
.fontSize(14)
... |
application-dev\ui\state-management\arkts-reusable.md | // xxx.ets
export class Message {
value: string | undefined;
constructor(value: string) {
this.value = value;
}
}
@Entry
@Component
struct Index {
@State switch: boolean = true;
build() {
Column() {
Button('Hello')
.fontSize(30)
.fontWeight(FontWeight.Bold)
.onClick(()... |
application-dev\ui\state-management\arkts-reusable.md | class MyDataSource implements IDataSource {
private dataArray: string[] = [];
private listener: DataChangeListener | undefined;
public totalCount(): number {
return this.dataArray.length;
}
public getData(index: number): string {
return this.dataArray[index];
}
public pushData(data: string): vo... |
application-dev\ui\state-management\arkts-reusable.md | @Entry
@Component
struct Index {
private dataSource = new MyDataSource<FriendMoment>();
aboutToAppear(): void {
for (let i = 0; i < 20; i++) {
let title = i + 1 + "test_if";
this.dataSource.pushData(new FriendMoment(i.toString(), title, 'app.media.app_icon'));
}
for (let i = 0; i < 50; i++... |
application-dev\ui\state-management\arkts-reusable.md | // xxx.ets
class MyDataSource implements IDataSource {
private dataArray: string[] = [];
public totalCount(): number {
return this.dataArray.length;
}
public getData(index: number): string {
return this.dataArray[index];
}
public pushData(data: string): void {
this.dataArray.push(data);
}
... |
application-dev\ui\state-management\arkts-reusable.md | // Class MyDataSource implements the IDataSource API.
class MyDataSource implements IDataSource {
private dataArray: number[] = [];
public pushData(data: number): void {
this.dataArray.push(data);
}
// Total data amount of the data source
public totalCount(): number {
return this.dataArray.length;
... |
application-dev\ui\state-management\arkts-reusable.md | class WaterFlowDataSource implements IDataSource {
private dataArray: number[] = [];
private listeners: DataChangeListener[] = [];
constructor() {
for (let i = 0; i <= 60; i++) {
this.dataArray.push(i);
}
}
// Obtain the data corresponding to the specified index.
public getData(index: number... |
application-dev\ui\state-management\arkts-reusable.md | @Entry
@Component
struct Index {
private dataSource = new MyDataSource<Question>();
aboutToAppear(): void {
for (let i = 0; i < 1000; i++) {
let title = i + 1 + "test_swiper";
let answers = ["test1", "test2", "test3",
"test4"];
// Add the app.media.app_icon image to the src/main/resou... |
application-dev\ui\state-management\arkts-reusable.md | @Entry
@Component
struct ListItemGroupAndReusable {
data: DataSrc2 = new DataSrc2();
@Builder
itemHead(text: string) {
Text(text)
.fontSize(20)
.backgroundColor(0xAABBCC)
.width('100%')
.padding(10)
}
aboutToAppear() {
for (let i = 0; i < 10000; i++) {
let data_1 = new ... |
application-dev\ui\state-management\arkts-reusable.md | class MyDataSource implements IDataSource {
private dataArray: string[] = [];
private listener: DataChangeListener | undefined;
public totalCount(): number {
return this.dataArray.length;
}
public getData(index: number): string {
return this.dataArray[index];
}
public pushData(data: string): vo... |
application-dev\ui\state-management\arkts-reusable.md | class MyDataSource implements IDataSource {
private dataArray: string[] = [];
private listener: DataChangeListener | undefined;
public totalCount(): number {
return this.dataArray.length;
}
public getData(index: number): string {
return this.dataArray[index];
}
public pushData(data: string): vo... |
application-dev\ui\state-management\arkts-state-management-best-practices.md | @Observed
class MyClass {
public num: number = 0;
constructor(num: number) {
this.num = num;
}
}
@Component
struct PropChild {
@Prop testClass: MyClass; // @Prop makes a deep copy.
build() {
Text(`PropChild testNum ${this.testClass.num}`)
}
}
@Entry
@Component
struct Parent {
@State testClass:... |
application-dev\ui\state-management\arkts-state-management-best-practices.md | @Observed
class MyClass {
public num: number = 0;
constructor(num: number) {
this.num = num;
}
}
@Component
struct PropChild {
@ObjectLink testClass: MyClass; // @ObjectLink does not make a deep copy.
build() {
Text(`PropChild testNum ${this.testClass.num}`)
}
}
@Entry
@Component
struct Parent {... |
application-dev\ui\state-management\arkts-state-management-best-practices.md | @Entry
@Component
struct MyComponent {
@State needsUpdate: boolean = true;
realStateArr: Array<number> = [4, 1, 3, 2]; // No state variable decorator is used.
realState: Color = Color.Yellow;
updateUIArr(param: Array<number>): Array<number> {
const triggerAGet = this.needsUpdate;
return param;
}
up... |
application-dev\ui\state-management\arkts-state-management-best-practices.md | @Entry
@Component
struct CompA {
@State realStateArr: Array<number> = [4, 1, 3, 2];
@State realState: Color = Color.Yellow;
build() {
Column({ space: 20 }) {
ForEach(this.realStateArr,
(item: Array<number>) => {
Text(`${item}`)
})
Text("add item")
.onClick(() => {... |
application-dev\ui\state-management\arkts-state-management-best-practices.md | @Observed
class Translate {
translateX: number = 20;
}
@Component
struct Title {
@ObjectLink translateObj: Translate;
build() {
Row() {
// 'app.media.icon' is only an example. Replace it with the actual one in use. Otherwise, the imageSource instance fails to be created, and subsequent operations cannot... |
application-dev\ui\state-management\arkts-state-management-best-practices.md | @Observed
class Translate {
translateX: number = 20;
}
@Component
struct Title {
build() {
Row() {
// 'app.media.icon' is only an example. Replace it with the actual one in use. Otherwise, the imageSource instance fails to be created, and subsequent operations cannot be performed.
Image($r('app.medi... |
application-dev\ui\state-management\arkts-state-management-best-practices.md | import hilog from '@ohos.hilog';
@Entry
@Component
struct Index {
@State message: string = '';
build() {
Column() {
Button ('Print Log')
.onClick(() => {
for (let i = 0; i < 10; i++) {
hilog.info(0x0000, 'TAG', '%{public}s', this.message);
}
})
.wi... |
application-dev\ui\state-management\arkts-state-management-best-practices.md | import hilog from '@ohos.hilog';
@Entry
@Component
struct Index {
@State message: string = '';
build() {
Column() {
Button ('Print Log')
.onClick(() => {
let logMessage: string = this.message;
for (let i = 0; i < 10; i++) {
hilog.info(0x0000, 'TAG', '%{public}s', ... |
application-dev\ui\state-management\arkts-state-management-best-practices.md | import { hiTraceMeter } from '@kit.PerformanceAnalysisKit';
@Entry
@Component
struct Index {
@State message: string = '';
appendMsg(newMsg: string) {
// Performance Tracing
hiTraceMeter.startTrace('StateVariable', 1);
this.message += newMsg;
this.message += ';';
this.message += '<br/>';
hi... |
application-dev\ui\state-management\arkts-state-management-best-practices.md | import { hiTraceMeter } from '@kit.PerformanceAnalysisKit';
@Entry
@Component
struct Index {
@State message: string = '';
appendMsg(newMsg: string) {
// Performance Tracing
hiTraceMeter.startTrace('TemporaryVariable', 2);
let message = this.message;
message += newMsg;
message += ';';
messa... |
application-dev\ui\state-management\arkts-state-management-overview.md | @Component
struct MyComponent {
@State count: number = 0;
private increaseBy: number = 1;
build() {
}
}
@Entry
@Component
struct Parent {
build() {
Column() {
// Initialization from the parent component: The named parameter specified here will overwrite the default value de... |
application-dev\ui\state-management\arkts-state.md | // Simple type.
@State count: number = 0;
// The value change can be observed.
this.count = 1; |
application-dev\ui\state-management\arkts-state.md | class Person {
public value: string;
constructor(value: string) {
this.value = value;
}
}
class Model {
public value: string;
public name: Person;
constructor(value: string, person: Person) {
this.value = value;
this.name = person;
}
} |
application-dev\ui\state-management\arkts-state.md | // Class type
@State title: Model = new Model('Hello', new Person('World')); |
application-dev\ui\state-management\arkts-state.md | // Assign a value to the class object.
this.title = new Model('Hi', new Person('ArkUI')); |
application-dev\ui\state-management\arkts-state.md | // Assign a value to a property of the class object.
this.title.value = 'Hi'; |
application-dev\ui\state-management\arkts-state.md | // The value assignment of the nested property cannot be observed.
this.title.name.value = 'ArkUI'; |
application-dev\ui\state-management\arkts-state.md | class Model {
public value: number;
constructor(value: number) {
this.value = value;
}
} |
application-dev\ui\state-management\arkts-state.md | // Array type
@State title: Model[] = [new Model(11), new Model(1)]; |
application-dev\ui\state-management\arkts-state.md | // Value assignment of the array
this.title = [new Model(2)]; |
application-dev\ui\state-management\arkts-state.md | // Value assignment of an array item
this.title[0] = new Model(2); |
application-dev\ui\state-management\arkts-state.md | // Array item change
this.title.pop(); |
application-dev\ui\state-management\arkts-state.md | // Array item change
this.title.push(new Model(12)); |
application-dev\ui\state-management\arkts-state.md | // The value assignment of the nested property cannot be observed.
this.title[0].value = 6; |
application-dev\ui\state-management\arkts-state.md | @Entry
@Component
struct DatePickerExample {
@State selectedDate: Date = new Date('2021-08-08');
build() {
Column() {
Button('set selectedDate to 2023-07-08')
.margin(10)
.onClick(() => {
this.selectedDate = new Date('2023-07-08');
})
Button... |
application-dev\ui\state-management\arkts-state.md | // Incorrect format. An error is reported during compilation.
@State count: number;
// Correct format.
@State count: number = 10; |
application-dev\ui\state-management\arkts-state.md | @Entry
@Component
struct MyComponent {
@State count: number = 0;
build() {
Button(`click times: ${this.count}`)
.onClick(() => {
this.count += 1;
})
}
} |
application-dev\ui\state-management\arkts-state.md | class Model {
public value: string;
constructor(value: string) {
this.value = value;
}
}
@Entry
@Component
struct EntryComponent {
build() {
Column() {
// The parameters specified here will overwrite the default values defined locally during initial render. Not all parameters need to be initiali... |
application-dev\ui\state-management\arkts-state.md | // No external value is passed to title. Use the local value new Model('Hello World') for initialization.
MyComponent({ count: 1, increaseBy: 2 })
// No external value is passed to increaseBy. Use the local value 1 for initialization.
MyComponent({ title: new Model('Hello World 2'), count: 7 }) |
application-dev\ui\state-management\arkts-state.md | // Used 1 and 2 passed from the external to initialize count and increaseBy.
MyComponent({ count: 1, increaseBy: 2 })
// Used new Model('Hello World 2') and 7 passed from the external to initialize title and count.
MyComponent({ title: new Model('Hello World 2'), count: 7 }) |
application-dev\ui\state-management\arkts-state.md | @Entry
@Component
struct MapSample {
@State 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[1]}`).fontSiz... |
application-dev\ui\state-management\arkts-state.md | @Entry
@Component
struct SetSample {
@State message: Set<number> = new Set([0, 1, 2, 3, 4]);
build() {
Row() {
Column() {
ForEach(Array.from(this.message.entries()), (item: [number]) => {
Text(`${item[0]}`).fontSize(30)
Divider()
})
Button('init set').onClick((... |
application-dev\ui\state-management\arkts-state.md | @Entry
@Component
struct EntryComponent {
build() {
Column() {
MyComponent()
}
}
}
@Component
struct MyComponent {
@State count: number | undefined = 0;
build() {
Column() {
Text(`count(${this.count})`)
Button('change')
.onClick(() => {
this.count = undefined;
... |
application-dev\ui\state-management\arkts-state.md | export default class PlayDetailViewModel {
coverUrl: string = '#00ff00';
changeCoverUrl= ()=> {
this.coverUrl = '#00F5FF';
}
} |
application-dev\ui\state-management\arkts-state.md | import PlayDetailViewModel from './PlayDetailViewModel';
@Entry
@Component
struct PlayDetailPage {
@State vm: PlayDetailViewModel = new PlayDetailViewModel();
build() {
Stack() {
Text(this.vm.coverUrl).width(100).height(100).backgroundColor(this.vm.coverUrl)
Row() {
Button('Change Color')
... |
application-dev\ui\state-management\arkts-state.md | export default class PlayDetailViewModel {
coverUrl: string = '#00ff00';
changeCoverUrl= (model:PlayDetailViewModel)=> {
model.coverUrl = '#00F5FF';
}
} |
application-dev\ui\state-management\arkts-state.md | import PlayDetailViewModel from './PlayDetailViewModel';
@Entry
@Component
struct PlayDetailPage {
@State vm: PlayDetailViewModel = new PlayDetailViewModel();
build() {
Stack() {
Text(this.vm.coverUrl).width(100).height(100).backgroundColor(this.vm.coverUrl)
Row() {
Button('Change Color')
... |
application-dev\ui\state-management\arkts-state.md | @Entry
@Component
struct Index {
@State viewModel: TestModel = new TestModel();
build() {
Row() {
Column() {
Text(this.viewModel.isSuccess ? 'success' : 'failed')
.fontSize(50)
.fontWeight(FontWeight.Bold)
.onClick(() => {
this.viewModel.query();
... |
application-dev\ui\state-management\arkts-state.md | @Entry
@Component
struct Index {
@State viewModel: TestModel = new TestModel();
build() {
Row() {
Column() {
Text(this.viewModel.isSuccess ? 'success' : 'failed')
.fontSize(50)
.fontWeight(FontWeight.Bold)
.onClick(() => {
this.viewModel.query();
... |
application-dev\ui\state-management\arkts-state.md | class Info {
address: string = 'Hangzhou'
}
@Entry
@Component
struct Test {
@State message: string =' Shanghai'
@State info: Info = new Info();
aboutToAppear(): void {
this.info.address = this.message;
}
build() {
Column() {
Text(`${this.message}`);
Text(`${this.info.address}`);
... |
application-dev\ui\state-management\arkts-state.md | class Info {
address: string = 'Hangzhou'
constructor(address: string) {
this.address = address;
}
}
class User {
info: Info = new Info('Tianjin');
}
@Entry
@Component
struct Test {
@State info: Info = new Info('Shanghai');
@State user: User = new User();
aboutToAppear(): void {
this.user.info... |
application-dev\ui\state-management\arkts-state.md | class Info {
address: string = 'Hangzhou'
constructor(address: string) {
this.address = address;
}
}
class User {
info: Info = new Info('Tianjin');
}
@Entry
@Component
struct Test {
@State info: Info = new Info('Shanghai');
@State user: User = new User();
aboutToAppear(): void {
this.user.info... |
application-dev\ui\state-management\arkts-state.md | class DataObj {
name: string = 'default name';
constructor(name: string) {
this.name = name;
}
}
@Entry
@Component
struct Index {
list: DataObj[] = [new DataObj('a'), new DataObj('b'), new DataObj('c')];
@State dataObjFromList: DataObj = this.list[0];
build() {
Column() {
ConsumerChild({ da... |
application-dev\ui\state-management\arkts-state.md | @Observed
class DataObj {
name: string = 'default name';
constructor(name: string) {
this.name = name;
}
}
@Entry
@Component
struct Index {
list: DataObj[] = [new DataObj('a'), new DataObj('b'), new DataObj('c')];
@State dataObjFromList: DataObj = this.list[0];
build() {
Column() {
Consumer... |
application-dev\ui\state-management\arkts-state.md | import { UIUtils } from '@ohos.arkui.StateManagement';
class DataObj {
name: string = 'default name';
constructor(name: string) {
this.name = name;
}
}
@Entry
@Component
struct Index {
list: DataObj[] = [new DataObj('a'), new DataObj('b'), new DataObj('c')];
@State dataObjFromList: DataObj = this.list[... |
application-dev\ui\state-management\arkts-state.md | @Entry
@Component
struct Index {
@State count: number = 1;
build() {
Column() {
// Avoid directly changing the value of count in the Text component.
Text(`${this.count++}`)
.width(50)
.height(50)
}
}
} |
application-dev\ui\state-management\arkts-state.md | FIX THIS APPLICATION ERROR: @Component 'Index'[4]: State variable 'count' has changed during render! It's illegal to change @Component state while build (initial render or re-render) is on-going. Application error! |
application-dev\ui\state-management\arkts-state.md | @Entry
@Component
struct Index {
@State message: number = 20;
build() {
Column() {
Text(`${this.message++}`)
Text(`${this.message++}`)
}
.height('100%')
.width('100%')
}
} |
application-dev\ui\state-management\arkts-state.md | class Balloon {
volume: number;
constructor(volume: number) {
this.volume = volume;
}
static increaseVolume(balloon:Balloon) {
balloon.volume += 2;
}
}
@Entry
@Component
struct Index {
@State balloon: Balloon = new Balloon(10);
reduceVolume(balloon:Balloon) {
balloon.volume -= 1;
}
bui... |
application-dev\ui\state-management\arkts-state.md | class Balloon {
volume: number;
constructor(volume: number) {
this.volume = volume;
}
static increaseVolume(balloon:Balloon) {
balloon.volume += 2;
}
}
@Entry
@Component
struct Index {
@State balloon: Balloon = new Balloon(10);
reduceVolume(balloon:Balloon) {
balloon.volume -= 1;
}
bui... |
application-dev\ui\state-management\arkts-state.md | class Model {
private callback: (() => void) | undefined = () => {};
add(callback: () => void): void {
this.callback = callback;
}
delete(): void {
this.callback = undefined;
}
call(): void {
if (this.callback) {
this.callback();
}
}
}
let model: Model = new Model();
@Entry
@Com... |
application-dev\ui\state-management\arkts-statestyles.md | @Entry
@Component
struct StateStylesSample {
build() {
Column() {
Button('Button1')
.stateStyles({
focused: {
.backgroundColor('#ffffeef0')
},
pressed: {
.backgroundColor('#ff707070')
},
normal: {
.backgroundColor(... |
application-dev\ui\state-management\arkts-statestyles.md | @Entry
@Component
struct MyComponent {
@Styles normalStyle() {
.backgroundColor(Color.Gray)
}
@Styles pressedStyle() {
.backgroundColor(Color.Red)
}
build() {
Column() {
Text('Text1')
.fontSize(50)
.fontColor(Color.White)
.stateStyles({
normal: this.normal... |
application-dev\ui\state-management\arkts-statestyles.md | @Entry
@Component
struct CompWithInlineStateStyles {
@State focusedColor: Color = Color.Red;
normalColor: Color = Color.Green
build() {
Column() {
Button('clickMe').height(100).width(100)
.stateStyles({
normal: {
.backgroundColor(this.normalColor)
},
fo... |
application-dev\ui\state-management\arkts-style.md | // Global (outside a component declaration)
@Styles function functionName() { ... }
// Inside a component declaration
@Component
struct FancyUse {
@Styles fancy() {
.height(100)
}
} |
application-dev\ui\state-management\arkts-style.md | // index.ets
import { MyButtonModifier } from './setAttribute'
@Entry
@Component
struct AttributeDemo {
@State modifier: MyButtonModifier = new MyButtonModifier();
build() {
Row() {
Column() {
Button("Button")
.attributeModifier(this.modifier)
.onClick((... |
application-dev\ui\state-management\arkts-style.md | // setAttribute.ets
export class MyButtonModifier implements AttributeModifier<ButtonAttribute> {
isDark: boolean = false;
applyNormalAttribute(instance: ButtonAttribute): void {
if (this.isDark) {
instance.backgroundColor(Color.Black)
} else {
instance.backgroundColor(Color.Red)
... |
application-dev\ui\state-management\arkts-style.md | @Entry
@Component
struct FancyUse {
@State heightValue: number = 100;
@Styles fancy() {
.height(this.heightValue)
.backgroundColor(Color.Yellow)
.onClick(() => {
this.heightValue = 200;
})
}
} |
application-dev\ui\state-management\arkts-style.md | // Incorrect format.
@Styles function globalFancy (value: number) {
.width(value)
}
// Correct format.
@Styles function globalFancy () {
.width(value)
} |
application-dev\ui\state-management\arkts-style.md | // Incorrect format.
@Styles function backgroundColorStyle() {
if (true) {
.backgroundColor(Color.Red)
}
}
// Correct format.
@Styles function backgroundColorStyle() {
.backgroundColor(Color.Red)
} |
application-dev\ui\state-management\arkts-style.md | // Define a \@Styles decorated method outside a component declaration.
@Styles function globalFancy () {
.width(150)
.height(100)
.backgroundColor(Color.Pink)
}
@Entry
@Component
struct FancyUse {
@State heightValue: number = 100;
// Define a \@Styles decorated method inside a component declaration.
@Styl... |
application-dev\ui\state-management\arkts-track.md | class LogTrack {
@Track str1: string;
@Track str2: string;
constructor(str1: string) {
this.str1 = str1;
this.str2 = 'World';
}
}
class LogNotTrack {
str1: string;
str2: string;
constructor(str1: string) {
this.str1 = str1;
this.str2 = 'World';
}
}
@Entry
@Component
struct AddLog {
... |
application-dev\ui\state-management\arkts-track.md | Text 1 is rendered |
application-dev\ui\state-management\arkts-track.md | Text 3 is rendered
Text 4 is rendered |
application-dev\ui\state-management\arkts-track.md | class Log {
@Track logInfo: string;
owner: string;
id: number;
time: Date;
location: string;
reason: string;
constructor(logInfo: string) {
this.logInfo = logInfo;
this.owner = 'OH';
this.id = 0;
this.time = new Date();
this.location = 'CN';
this.reason = 'NULL';
}
}
@Entry
@Co... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.