-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Conversation
ee25cd5
to
4d418f3
Compare
e5243fa
to
9fe796b
Compare
public const string Android = "Android"; | ||
public const string WinPhone = "WinPhone"; | ||
public const string Windows = "Windows"; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello, This is Tizen . Please don't forget me.
public const string Tizen = "Tizen";
I may have missed it, but it doesn't look like we're testing the backcompat piece anywhere. All of the tests are updated to use the new syntax, so we don't have any tests that confirm backwards compatibility. |
@samhouts all prior tests using the Xaml |
Tizen will be added in a future update, wont be forgotten before stable release. |
The loss of type safety and added verbosity seems far worse than simply having a slightly bloated |
@gtbuchanan we went for non-generic As for the conversion issue, please file an issue and I'll look at it |
I agree that the loss of type safety seems to be a step in the wrong direction. var menuButtonSize = (OnPlatform<double>)Application.Current.Resources["MenuButtonSize"];
return new GridLength(Device.OS == TargetPlatform.iOS ? menuButtonSize.iOS : menuButtonSize.Android); And look at the amount of type casts I have to do now (please correct me if this can be done in a better way): var menuButtonSize = (OnPlatform<double>)Application.Current.Resources["MenuButtonSize"];
var v = menuButtonSize.Platforms.First(p => p.Platform.First().Equals(Device.RuntimePlatform)).Value;
return new GridLength(double.Parse((string)v)); Is this intended? It doesn't feel right writing this code. The xaml is also slightly more verbose now, it has gone from this: <OnPlatform x:TypeArguments="x:Double" iOS="40" Android="60" x:Key="MenuButtonSize" /> to this: <OnPlatform x:TypeArguments="x:Double" x:Key="MenuButtonSize">
<On Platform="iOS">40</On>
<On Platform="Android">60</On>
</OnPlatform> I don't mind the slightly more verbose xaml, but I don't really like the loss of type safety. |
@appbureauet : this works fine for me: |
@fuse314 : thanks that works! new GridLength((OnPlatform<double>)Application.Current.Resources["MenuButtonSize"]); Just not quite sure why it works? |
@appbureauet it works because |
@akamud thank you - that makes sense. |
So how this construction will be looking now? new Setter { Property = Label.FontSizeProperty, Value = Device.GetNamedSize(NamedSize.Medium, typeof(Label)) * Device.OnPlatform(1.0, 1.0, 0.7) }; |
@kapitspo you could do it like this: new Setter
{
Property = Label.FontSizeProperty,
Value = Device.GetNamedSize(NamedSize.Medium, typeof(Label))
* (Device.RuntimePlatform == Device.WinPhone ? 0.7 : 1.0)
}; |
Thanks... Not sure if I like it new way. I have projects where I target all 3 major platforms, and combination of Device.OnPlatform and Device.Idiom did the job for me. Why fixing things which were fit to purpose in 99% of scenarios? At least, please remove "deprecated" warning for now. You've touched one of the sensitive areas in cross-platform design, so I guess it would be wise to give us "old timers" a bit more time to get used to the change. Or challenge it all the way back to where it was. |
How would I set a default value in xaml? I have tried:
and
But neither work? |
Indeed, default doesn't seem to be working. |
I'm just curious, but why use magic strings when you can use an Enum?
|
@brianlagunas According to the original thread the reasoning is:
Personally, I think this solution as implemented is far worse than the stated problem above. There are a finite number of platforms even into the forseeable future (eg, Tizen, MacOS) and adding a handful of new entries to the enum over time seems eminently reasonable. Also, for 3rd parties you could just add a "release-valve" |
Totally agree there are a finite number of new platforms, and I would say there doesn't need to be a requirement that the Platform implementation should have to be part of the Xamarin Forms repository like Tizen. That said magic string seems more error prone than to simply require Tizen or whoever to submit a PR adding their platform to an OS/RuntimePlatform enum. Think of it like a developer adding their RSS feed to Planet Xamarin. Not to mention somehow we ended up with |
I have a feeling that the developer experience was not considered when creating this API. Meaning the API was not used in a production app scenario, but instead created from inside a sandbox. I'm assuming/hoping there is some technical reason why this was a string and not Enum. Otherwise it's just a poor coding practice. |
In a scenario like this:
What would be the best way to rewrite this given this new API? I'm finding that it requires a switch statement outside of the scenario to store the Thickness property to then apply it in the Content construction:
Or am I just missing something easy? /crossesfingers |
@renzska You just pointed out another major issue with this new API. IMO, it's not very well thought out. Unless I too am missing something obvious. |
@renzska I used an IIFE in the first example of my original comment to avoid the intermediary variable. It's not pretty, but you can use a similar solution. |
I don't agree with strings instead of a type and losing type safety. Also, I don't see anywhere mentioned what happens if the platform string is misspelled. |
Is this how default should work in the new way? Because it is not working at the moment: <Label Text="This should be the default">
<Label.Text>
<OnPlatform x:TypeArguments="x:String">
<On Platform="iOS">iOS</On>
</OnPlatform>
</Label.Text>
</Label> If I run this sample on Android, the text is empty. |
@akamud no what you are doing is overriding the Text Value, not setting a default. While there are some arguments that the new OnPlatform is more extensible, it wasn't fully thought out. The current releases would require that you specify the platform otherwise you effectively get |
Description of Change
Implement the change proposed in https://forums.xamarin.com/discussion/84632/redesign-onplatform
C# code should be ported to this:
New xaml syntax looks like this:
(note: I tested it, it actually works with emojis as platform names. Be creative.)
Bugs Fixed
none. but allow 3rd party platforms
API Changes
Added
Obsoleted
Removed
All Tizen overrides. Not published in any release yet.
Internal
Device.OS
setterBehavioral Changes
None, hopefully
PR Checklist