Xamarin.forms: [F100] Allow overriding theme capitalization settings in Android

Created on 26 Jan 2018  Â·  19Comments  Â·  Source: xamarin/Xamarin.Forms

Rationale

Sometimes changing the theme on an android app can be a bit difficult. It may be useful for people to be able to override theme capitalization settings without modifying the theme or using an effect.

Implementation

button.On<Android>().SetAllCaps (true/false);

Expected Result

Android

When set to false, the button should not auto-cap letters. When set to true it should.

Should directly pass ABP value to Control.SetAllCaps (value);

iOS

No change

UWP

No change

Implications for CSS

Not relevant to CSS

Backward Compatibility

Third party renderers may need to be updated to ensure that this functionality is supported through the new official mechanism. Further we will need to be careful to code the changes to the renderers in a careful manner to ensure that if someone is already using an effect support this feature that the effect is as best as possible not broken by our changes.

Difficulty : Trivial

Yeah, straightforward and easy.

F100 community-sprint help wanted inactive Android proposal-accepted roadmap enhancement âž• up-for-grabs

All 19 comments

I can take this!

Moving to InProgress :)

As a matter of practice (and nothing personal) we will probably move this back to an unclaimed pool if we dont get just a ping or something that work is still going on every 2 weeks or so.

So SetAllCaps is a property of TextView (from which Button inherits) rather than Button. Should the platform-specific be added at the TextView level, or is this item only relevant to Button? Are there any other controls that inherit from TextView besides Button, Label, Switch, and Entry? That seems to be the complete list best I can tell based on this: https://developer.android.com/reference/android/widget/TextView.html

@jassmith can you let me know your thoughts on the above? Otherwise I'll just assume that for completion's sake it's best to apply this to all the TextView controls I mentioned.

Yes, sorry for the delay. I was in boston all last week. Still catching up.

It would be ideal to add this to each of those controls yes. Unfortunately as its a platform specific and we wouldn't want to add this to each base class you will likely need to do a fair amount of copy/paste work here.

no problem at all, hope you enjoyed Boston.
I don't have a problem with some extra copy/paste if it produces something considered more ideal 😄 . Thanks.

I'm not setting SetAllCaps for this issue
https://github.com/xamarin/Xamarin.Forms/issues/1683

But just wanted to reference other Caps efforts happening right now

@jassmith hit a bit of snag here -- since Android doesn't provide a getter for IsAllCaps, and the default value of the control could vary based on the theme, how do I determine what the default should be?

I could just pick an arbitrary default and not change the renderer until SetAllCaps is explicitly called, but then calls to GetIsAllCaps could return a potentially misleading (incorrect) value at any time before that happens.

Should this perhaps be implemented in a way that doesn't use Bindable properties (an event)? Essentially I feel like in order to not break this we have to do the same thing Android does (no getter), otherwise we would be exposing methods that could say that something isn't all caps even though it is, or vice versa.

I got some inspiration after I saw what @rmarinho did here: https://github.com/xamarin/Xamarin.Forms/pull/1829/files

Basically I'll just use an enum of default, true, false rather than a bool and that should take care of this.

@alanag13 sounds great, sorry I didn't see your response! Looking forward to the PR.

Despite what I said above I struggled a little bit because when the user chooses Default, I need to be able to check to see what IsAllCaps is/was by default for the Android theme, but no such property exists. I found a (somewhat unconventional) way to determine this...

When you use SetAllCaps and set true, TextView.TransformationMethod becomes an instance of AllCapsTransformationMethod... which is an internal Android class, so unfortunately we can't just do an is or something... however, we can use Java.Lang.Object to get the same of that class. Would comparing the name of that class to its known value if SetAllCaps is set to true here be acceptable?

@jassmith ^

@alanag13

Looking around it seems like that's what people have checked to see if it's set. The other variation I found would be to just check what happens to lower case text but checking the type should be fine.

Either way I would say just PR it with what you propose and let's not let it hold up getting the PR in there :-)

@alanag13 Are we ready to create the PR in the main repo?

@alanag13 ping! Let us know if you'd like us to return this to the backlog. Thanks!

Hey @samhouts, same here, sorry for the delay but I'll try to get this to you really soon. If I can't then we can go ahead and return this but I'd like to get it out to you in the next week or so.

I suspect @alanag13 will be a little too busy to continue on this. Congrats!

image

Back to the pile

@davidortinau @samhouts sorry to be such a tease for so long about getting this one done! Fatherhood is definitely a blocker for now but I'll make my ( hopefully more predictable ) return to OSS in time.

@jassmith this is very useful but addition, but what if we expand the allCaps as an abstraction in Xamarin.Forms itself? What I mean is, sometimes is useful if we could just set Label.IsAllCaps = true and it works not just in Android, but also in iOS. I think this feature itself is useful enough to not be a platform specific.

What you think about it @davidortinau? I know that this would change the structure of this whole spec, since It would need to add a BindableProperty to the label and implement specific logic in iOS to handle capitalising its contents, but I think it's worth!

Was this page helpful?
0 / 5 - 0 ratings