Skip to content

feat(iOS): custom style - #641

Open
kacperzolkiewski wants to merge 13 commits into
@kacperzolkiewski/custom-stylefrom
@kacperzolkiewski/feat-custom-style
Open

feat(iOS): custom style#641
kacperzolkiewski wants to merge 13 commits into
@kacperzolkiewski/custom-stylefrom
@kacperzolkiewski/feat-custom-style

Conversation

@kacperzolkiewski

@kacperzolkiewski kacperzolkiewski commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator

Summary

Add custom style for foreground and background colors handling

Test Plan

Run the example app and experiment with applying foreground and background colors through the toolbar across different text styles.

Screenshots / Videos

Screen.Recording.2026-06-17.at.13.38.30.mov

Compatibility

OS Implemented
iOS
Android

Checklist

  • E2E tests are passing
  • Required E2E tests have been added (if applicable)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an iOS-only “custom style” layer to support per-range foreground/background colors, including native commands/state events and HTML span parsing/serialization.

Changes:

  • Exposes a new setStyle imperative command and emits customStyle in state/context-menu events.
  • Implements iOS CustomStyle/CustomStyleData to apply per-range colors and integrates it into style application priority.
  • Parses <span style="color: ...; background-color: ..."> into native style data and serializes custom styles back to HTML.

Reviewed changes

Copilot reviewed 23 out of 23 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
src/web/useOnChangeState.ts Adds default customStyle fields to the web state shape.
src/web/EnrichedTextInput.tsx Adds a setStyle no-op to the web imperative handle.
src/types.ts Extends public TS types with customStyle and setStyle(...).
src/spec/EnrichedTextInputNativeComponent.ts Adds customStyle to events and introduces the setStyle native command in the codegen spec.
src/native/EnrichedTextInput.tsx Implements setStyle command payload creation (processColor + JSON).
ios/utils/StyleUtils.mm Registers CustomStyle in conflict/blocking maps and style registries.
ios/textHtmlParser/TextHtmlParser.mm Applies CustomStyle when processing styles from HTML (viewer path).
ios/styles/EnrichedTextStyles.mm Adds EnrichedTextCustomStyle implementation hook.
ios/styles/CustomStyle.mm New iOS style implementation applying fg/bg colors via attributed text.
ios/interfaces/StyleTypeEnum.h Adds Custom style type.
ios/interfaces/StyleHeaders.h Declares CustomStyle interface in shared style headers.
ios/interfaces/StyleBase.mm Introduces stylePriority default implementation.
ios/interfaces/StyleBase.h Exposes stylePriority on the base style protocol.
ios/interfaces/EnrichedTextStyleHeaders.h Adds EnrichedTextCustomStyle header.
ios/inputHtmlParser/InputHtmlParser.mm Applies CustomStyle when processing styles from HTML (input path).
ios/inputAttributesManager/InputAttributesManager.mm Changes style application ordering to use stylePriority.
ios/htmlParser/HtmlParser.mm Parses/serializes custom styles as <span style="..."> and splits spans when data changes.
ios/extensions/ColorExtension.mm Adds rgba string conversion + rgba parsing helpers.
ios/extensions/ColorExtension.h Declares rgba helpers in the UIColor category.
ios/EnrichedTextInputView.mm Implements setStyle command handling and emits customStyle in events.
ios/customStyleData/CustomStyleData.mm New data object storing fg/bg UIColors with merge/equality/copy.
ios/customStyleData/CustomStyleData.h Declares CustomStyleData API.
apps/example/src/constants/editorConfig.ts Extends example default editor state with customStyle.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread ios/htmlParser/HtmlParser.mm Outdated
Comment thread ios/EnrichedTextInputView.mm Outdated
Comment thread ios/extensions/ColorExtension.mm Outdated
Comment thread ios/extensions/ColorExtension.mm Outdated
Comment thread src/spec/EnrichedTextInputNativeComponent.ts
Comment thread src/native/EnrichedTextInput.tsx Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 24 out of 24 changed files in this pull request and generated 2 comments.

Comment thread src/web/useOnChangeState.ts
Comment thread src/web/EnrichedTextInput.tsx

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 28 out of 31 changed files in this pull request and generated 6 comments.

Comment thread ios/htmlParser/HtmlParser.mm Outdated
Comment thread src/native/EnrichedTextInput.tsx Outdated
Comment thread src/native/EnrichedTextInput.tsx Outdated
Comment thread ios/extensions/ColorExtension.mm
Comment thread src/web/EnrichedTextInput.tsx
@kacperzolkiewski
kacperzolkiewski marked this pull request as ready for review June 17, 2026 11:39
@kacperzolkiewski
kacperzolkiewski changed the base branch from main to @kacperzolkiewski/custom-style June 17, 2026 11:53
@kacperzolkiewski kacperzolkiewski changed the title feat(iOS): add custom style feat(iOS): custom style Jun 24, 2026
@hejsztynx

Copy link
Copy Markdown
Collaborator

Currently you can't see the selection when background color is set

Screen.Recording.2026-07-29.at.10.39.38.mov

The background and foreground colors are dimmed up in a codeblock, it doesn't happen on other platforms

image

Probably not in this PR's scope, but when text alignment is set and the text wraps, the background color fills up the whole line. This also applies to mentions.

Screen.Recording.2026-07-29.at.10.42.28.mov

@kacperzolkiewski

kacperzolkiewski commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator Author

@hejsztynx,

  1. I applied the same behavior we use for other editor colors (e.g. inside code blocks): if the user doesn't provide an opacity value, one is added automatically.
  2. I would leave it like this in first iteration. Android behaves similar to iOS:
image

The problem is not straightforward to resolve. On iOS, custom style backgrounds are applied via NSBackgroundColorAttributeName on the text storage, while code block backgrounds are drawn manually as UIBezierPath filled rects in LayoutManagerExtension one per line, stretched to the full container width. These two layers are completely independent, so making them work together would require splitting the code block rects around the custom-colored ranges.

  1. Yes there is a bug but it should be fix in separate PR the same issue occur with inline code:
image

@hejsztynx hejsztynx left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Functionally looks great!

Comment thread ios/styles/CustomStyle.mm
Comment on lines +59 to +64
attrs[NSForegroundColorAttributeName] =
[data.foregroundColor colorWithResolvedAlpha];
attrs[NSUnderlineColorAttributeName] =
[data.foregroundColor colorWithResolvedAlpha];
attrs[NSStrikethroughColorAttributeName] =
[data.foregroundColor colorWithResolvedAlpha];

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would not change the opacity of the foregroundColor, we don't do that with the inline code style. It doesn't interfere with the selection visibility.

Suggested change
attrs[NSForegroundColorAttributeName] =
[data.foregroundColor colorWithResolvedAlpha];
attrs[NSUnderlineColorAttributeName] =
[data.foregroundColor colorWithResolvedAlpha];
attrs[NSStrikethroughColorAttributeName] =
[data.foregroundColor colorWithResolvedAlpha];
attrs[NSForegroundColorAttributeName] =
data.foregroundColor;
attrs[NSUnderlineColorAttributeName] =
data.foregroundColor;
attrs[NSStrikethroughColorAttributeName] =
data.foregroundColor;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants