-
Notifications
You must be signed in to change notification settings - Fork 423
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Proposal] OnScreenSize Markup #425
Comments
First off I really like the idea. I would like to explore the C# Usage option a little, in theory anything that we can build in XAML we can do in C#. The MarkupExtension might not how we build the C# UI but it would be nice to work out how it would be done in C#. I am not at my machine right now but I would be happy to take a look at some possible suggestions if that helps? Another option I would like to check and I have to admit I don't know much about other approaches like OnIdiom, but is there a way to make things a little more type safe? Currently Small, Medium, etc. can take any value given it's |
Shaun, About your concern regarding the code-behind, I know that there are some static methods on class About type safety, I also don't feel very confortable on having "object" instead of the actual type the markup should return. I need to explore a little more how the markups were implemented on Xamarin (and also Maui). I Must confess I didin't take a closer look on it. About your concern on Let me get a closer look on how a code-behind extensions are implemented and I will bring some news back here. Thanks |
Ok, I just implemented a static class ( Here is the code for c# var label = new Label();
label.Padding = Markup.OnScreenSize<Thickness>(defaultSize: new Thickness(10, 10, 0, 0),
medium: new Thickness(15, 15, 0, 0),
large: new Thickness(20, 20, 0, 0)); Tell me what you think. |
@carolzbnbr, thanks again for moving this forward❣️ I took a look into your implementation and I have something that I want to highlight. Here you cache a bunch of device models and their Screen category (Small, Large, Medium, etc). And other At the first point, I would like to avoid this approach because means that we need to populate the models On Maui that will be var height = DeviceDisplay.Current.MainDisplayInfo.Height;
var width = DeviceDisplay.Current.MainDisplayInfo.Width; With that, we will solve the issue of having to keep a large list of devices and screen sizes, in the happy path we will need to perform this calculation just once. But we may have other scenarios, where having that collection and calculating the size against the device display info will not help too much. Scenarios where developers will be interested in the size of the 1. Having two apps opened at the same time AndroidFor example, in the image below I have two apps opened at the same time on my Motorola One device So even if it's considered a 2. Changing the Window size in a desktop appAlso, we can think of desktop scenarios where the screen size can change (if the dev allows the user to do so), in that case, should the Markup be triggered and change the control's size? 3. Using iPad as a second screenAnd one more scenario, now apple allows you to have your iPad as a secondary screen, so if you open a macOS application and drag and drop it inside the iPad how the markup we will handle that? For this one, I don't even know how the We can think of the answer for those scenarios together, and also if we should care about them (maybe I'm thinking too big). |
Hello @pictos, Here are my answers regarding the questions/issues you raised previously.
In the past, during development and tests on some iOS simulators, I had issues regarding getting the correct width/height on some devices, leading to a mismatch screen size (Width/Height) between iOS simulator devices, and actual devices, so thats why I keep a list of devices "hard-coded". The user is also able to extend the I agree that it is not an elegant solution, and yes, you are correct, that way either the maintainers, or the toolkit users (developers) would need to maintain that list up to date. That's why I've chose to implement two methods to the class you mentioned:
On my code we first attempt to execute method We may need to think about other solution, but in eiher case, we will end up having a kind of cache for
We could add a two-option-enum property on the markup for the user to choose from, for instance:
I don't have Android here for testing, but on the above sample screen you sent, does it resizes automatically when you open two apps at the same time? I mean, both app's view control page's gets resized when you put them in say
Well, I'm not expert on Maui, but on Xamarin, Markups are not involved (do not trigger) page lifecycle events. Actually is the opposide - page lifecycle events are the one responsible for triggering Xaml/Bindings/Markups/Converters, and etc. So I don't think it is possible to start a
We will need to test that, but I suspect that it keeps the aspect ratio of the In my opnion, we could start by having the markup compatible with mobile phones screens, and over the time we could evolve to desktop support.
No, you are not thinking too big. You are absolutely right, you raised important issues that we need to keep an eye on. By now, my main concern is related on the screen categorization versus it's size, how to make it less "hard coded" and more smart? I don't have an answer yet. |
@carolzbnbr sorry for the late reply, rush week on my side.
So let's focus on this first, with MAUI we have the concept of Window, maybe we can use it to define the size that we're. In my head this also solves the issue for desktop applications (where the user can change the size of the screen) |
I'm working on other issues, but let me know if you need any help. If you want/need a more real time conversation, you can join our discord server in the |
Sorry I do also intend on responding on the bits of our discussion but I haven't found time to properly read through it and come up with a response yet. Hopefully in the next few days I will |
Hi @pictos, Hope you are doing great.
Sorry, but I didn't understand what you have in mind. Is this proposal approved? Are we ready to start implementing it's MAUI version, or not? Also, As I told you, I can't think on a different approach on how to implement that categorization without having the screen-sizes (window-size) either In case this Proposal is approved, which approach do you consider more reliable to implement? Honestly I would rely in the dictionary (Width/Height versus Screen-Category) as I've done before, but you seemed uncomfortable with that approach, so I would like to hear from you first. |
Hey, @carolzbnbr I'm doing fine, how about you? Oh, I'm sorry for the confusion. So this proposal isn't approved yet, we need to vote on it first. But before voting, I would like to have something on the path to discuss with the other members and the community. About the screen sizes, you mentioned that you moved to the Dictionary approach due to issues on the iOS simulator, maybe on MAUI these issues are fixed, so I would like to confirm first. I can try to reserve some time to do a PoC and validate that if you don't have time right now. I also noticed that there's no implementation to desktop targets, is that right? |
I do like the look of that C# example but as you have pointed out I am not sure what could be done in XAML. Also have you pointed out the OnPlatform extension and actually other MarkupExtensions are not type safe. It's a shame if we can't achieve type safety but it wouldn't be the end of the world. |
Hi @bijington, hope you are doing great!
That class is meant to be used on a code-behind only.
Yeap, thats a shame! |
@carolzbnbr I am good and I hope the same is true with yourself! I like the idea of making things type safe where we can live you have suggested with the C# side. Sorry I missed that this would be C# only. I guess this |
Discussion from June Standup: https://www.youtube.com/watch?v=t3g_NrQfE8g
|
I propose to name it OnWindowsSize.
As for default values, I propose such options: https://mudblazor.com/features/breakpoints#breakpoints As for the Window resize, we can implement some kind of this: https://mudblazor.com/components/hidden#listening-to-browser-window-resize-events |
Not sure if its worth considering TV sizes too. I.e. you may want to display things differently on a 55" tv compared to a 32" tv |
Hi @VladislavAntonyuk thanks for the info.
This approach has some drawbacks: 1 - It is pixel-based, instead of "dp", or "dip" (Density-independent Pixels as used on Android) that could lead to issues like this. I know, i'm talking about "dp" which is not used on iPhones, Windows, mac, and etc, but wether we implement an algorithm similar to "dp" for all platforms we would avoid problems related to screen resolutions. 2 - They don't distinguish mobile phone sizes, they categorizes all mobile devices as ExtraSmall Devices, that could lead to problems, because we have many different mobile devices with many different sizes out there See here.
As far as I know, markups in Xamarin/Maui cannot initiate UI events in which would force the Actually it is exactly the opposite. The markups are triggered by the Xaml (UI) during the rendering phase. Please see here how a markup is created. They do not say that a markup can initiate UI events and that it could raise a Xaml (Views) changes by itself. A Markup is much similar to a Converter. |
Hello @brminnick,
We can change my implementation to maybe expose a couple of properties where the user could only sets their own values. On my current implementation this can be done by overriding methods of a class that is responsible for the categorization of devices. Please take a look here.
It is just like a regular Markup, so it already works on Bindable Properties. |
Removed, duplicate |
Hi @bijington,
No problem at all. :D
I'm almost sure of that. |
Just to say that this would be a fantastic addition - In the real world we have to support multiple device sizes - This is a real pain!!! This should really be embedded in Maui but that will never happen in the short time. Confused if this is approved already or not.. Cant wait to try it out. |
I am trying to have something similar but I am unable to get the resize events in IMarkupExtension, any suggestions? |
OnScreenSize Markup
Link to Discussion
Please link to the completed/approved Discussion
Summary
OnScreenSize Markup: A Markup for controlling Views according to a category a screen size fits in (Small, Medium, Large, ExtraLarge, etc).
Detailed Design
ScreenCategories.cs enum:
Depending on the screen-size (Width/Heigh), or a device model is, a
ScreenCategories
enum is used.ICategoryFallbackHandler.cs:
This interface is used to determine the category a device fits in, during first execution we attempt to execute
TryGetCategoryByDeviceModel
and wether it returns false, we attempt to executeTryGetCategoryByPhysicalSize
OnScreenSize.cs:
The markup itself.
ICategoryFallbackHandler.TryGetCategoryByDeviceModel
andICategoryFallbackHandler.TryGetCategoryByPhysicalSize
are called to determine theDevice Category
a device fits in, and after that, its result is cached to optimize next runs.Device Category
a device was categorized, a value will be obtained from it's corresponding Markup's property.For instance: If device category was categorized a
Large
, the markup will attempt to get the value from propertyOnScreenSize.Large
.OnScreenSize.DefaultSize
.Note: Before returning, each markup property's value are attempted to be converted to its property-type, making it possible to have a batter user experience, but allowing values to be converted to
GridLength
,Colors
,Thinkness
,RowDefinition
,ColumnDefinition
, and etc.Usage Syntax
XAML Usage
C# Usage
There is no code-equivalent for instantiating a Markup, since
IServiceProvider
instance fromOnScreenSize.ProvideValue(IServiceProvider serviceProvider)
is only available via XAML.The text was updated successfully, but these errors were encountered: