Skip to content
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

[Material,WIP] Add attached properties for Material specific attributes #5005

Open
PureWeen opened this Issue Jan 17, 2019 · 9 comments

Comments

5 participants
@PureWeen
Copy link
Contributor

PureWeen commented Jan 17, 2019

Add Material Attached properties

  • Button Styles
    There are 4 button styles in material (https://material.io/design/components/buttons.html#specs): Contained (current style), Border, Text, Toggle / Icon. We could create an attached property that allows us to set this style: Material.ButtonStyle="Contained". One thing to note with this is that Android will be hard, if not impossible, to dynamically change. iOS just has a theme that you apply (not so sure if it supports undoing a style and may not actually work). Android has a style resource that probably needs to be applied in the constructor of the renderer. To support dynamic changes like this, we will probably not be able to use the "fast renderer" style and would need to use the ViewRenderer<T, T> base. iOS is already using this, so we can always recreate the control, but for Android we may lose the optimizations gained.
  • Entry / Editor Styles
  • Frame / Card Styles

API

Current front runner

<Button material:Button.Style="Outline"></Button>

Other API Choices

<Button Material.ButtonStyle="Outline"></Button>

Pros

  • One Attached property

cons

  • Too many styles underneathe the same namespace that don't apply to each control

<Button material:Button.Style="Outline"></Button>

Pros

  • Attached properties can easily be split up according to the Element it's going to be applied to.

Cons

  • having to import custom namespaces is cumbersome for developers.

<Button MaterialButton.Style="Outline"></Button>

Pros

  • Attached properties can easily be split up according to the Element it's going to be applied to.

Cons

  • Will add a large number of attached properties to default namespace intellisense

Backward Compatibility

Difficulty : medium

@arggrande

This comment has been minimized.

Copy link

arggrande commented Mar 8, 2019

Hi, here from the .NET Standup Video which mentioned this PR.

I love this feature ❤️

Would it be possible to specify something at the App level to auto-import the material namespace into the Views?

like App.UseMaterial = true;

Then you could have something like:

<Button MaterialStyle="Outline"></Button>

Also, regarding :

One thing to note with this is that Android will be hard, if not impossible, to dynamically change

What do you mean specifically by this? Do you mean the styles.xml file android uses?

@arggrande

This comment has been minimized.

Copy link

arggrande commented Mar 8, 2019

Ooo I like the suggestion in #5487 , around the assembly-level attribute attach.

@PureWeen

This comment has been minimized.

Copy link
Contributor Author

PureWeen commented Mar 8, 2019

@arggrande something like

<Button MaterialStyle="Outline"></Button>

Is a possible option. If we were to put all the material things into the same namespace then you wouldn't need the prefix. My only concern with this was discoverability or possibly having too many things show up by default

MaterialEditorProp1, MaterialEditorProp2, MaterialEditorProp3,
MaterialButtonProp1, MaterialButtonProp2, etc...

whereas with
material:Editor.Prop1

A conditional like you have is an interesting thought. I wonder if we could just enable intellisense if you set the visual

that'd be kind of neat

@pranshaggarwal

This comment has been minimized.

Copy link

pranshaggarwal commented Mar 8, 2019

@PureWeen we can use new XmlnsDefinitionAttribute to combine multiple CLR namespace with single XML namespace

@PureWeen

This comment has been minimized.

Copy link
Contributor Author

PureWeen commented Mar 8, 2019

@pranshaggarwal Right! Which is a good point. Because we could just leave it in its own namespace and then if people wanted to just combine them they could

@pranshaggarwal

This comment has been minimized.

Copy link

pranshaggarwal commented Mar 8, 2019

One Question, Doesn't this code make the xml invalid?
<Button MaterialStyle="Outline"></Button>

@PureWeen

This comment has been minimized.

Copy link
Contributor Author

PureWeen commented Mar 9, 2019

@pranshaggarwal yes :-/ that wasn't one of the case I had even initially proposed and just wasn't thinking of it straight when I commented above.

My main point with that still stands even with using XmlnsDefinitionAttribute
I wonder if that will put too many properties under one place

Material.ButtonStyle vs material:Button.Style

I played around with it a little bit here with using XmlnsDefinitionAttribute
https://github.com/xamarin/Xamarin.Forms/tree/visual_buttonstyle

The other nuance of XmlnsDefinitionAttribute is that the cross platform library has to have an init call or something calling into Xamarin.Forms.Material otherwise it runs into issues with the linker.

For example if you just call init on the platform project then the cross platform fails to compile with a namespace not found exception

@pranshaggarwal

This comment has been minimized.

Copy link

pranshaggarwal commented Mar 9, 2019

@PureWeen yes you are right, XmlnsDefinitionAttribute will not solve this problem.

Another option is to defines all the attached property in their respective class then have a clone of all the properties in one class(Material).

Btw if we are able to somehow simplify the attached property syntax as I describe here #5487 then we will not have to worry about this.

@davidortinau davidortinau pinned this issue Mar 9, 2019

@samhouts samhouts moved this from To do to Returned to backlog in Sprint 149 Mar 11, 2019

@StephaneDelcroix

This comment has been minimized.

Copy link
Member

StephaneDelcroix commented Mar 12, 2019

to avoid reinventing the wheel again and again, I'd go for something very similar to PlatformSpecific

<Button m:Button.Style="Outline" />

everyone being able to redefine his own MaterialButton and include the properties directly. This is also what gives us the best options to move forward if we decide at some point to move the Material Style property directly to the Button class

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.