maui icon indicating copy to clipboard operation
maui copied to clipboard

Bugfix for text not properly aligned with radioButton when in RTL for Android

Open dustin-wojciechowski opened this issue 1 year ago • 1 comments

Description of Change

Creating this as a draft first for some initial opinions, and still need to write some tests. Trying to describe using my developing understanding of the codebase, so let me know if I'm wrong about something!

Short summary is this fixes an issue where, when using the native radiobutton for android, and you set flow direction to RTL, The ellipse will be right aligned correctly, but the text (ex English) will be aligned in LTR fashion. When you create a RadioButton with RTL text (like Hebrew), the text will be aligned correctly.

LTR RTL
image image
LTR RTL
<> image

So the issue is textview content in the AppCompatRadioButton is not displaying text in correct alignment according to the flow direction set by developer in XAML. From what I understand, flow direction has been deferred to platforms, and I did notice that calling UpdateFlowDirection() on a TextView, that when ATextDirection.Inherit is assigned, it automatically becomes LTR. see here so this simply checks the Window's current page's flow direction and concatenates the unicode character for RTL with the presented text. It also addresses Window not returning the correct flow direction (came upon this problem when getting different results based on whether I used the Controls Sample app and the Sandbox app)

It feels kind of hackey to me, but I was having a bit of trouble getting text direction to take without direct access to EffectiveFlowDirection, which was showing the accurate flow direction, and the flow direction which was set to MatchParent, or in the Android View, Inherit, which would automatically set to LTR.

In my first attempt, I tried implementing a way for flow direction to propagate to child views similar to how this PR did for iOS, but Android doesn't seem to have something like a SemanticContentAttribute so there didn't seem to be a way to access that information.

Please let me know if I missed something or if there's a better way to do this.

BTW this issue doesn't occur for RadioButtons defined by a Control template, as those use labels for text content and we have a mapper for setting the text direction.

Issues Fixed

Fixes #6708

dustin-wojciechowski avatar Feb 28 '23 22:02 dustin-wojciechowski

Thank you for your pull request. We are auto-formating your source code to follow our code guidelines.

github-actions[bot] avatar Feb 28 '23 23:02 github-actions[bot]

@dustin-wojciechowski just double-checking... Does this also fix: https://github.com/dotnet/maui/issues/6939 ?

jfversluis avatar Mar 09 '23 08:03 jfversluis

@dustin-wojciechowski just double-checking... Does this also fix: #6939 ?

I was a little confused by the repros using LTR text in both of these issues, but yeah this would complete the earlier fix that went in that fixed the text disappearing.

dustin-wojciechowski avatar Mar 09 '23 17:03 dustin-wojciechowski