HarmonyOS State Management with ArkTS: Component and Application-Level Patterns

@State Decorator The @State decorator is used to declare a state variable in a component. When the state variable changes, the component automatically re-renders. Assigning Values to Class Properties In HarmonyOS with ArkTS, you can assign values to class properties within components. Here's an example: @Component struct MyComponent { @State ...

Posted on Thu, 03 Sep 2026 16:28:07 +0000 by benyboi

HarmonyOS NEXT Promise Await Exception Handling Without Cluttered Try-Catch Blocks

Async/await operasions throw errors when the underlying Promise rejects, halting eexcution of subsequent code. For example: async function simulateRequest() { console.log('Request initiated'); const response = await new Promise<string>((resolve, reject) => { setTimeout(() => reject('Data fetch timeout'), 1200); }); conso ...

Posted on Mon, 31 Aug 2026 16:30:53 +0000 by hkothari

Calling ArkTS Functions from Non-ArkTS Threads in HarmonyOS

Module Registration First, we need to register the native module. This is done in the queue_work.cpp file: // queue_work.cpp EXTERN_C_START static napi_value Init(napi_env env, napi_value exports) { napi_property_descriptor desc[] = { { "queueWork", nullptr, QueueWork, nullptr, nullptr, nullptr, napi_default, nullptr } ...

Posted on Fri, 21 Aug 2026 16:48:40 +0000 by Tonsil

HarmonyOS N-API Module Loading in Main Thread

Module Loading Overview The Node-API napi_load_module intreface enables module loading in the main thread. After loading, developers can retrieve exported properties using napi_get_property or access functions via napi_get_named_property. Supported scenarios include: Loading system modules (e.g., @ohos.hilog) Loading modules from ArkTS files ...

Posted on Fri, 31 Jul 2026 16:08:29 +0000 by himnbandit

Working with XML in HarmonyOS ArkTS: Structure Definition and Processing

An XML element consists of three main parts: Tag: Marks the begining and end of an element Attributes: Provide additional information about the element Content: The data contained within the element Element Structure Example <book category="fiction"> <title>XML Fundamentals</title> <author>Jane Smith</ ...

Posted on Fri, 24 Jul 2026 16:39:15 +0000 by bagsobrands

AOP in the HarmonyOS Architecture

Introduction to AOP For developers familiar with Android or Java Web development, the concept of Aspect-Oriented Programming (AOP) is well-established. The core of AOP lies in identifying an aspect and then performing pre-processing or post-processing on a specific business operation, or even replacing the operation entirely. The granularity of ...

Posted on Thu, 16 Jul 2026 16:26:55 +0000 by gtibok

Implementing Persistent Worker Threads in HarmonyOS

In HarmonyOS, while TaskPool is ideal for short-lived, independent tasks, scenarios requiring long-lived state or persistent object handles often necessitate the use of Worker threads. Unlike TaskPool, which manages task lifecycles automatically, Worker allows for maintaining a single, consistent execution context. Creating and Managing a Worke ...

Posted on Mon, 13 Jul 2026 16:51:23 +0000 by Merdok

Building Grid Layouts in HarmonyOS with Grid and GridItem

To create responsive grid layouts in HarmonyOS, developers use the Grid container along with GridItem children. This approach supports flexible sizing, spacing, direction control, and even pagination. Defining Rows and Columns with Templates The structure of a grid is defined using rowsTemplate and columnsTemplate, which accept CSS-like fractio ...

Posted on Wed, 01 Jul 2026 17:59:05 +0000 by aka_bigred

Managing Application Context in HarmonyOS Stage Model

Overview of Context TypesIn the HarmonyOS Stage model, Context provides access to application resources, paths, and configurations. Several specialized context classes inherit from the base Context class, including ApplicationContext, AbilityStageContext, UIAbilityContext, and ExtensionContext. These subclasses provide specific capabilities whi ...

Posted on Thu, 25 Jun 2026 17:40:44 +0000 by thewomb

Implementing Tab Navigation in HarmonyOS Applications

Bottom Navigation Bar @Entry @Component struct MainScreen { build() { Column() { Tabs({ barPosition: BarPosition.End }) { TabContent() { Text('Home Screen').fontSize(30) }.tabBar('Home') TabContent() { Text('Discovery Screen').fontSize(30) }.tabBar('Discovery') TabContent ...

Posted on Tue, 23 Jun 2026 17:09:58 +0000 by rich1983