Skip to content

fix(harmonyos): style text fields through TextInput's own attributes - #884

Merged
houko merged 3 commits into
mainfrom
fix/harmony-text-rendering-811
Nov 19, 2026
Merged

houko merged 3 commits into
mainfrom
fix/harmony-text-rendering-811

Conversation

@houko

@houko houko commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator

Part of #811

Summary

  • Text fields (the AI Chat composer, the Combobox): ArkUI's TextInput keeps its theme's grey capsule, padding and default font unless its own attributes set them, and the common attributes the renderer writes for every view (style()) never reach its background, corners or border. The host now writes the engine's background, corners and border through the TextInput's attributes too, transparent where the engine gives none, pads the field to the content box the engine laid out (InputConfig.Content, now sent with the in op, as Android and the web place their editors there), and gives the placeholder the field's font and, when the app sets one, its color (an unset PlaceholderColor keeps the platform's, as Android does). ArkUI centers a single line in that box, so only a multi-line field keeps an explicit lineHeight.
  • Inline views in text: the U+FFFC attachment characters are left out of the text drawn and measured, so no box shows. The views themselves are still not drawn: the HarmonyOS text engine has no attachment layout (core.AttachmentLayout), so the engine hides them. That needs the text laid out with placeholders on the host and reported back synchronously, which is its own piece of work, so the roadmap records it under HarmonyOS preview: text rendering differences in the gallery #811 and the issue stays open.

Why the first review saw no change for the text fields

nsgo test -target harmonyos without hvigorw and OHOS_BASE_SDK_HOME packages the committed host in cmd/nsgo/harmony/host/, not the templates, and that host predates the last seven template commits, so the Index.ets changes never ran. Filed as #907. The screenshots below were taken with a host compiled from this branch's templates on the Mac Studio's DevEco SDK (test-only build, not committed); the committed host is left as it is, for #907.

Screenshots

HarmonyOS 6.0.2 phone emulator, gallery pages; before is main, after is this branch.

Text page, inline views:

before after
text before text after

Select page, Combobox:

before after
select before select after

Conversation page, composer:

before after
composer before composer after

Verification

  • go tool nsgo test ./cmd/nsgo/harmony (ops and host checks), go tool nsgo test -target web ./internal/platform/harmonyos (TestTextDrawsNoAttachmentRunes), go tool nsgo check -target harmonyos.
  • Index.ets compiled with hvigor; the emulator run above used that host.

@github-actions github-actions Bot added bug Something isn't working documentation Improvements or additions to documentation cli size/S conflict Conflicts with the base branch; resolve it first labels Nov 19, 2026
@houko
houko force-pushed the fix/harmony-text-rendering-811 branch from f48bf5e to 55452fd Compare November 19, 2026 16:34
@github-actions github-actions Bot removed the conflict Conflicts with the base branch; resolve it first label Nov 19, 2026
@houko

houko commented Nov 19, 2026

Copy link
Copy Markdown
Collaborator Author

Not merging yet: checked on the HarmonyOS 6.0.2 phone emulator (3.5 pixels a point), the PR fixes only the first of #811's three points.

Pushed on top: an unset PlaceholderColor (0) was sent as rgba(0,0,0,0), a transparent placeholder; it is now sent as none and the host keeps ArkUI's color, as Android does (setHintTextColor only when non-zero). Also added (#811 by @houko) to the CHANGELOG bullet and a browser-run test (TestTextDrawsNoAttachmentRunes) for the stripped rune.

What the emulator shows:

  1. Text page: the U+FFFC boxes are gone. The inline views themselves (logo, status badge, button) are not drawn, before or after, so the line keeps an empty gap where each was; the doc sentence "their views are mounted separately at the engine's attachment frames" overstates it. Either draw them or record the gap in the roadmap.
before after
text before text after
  1. Select page: the Combobox placeholder is unchanged, still larger and darker than the Select's, on a grey pill. placeholderFont/placeholderColor do not reach it, so it is probably not the TextInput placeholder path at all (worth checking what the combobox mounts there).
before after
select before select after
  1. AI Chat (Conversation) composer after the change: the placeholder "输入消息。" sits on a grey pill, in a larger font than the field's, and the caret is drawn over its first glyph at the left edge. (The before capture timed out: "the page did not answer the snapshot".)

conversation after

So the acceptance ("match Android for the three points") is not met for points 2 and 3. These need iteration on the emulator, and comparison with Android, before merging.

@github-actions github-actions Bot added the conflict Conflicts with the base branch; resolve it first label Nov 19, 2026
@houko
houko force-pushed the fix/harmony-text-rendering-811 branch from 55452fd to 9c6e180 Compare November 19, 2026 22:45
@github-actions github-actions Bot removed the conflict Conflicts with the base branch; resolve it first label Nov 19, 2026
@houko houko changed the title fix(harmonyos): match text field rendering fix(harmonyos): style text fields through TextInput's own attributes Nov 19, 2026
An unset PlaceholderColor is 0, which the host was sent as transparent and drew no placeholder at all; send none, as the other targets keep the platform's, and test that the drawn text leaves out attachment runes.
The composer's and the Combobox's grey capsule, larger placeholder and unpadded text had one cause: ArkUI's TextInput keeps its theme's background, corners, border and padding unless its own attributes set them, and the common attributes style() writes never reach them. The host now writes the engine's background, corners and border through the TextInput's attributes too, transparent where the engine gives none, and pads the field to the content box the engine laid out (InputConfig.Content, now sent with the "in" op), as Android and the web place their editors. A single line is centered by ArkUI in that box, so only a multi-line field keeps an explicit lineHeight.

The text engine also measures the text it draws, without attachment runes, so a measured line is the line ArkUI draws. Inline views themselves are still not drawn on HarmonyOS: the engine has no attachment layout there yet, which the roadmap now records under #811, and the architecture document no longer says their views are mounted.

Checked on the HarmonyOS 6.0.2 phone emulator with a host compiled from these templates: the Select page's Combobox matches the Select's field, and the Conversation composer shows its placeholder at 13.5 pt in its faint color, inset by its padding, with no capsule.
@houko
houko force-pushed the fix/harmony-text-rendering-811 branch from 9c6e180 to 947176a Compare November 19, 2026 23:29
@houko

houko commented Nov 19, 2026

Copy link
Copy Markdown
Collaborator Author

Reviewed.

@houko
houko merged commit ddfaeec into main Nov 19, 2026
20 checks passed
@houko
houko deleted the fix/harmony-text-rendering-811 branch November 19, 2026 23:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working cli documentation Improvements or additions to documentation size/S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant