Implement VerticalTextAlignment on text-input handlers#275
Open
jonathanpeppers wants to merge 1 commit into
Open
Implement VerticalTextAlignment on text-input handlers#275jonathanpeppers wants to merge 1 commit into
jonathanpeppers wants to merge 1 commit into
Conversation
Wires VerticalTextAlignment on LabelHandler, EntryHandler, EditorHandler, SearchBarHandler, and PickerHandler — bringing each from 98% to 100% in docs/maui-coverage.md. Approach: add a Modifier.WrapContentHeight(Alignment.Vertical, bool) overload (new sibling JNI bridge ModifierWrapContentHeightAligned reusing ModifierWrapContentHeightDefault) so each handler can map TextAlignment to the corresponding Alignment.Vertical and chain it onto the outer modifier. A shared helper in Platform/VerticalAlignmentMapping.cs converts MAUI''s TextAlignment (Start/Center/End/Justify; Justify collapses to Top) into the Compose alignment + applies the modifier in one call. Adds a VerticalAlignmentPage demo to the MAUI sample exercising VerticalTextAlignment on each of the five controls inside fixed-height frames so the visual diff is obvious. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR wires VerticalTextAlignment support onto the five Compose-backed MAUI text-input handlers (LabelHandler, EntryHandler, EditorHandler, SearchBarHandler, PickerHandler), moving each from 98% to 100% property-mapper coverage. The approach uses Compose's Modifier.wrapContentHeight(Alignment.Vertical) to position text content within a parent slot, which is the correct semantic match for MAUI's VerticalTextAlignment property.
Changes:
- Adds a new
ComposeBridges.ModifierWrapContentHeightAlignedJNI bridge and correspondingModifier.WrapContentHeight(Alignment.Vertical, bool)public API (static factory + extension), reusing the existingModifierWrapContentHeightDefaultenum. - Introduces
VerticalAlignmentMapping(internal helper in the MAUI project) to convertMicrosoft.Maui.TextAlignment→Alignment.Verticaland chain the modifier, then wires_vTextAlignMutableState<int>+MapVerticalTextAlignment+ApplyVerticalTextAlignmentonto all five handlers with consistent patterns. - Adds a
VerticalAlignmentPageXAML sample exercising all five controls with Start/Center/End inside fixed-height frames, and updatesdocs/maui-coverage.mdto reflect the new 100% coverage.
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
src/Microsoft.AndroidX.Compose/ComposeBridges.cs |
New ModifierWrapContentHeightAligned bridge with explicit IAlignmentVertical? param |
src/Microsoft.AndroidX.Compose/ModifierExtensions.cs |
New WrapContentHeight(Alignment.Vertical, bool) extension method with null check |
src/Microsoft.AndroidX.Compose/Modifier.cs |
Static factory overload delegating to the extension; fixes inheritdoc cref for disambiguation |
src/Microsoft.AndroidX.Compose/PublicAPI.Unshipped.txt |
Two new entries for the public overload (static + extension) |
src/Microsoft.AndroidX.Compose.Maui/Platform/VerticalAlignmentMapping.cs |
New internal mapping helper: TextAlignment → Alignment.Vertical + modifier extension |
src/Microsoft.AndroidX.Compose.Maui/Handlers/LabelHandler.cs |
Adds _vTextAlign slot, mapper, and modifier chaining; removes TODO comment |
src/Microsoft.AndroidX.Compose.Maui/Handlers/EntryHandler.cs |
Same wiring pattern as LabelHandler (default Center) |
src/Microsoft.AndroidX.Compose.Maui/Handlers/EditorHandler.cs |
Same wiring pattern (default Start for multi-line) |
src/Microsoft.AndroidX.Compose.Maui/Handlers/SearchBarHandler.cs |
Same wiring pattern (default Center) |
src/Microsoft.AndroidX.Compose.Maui/Handlers/PickerHandler.cs |
Same wiring pattern (default Center) |
src/Microsoft.AndroidX.Compose.Maui.Sample/Pages/VerticalAlignmentPage.xaml |
XAML demo exercising Start/Center/End on all 5 controls in fixed-height frames |
src/Microsoft.AndroidX.Compose.Maui.Sample/Pages/VerticalAlignmentPage.xaml.cs |
Code-behind seeding Picker items |
src/Microsoft.AndroidX.Compose.Maui.Sample/HomePage.xaml.cs |
Demo registry entry |
src/Microsoft.AndroidX.Compose.Maui.Sample/AppShell.xaml.cs |
Route registration for vertical-align |
docs/maui-coverage.md |
Coverage numbers updated to reflect 100% on all 5 handlers |
| /// content within the parent's allocated height using | ||
| /// <paramref name="align"/> instead of Kotlin's default | ||
| /// <see cref="Alignment.Vertical.CenterVertically"/>. Useful for | ||
| /// mapping <see cref="Microsoft.Maui.ITextAlignment.VerticalTextAlignment"/> |
| /// <see cref="Alignment.Vertical"/> and the matching | ||
| /// <see cref="ModifierExtensions.WrapContentHeight(Modifier, Alignment.Vertical, bool)"/> | ||
| /// modifier. Used by every Compose-backed text-input handler so the | ||
| /// cross-platform property line up consistently regardless of which |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Wires
VerticalTextAlignmenton the five Compose-backed text-input handlers —LabelHandler,EntryHandler,EditorHandler,SearchBarHandler,PickerHandler— so each goes from 98% → 100% indocs/maui-coverage.md.Coverage delta
LabelHandlerEntryHandlerEditorHandlerSearchBarHandlerPickerHandlerApproach
Compose's
Modifier.wrapContentHeight(align)measures the child without imposing the parent's min height, then aligns the child within the parent's allocated height. That's exactly the semantic MAUI'sVerticalTextAlignmentcarries — visible only when the control has more height than it naturally needs.ComposeBridges.ModifierWrapContentHeightAligned(IntPtr, IAlignmentVertical?, bool). Reuses the existingModifierWrapContentHeightDefaultenum (slot 0 =align, slot 1 =unbounded) so the auto-default-mask clears bit 0 only when the C# caller passes a non-null alignment. The pre-existingModifierWrapContentHeight(IntPtr, bool)overload is untouched (still defaults to Kotlin'sCenterVertically).Modifier.WrapContentHeight(Alignment.Vertical, bool)static factory + extension method. Public-API entries added toPublicAPI.Unshipped.txt.Microsoft.AndroidX.Compose.Maui.Platform.VerticalAlignmentMappingconvertsMicrosoft.Maui.TextAlignment→Alignment.Vertical(Start→Top, Center→CenterVertically, End→Bottom, Justify→Top — Compose has no vertical-justify analog, matching the stock Android backend)._vTextAlignMutableState<int>slot, aMapVerticalTextAlignmentmapper entry, and.ApplyVerticalTextAlignment(vAlign)chained onto its outer modifier (afterApplySemantics). The five// TODO: VerticalTextAlignment …comments are deleted.Sample
Adds
VerticalAlignmentPagetoMicrosoft.AndroidX.Compose.Maui.Sample— one page exercisingVerticalTextAlignment="Start|Center|End"on each of the five controls inside fixed-height frames so the difference is obvious. Wired intoHomePage+AppShellunder routevertical-align.Verification
dotnet build src/Microsoft.AndroidX.Compose— 0 errors, no new warnings.dotnet build src/Microsoft.AndroidX.Compose.Maui— 0 errors, 0 warnings.dotnet build src/Microsoft.AndroidX.Compose.Maui.Sample— 0 errors, 0 warnings.dotnet run scripts/maui-coverage.cs— regenerateddocs/maui-coverage.md; all five handlers ✅ 100%.