harmony-arkts
БесплатноБез исполняемых скриптовНе проверенBest practices for HarmonyOS application development with ArkTS and ArkUI, covering components, state management, resources, layout, lifecycle, and…
от Mindrally★ 323 звезды на GitHubОб этом скилле
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, c
Установить harmony-arkts в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл harmony-arkts?
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.
Как установить скилл harmony-arkts?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл harmony-arkts запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
doc-coauthoring
Guide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision…
от Anthropicacademy-guide
Stop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials…
от Anthropicinternal-comms
A set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill…
от Anthropicskill-development
This skill should be used when the user wants to "create a skill", "add a skill to plugin", "write a new skill", "improve skill description", "organize skill…
от Anthropic