Skip to content

feat: text-alignment-support-android#488

Open
Wmg20 wants to merge 14 commits intosoftware-mansion:mainfrom
Wmg20:@wmg20/text-alignment-support-android
Open

feat: text-alignment-support-android#488
Wmg20 wants to merge 14 commits intosoftware-mansion:mainfrom
Wmg20:@wmg20/text-alignment-support-android

Conversation

@Wmg20
Copy link

@Wmg20 Wmg20 commented Mar 17, 2026

Summary

This pull request introduces Text Alignment support for Android, bringing it to parity with the existing iOS implementation.

Motivation

Previously, the setTextAlignment method was only functional on iOS. This PR implements the necessary native Android logic to support alignment for paragraphs and lists.

Implementation Details

  • Core Alignment: Implemented using Android's AlignmentSpan.Standard.
  • Placeholder Management: Added EnrichedAlignmentPlaceholderSpan which uses a Zero Width Space (ZWS) to maintain alignment state in empty paragraphs. This ensures the alignment isn't lost when a user clears a line and prevents the native placeholder from being incorrectly hidden.
  • HTML Parser Updates: Updated EnrichedParser and HtmlToSpannedConverter to support the text-align CSS property during HTML import/export for both <p> and <li> tags.
  • List Support: Refactored EnrichedOrderedListSpan, EnrichedUnorderedListSpan, and EnrichedCheckboxListSpan to correctly position markers (bullets, numbers, checkboxes) according to the paragraph's alignment and text direction.
  • State Synchronization: Updated EnrichedSpanState to emit the current alignment back to the React Native side, allowing toolbar buttons to highlight correctly.

Impacted Areas

  • Android Native Source (android/src/main/java/com/swmansion/enriched/...)
  • Common HTML Parser
  • API Documentation

Test Plan

Verification Steps

  1. Basic Alignment:
    • Open the Example App on an Android device/emulator.
    • Select a block of text and toggle between Left, Center, and Right alignment using the toolbar.
    • Verify the text shifts correctly.
  2. Empty Paragraphs:
    • Create an empty line.
    • Change its alignment.
    • Verify that the cursor moves to the Correct position (e.g., center) and that the "Placeholder" text remains visible until you start typing.
  3. List Alignment:
    • Create a Bullet or Numbered list.
    • Apply "Center" or "Right" alignment.
    • Verify that the markers (bullets/numbers) stay aligned with the start of the text block.
  4. HTML Persistence:
    • Align some text and click "Request HTML" (if available in the example).
    • Re-import that HTML and verify the alignment is preserved.

Expected Results

  • All alignments (except justify, which falls back to default on Android) should render consistently with iOS.
  • No layout "flickering" when switching alignment on empty lines.

Screenshots / Videos

Screenshot_1773725294

Compatibility

OS Implemented
iOS
Android

@Wmg20 Wmg20 changed the title @wmg20/text alignment support android feat: text-alignment-support-android Mar 17, 2026
@Wmg20
Copy link
Author

Wmg20 commented Mar 17, 2026

Hi @kacperzolkiewski,

I've just submitted a PR to add Text Alignment support for Android, bringing it up to parity with the iOS implementation.

Key highlights:

  • Implemented setTextAlignment logic for paragraphs and list items.
  • Added a custom EnrichedAlignmentPlaceholderSpan to maintain alignment on empty lines without hiding the native placeholder.
  • Updated the HTML parser to support text-align during import/export.
  • Refined list marker positioning to correctly handle different alignments.

I've also updated the API_REFERENCE.md to reflect these changes. I'd appreciate it if you could take a look! Thanks!

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