harmony-arkts
Skill266 starsChanged 10 months agoApache-2.0View on GitHub
Best practices for HarmonyOS application development with ArkTS and ArkUI, covering components, state management, resources, layout, lifecycle, and accessibility. Use when writing .ets component files, using ArkUI decorators like @Component/@State/@Prop/@Link, building layouts with Column/Row/Stack/List, managing HarmonyOS app resources with $r(), or handling component lifecycle and accessibility on HarmonyOS.
In this repository264 other files it gives its agents.
- accessibility-a11ySkill
- alpine-jsSkill
- analytics-data-analysisSkill
- android-developmentSkill
- angular-developmentSkill
- angularSkill
- anime-jsSkill
- anthropic-claude-developmentSkill
- api-developmentSkill
- apollo-graphqlSkill
- aspnet-coreSkill
- astroSkill
- auth0-authenticationSkill
- autogen-developmentSkill
- automl-hyperparameter-optimizationSkill
- aws-developmentSkill
- azureSkill
- backend-developmentSkill
- bash-scriptingSkill
- beautifulsoup-parsingSkill
- bitbucket-workflowSkill
- blazorSkill
- blender-python-addonSkill
- blockchainSkill
- bootstrapSkill
- business-central-developmentSkill
- cheerio-parsingSkill
- chrome-extension-developmentSkill
- ci-cd-best-practicesSkill
- clean-architectureSkill
- clean-codeSkill
- clerk-authenticationSkill
- cloudflare-developmentSkill
- computer-vision-opencvSkill
- convexSkill
- cppSkill
- c-sharpSkill
- cssSkill
- cypressSkill
- data-analysis-jupyterSkill
- data-analystSkill
- data-jupyter-pythonSkill
- deep-learning-pythonSkill
- deep-learning-pytorchSkill
- deep-learningSkill
- deno-typescriptSkill
- design-systemsSkill
- devopsSkill
- django-pythonSkill
- django-rest-api-developmentSkill
- dockerSkill
- dotnetSkill
- drizzle-ormSkill
- drupal-developmentSkill
- elasticsearch-best-practicesSkill
- electron-developmentSkill
- elixirSkill
- embedded-stm32Skill
- esbuild-bundlerSkill
- ethereumSkill
- The first 60 shown.
The file
Show its rules and text
We split this skill into the rules it gives an agent
19 rules. About 0 are common, 2 are distinctive, and 17 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
17
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 23
Use @Component to define components and PascalCase for the component struct name (e.g., struct UserProfileCard).
- Very specific: line 24
Keep state declarations (@State, @Prop, @Link, @StorageLink, plain fields) near the top of the component, before methods and lifecycle …
- Very specific: line 26
Place build() last and keep it focused purely on UI composition — pull data transformation and business logic out into methods called from …
- Very specific: line 31
Use @State for state owned and mutated by the component itself.
- Very specific: line 32
Use @Prop for one-way parent-to-child data — the child gets its own copy and local changes don't propagate back up.
- Very specific: line 33
Use @Link only for intentional two-way binding where the child genuinely needs to mutate the parent's state (e.g., a custom form control).
- Very specific: line 34
Keep derived values in computed helper methods rather than duplicating and manually syncing state (don't store both items and itemCount as …
- Very specific: line 35
Avoid broad global state (AppStorage/LocalStorage used indiscriminately) unless the project has an established app-state pattern.
- Very specific: line 91
Use Column, Row, Stack, List, and other ArkUI layout primitives intentionally based on the axis and stacking behavior actually needed, …
- Very specific: line 93
Use object notation for margin and padding when the sides differ (.margin({ top: 8, bottom: 16, left: 12, right: 12 })) rather than a …
- Very specific: line 94
Use logical pixels (vp) consistently for sizes so layouts scale correctly across device pixel densities.
- Very specific: line 95
Use percentage strings ('100%', '50%') for sizes that should be relative to the parent container instead of hardcoded fixed values.
- Very specific: line 96
Keep reusable spacing, colors, and typography values in the resource system ($r('app.color.primary'), $r('app.float.spacing_md')) when the …
- Very specific: line 100
Use arrow functions for event handlers (.onClick(() => this.handleTap()) or a bound class field like private handleTap = () => {...}) so …
- Distinctive: line 101
Keep event handlers themselves short — read the event, then delegate any non-trivial logic to a named method that can be tested and …
- Very specific: line 103
Use lifecycle hooks (aboutToAppear, aboutToDisappear, onPageShow, onPageHide, onBackPress) only for setup/teardown that genuinely depends …
- Very specific: line 107
Use $r() to reference app resources (strings, colors, media, floats) instead of embedding literal values directly in component code.
- Very specific: line 109
Add descriptive accessibility labels (.accessibilityText(), .accessibilityDescription()) and correct focus handling (.focusable(true), …
- Distinctive: line 111
Test on representative device sizes and orientations (phone, foldable, tablet, landscape/portrait) since ArkUI layouts that look correct on …
≈ “Common” is an estimate: at least 1 in 5 of the 213,895 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
HarmonyOS ArkTS Development
This skill covers building HarmonyOS applications with ArkTS and the declarative ArkUI framework, including component structure, state management, layout, lifecycle, resources, and accessibility.
Workflow for Building an ArkTS Component
- Define the component — Create a
structdecorated with@Component, named in PascalCase. - Declare state near the top — List
@State,@Prop,@Link, and other state decorators first, before any methods. - Add lifecycle hooks — Implement
aboutToAppear()/aboutToDisappear()(and others as needed) after state, beforebuild(). - Compose the UI in build() — Place
build()last, using ArkUI primitives (Column,Row,Stack,List, etc.) to lay out child components. - Extract complex UI — Once
build()grows large or nested, pull sections into smaller@Componentstructs or@Builderfunctions. - Wire events — Attach arrow-function event handlers that delegate non-trivial logic to named methods on the component.
- Externalize resources — Move strings, colors, dimensions, and images into the resource system and reference them with
$r(). - Verify accessibility and responsiveness — Add accessibility labels, check touch target sizes, and test across representative device sizes/orientations.
Component Structure
- Use
@Componentto define components and PascalCase for the component struct name (e.g.,struct UserProfileCard). - Keep state declarations (
@State,@Prop,@Link,@StorageLink, plain fields) near the top of the component, before methods and lifecycle hooks. - Group lifecycle hooks (
aboutToAppear,aboutToDisappear,onPageShow,onPageHide) beforebuild()so the component's lifecycle is easy to scan. - Place
build()last and keep it focused purely on UI composition — pull data transformation and business logic out into methods called frombuild(), not embedded inline. - Extract complex UI into smaller
@Componentstructs (or@Builderfunctions for lightweight, reusable UI fragments) once abuild()method grows past a screenful or nests more than a few levels deep.
State and Data Flow
- Use
@Statefor state owned and mutated by the component itself. - Use
@Propfor one-way parent-to-child data — the child gets its own copy and local changes don't propagate back up. - Use
@Linkonly for intentional two-way binding where the child genuinely needs to mutate the parent's state (e.g., a custom form control). - Keep derived values in computed helper methods rather than duplicating and manually syncing state (don't store both
itemsanditemCountas separate@Statefields whenitemCountcan bethis.items.length). - Avoid broad global state (
AppStorage/LocalStorageused indiscriminately) unless the project has an established app-state pattern; prefer passing data down through props/links for anything not genuinely global.
Example: A Component with State, Props, and Lifecycle
@Component
export struct CounterCard {
@Prop label: string = 'Counter';
@State private count: number = 0;
private maxCount: number = 99;
aboutToAppear(): void {
console.info(`CounterCard mounted with label=${this.label}`);
}
private increment = (): void => {
if (this.count >= this.maxCount) {
return;
}
this.count += 1;
};
private reset = (): void => {
this.count = 0;
};
build() {
Column({ space: 12 }) {
Text(this.label)
.fontSize(18)
.fontWeight(FontWeight.Medium)
Text(`${this.count}`)
.fontSize(32)
.fontColor($r('app.color.primary'))
.accessibilityText(`Current count is ${this.count}`)
Row({ space: 8 }) {
Button('Increment')
.onClick(this.increment)
.accessibilityText('Increment counter')
Button('Reset')
.onClick(this.reset)
.accessibilityText('Reset counter')
}
}
.width('100%')
.padding(16)
.alignItems(HorizontalAlign.Center)
}
}Layout and Styling
- Use
Column,Row,Stack,List, and other ArkUI layout primitives intentionally based on the axis and stacking behavior actually needed, rather than defaulting toStackand positioning everything absolutely. - Group layout properties — width, height, alignment, layout weight (
layoutWeight) — before visual properties (color, font, border) in the chained modifier calls, so structure reads before decoration. - Use object notation for margin and padding when the sides differ (
.margin({ top: 8, bottom: 16, left: 12, right: 12 })) rather than a single shorthand that implies uniform spacing. - Use logical pixels (
vp) consistently for sizes so layouts scale correctly across device pixel densities; avoid mixing raw pixel values. - Use percentage strings (
'100%','50%') for sizes that should be relative to the parent container instead of hardcoded fixed values. - Keep reusable spacing, colors, and typography values in the resource system (
$r('app.color.primary'),$r('app.float.spacing_md')) when the project supports it, instead of repeating literals across components.
Events and Lifecycle
- Use arrow functions for event handlers (
.onClick(() => this.handleTap())or a bound class field likeprivate handleTap = () => {...}) sothisbinds correctly without extra boilerplate. - Keep event handlers themselves short — read the event, then delegate any non-trivial logic to a named method that can be tested and reasoned about independently.
- Handle async failures explicitly (
try/catcharoundawait) and surface user-facing errors (a toast, an inline error state) instead of letting a rejected promise disappear silently. - Use lifecycle hooks (
aboutToAppear,aboutToDisappear,onPageShow,onPageHide,onBackPress) only for setup/teardown that genuinely depends on the component or page's lifecycle — don't use them as a dumping ground for logic that could live in a regular method.
Resources and Accessibility
- Use
$r()to reference app resources (strings, colors, media, floats) instead of embedding literal values directly in component code. - Group resource references consistently — organize
resources/base/element/string.json,color.json,float.jsonby feature or screen so they stay navigable as the app grows. - Add descriptive accessibility labels (
.accessibilityText(),.accessibilityDescription()) and correct focus handling (.focusable(true),.tabIndex()) for every interactive element. - Maintain sufficient color contrast between text and background, and keep touch targets at least the platform-recommended minimum size (generally 40vp or larger) for anything tappable.
- Test on representative device sizes and orientations (phone, foldable, tablet, landscape/portrait) since ArkUI layouts that look correct on one form factor can break on another.
Common Mistakes
- Burying business logic (data fetching, validation, complex branching) directly inside
build()instead of in dedicated methods —build()should read like a UI tree, not a program. - Using
@Linktwo-way binding when a simple one-way@Propwould do, which makes data flow harder to trace and invites accidental mutation from child components. - Hardcoding repeated strings, colors, and dimensions that belong in the resource system, making localization and theming changes require hunting through component code.
- Leaving debug
console.log/console.infocalls in production code paths, which adds noise and can leak internal state into logs.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

