Status Update
Comments
ha...@google.com <ha...@google.com>
ja...@squareup.com <ja...@squareup.com> #2
Thanks for reporting this!
The intention here was for parentWidth
to be hidden and it will be fixed soon. I see the potential convenience of exposing parentWidth
and parentHeight
, but in general it leads to a not very clean data flow: it would mean that after telling the layout system my size I receive the size back although my initial calculation is still in scope. I am afraid this would bring more confusion than convenience longer term.
Just as a background, the reason we have parentWidth
and not parentHeight
is that it is needed to calculate horizontally mirrored positioning of children for layout direction RTL when placeRelative
is used.
ha...@google.com <ha...@google.com> #3
Branch: androidx-master-dev
commit 36b705d1dd148fc57e8089a94d485e0bfcd05d0f
Author: Mihai Popa <popam@google.com>
Date: Mon Sep 14 11:59:30 2020
Hide parentWidth and parentLD in PlacementScope
When writing a custom layout, parentWidth and parentLayoutDirection
should not be read from the placement block as they are available or
calculated in the measure block. This CL is making them protected in
PlacementScope. The CL also merges the PlacementScope implementations
used for modifiers and layout nodes, which is now possible after the
modules' merging.
Relnote: PlacementScope#parentWidth and PlacementScope#parentLayoutDirection can no longer be read from the placement block of a custom layout.
Fixes: 168295623
Test: tests in foundation-layout
Change-Id: Icc1ae00d774147c5fa7006c4bb408c99c7731690
M compose/ui/ui/api/current.txt
M compose/ui/ui/api/public_plus_experimental_current.txt
M compose/ui/ui/api/restricted_current.txt
M compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/MeasureScope.kt
M compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/Placeable.kt
M compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/node/DelegatingLayoutNodeWrapper.kt
M compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/node/LayoutNode.kt
M compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/node/OuterMeasurablePlaceable.kt
ap...@google.com <ap...@google.com> #4
I actually found a reason for exposing both parentWidth
and parentHeight
in PlacementScope
and that is modifiers. I wanted to write a modifier that places a composable using a percent which requires access to the parent's size. This currently does not seem possible using modifiers.
Description
It is currently difficult to draw custom spans for
Text()
becauseTextLayoutResult
does not expose any APIs for accurately reading line bounds. Considering thatAndroidParagraph
already has APIs such asgetLineAscent()
,getLineBaseline()
andgetLineDescent()
, can they be bubbled up toTextLayoutResult
?Having access to
getTopPadding()
andgetBottomPadding()
fromandroid.text.Layout
would also be helpful.AFAIK, there is currently no workaround for reading these values. Inspecting font metrics would have been one option, but that is not available either ( https://issuetracker.google.com/issues/173648606 ).