Customers desire to more easily create Xamarin.Forms applications that look mostly or exactly the same by default on iOS and Android. In examining the style of design that is most typically implemented, Material design is the most beneficial starting point.
Developers should be able to express their design for this starting point at the top level of their Xamarin.Forms application, and have that preference reflected throughout.
Developers should be able to also control this preference at the ContentPage and control levell.
In the future, additional Visual styles may be supported, such as Cupertino, Fluent, or any other design styling that someone would wish to implement themselves.
Target controls
User control of rendering
public class VisualElement
{
[TypeConverter] //used for css
public IVisual Visual { get; set; } //BP
}
public interface IVisual {}
namespace Xamarin.Forms
{
public static class Visual
{
public static IVisual MatchParent { get; } = new MatchParentVisual();
public static IVisual Default { get; } = new DefaultVisual();
public static IVisual Material { get; } = new MaterialVisual();
public sealed class MaterialVisual : IVisual { }
public sealed class DefaultVisual : IVisual { }
public sealed class MatchParentVisual : IVisual { }
}
public interface IVisual { }
}
namespace Xamarin.Forms
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
public abstract class HandlerAttribute : Attribute
{
protected HandlerAttribute(Type handler, Type target, Type[] supportedVisuals = null)
{
SupportedVisuals = supportedVisuals ?? new[] { typeof(Visual.DefaultVisual) };
TargetType = target;
HandlerType = handler;
}
internal Type[] SupportedVisuals { get; private set; }
internal Type HandlerType { get; private set; }
internal Type TargetType { get; private set; }
public virtual bool ShouldRegister()
{
return true;
}
}
}
### Example Renderer ###
```C#
[assembly: ExportRenderer(typeof(Entry), typeof(MaterialTextViewRenderer), new[] { typeof(Visual.MateralVisual) })]
namespace Xamarin.Forms.ControlGallery.Android
{
public class MaterialEntryRenderer : ViewRenderer<Xamarin.Forms.Controls.App.MaterialTextView, global::Android.Support.Design.Widget.TextInputLayout>
{
}
}
* {
visual: material;
}
Button {
visual: fluent;
}
.normal {
visual: normal;
}
At Renderer selection time the Visual property of the View is inspected and included in the renderer selection process. When the Visual changes the Renderer is recreated from scratch along with any children. The SupportsVisualTypes property on the renderer is tested
IVisual is nothing more than a marker interface used at renderer selection time. For something like a skia backend you would then use an attached property to attach the drawing to the visual. This API gives us maximum flexibility.
Currently just creating new renderers for material components
https://www.nuget.org/packages/Xamarin.iOS.MaterialComponents/
So is this somehow supposed to be complementary to Shell/Material Shell spec?
should this launch come only in 2019?
@AmrAlSayed0 it is how we will support things like MaterialShell, yes. This works independent of Shell.
@andersondamasio we will have a preview available in a few weeks. When I get to my desk I will share some screenshots of the progress to see what everyone thinks.
Added Button Icon APIs. Comments are welcome
I think we'll go ahead and close this spec. We'll track remaining work on the sub issues linked above. Thanks!!
Most helpful comment
@AmrAlSayed0 it is how we will support things like MaterialShell, yes. This works independent of Shell.
@andersondamasio we will have a preview available in a few weeks. When I get to my desk I will share some screenshots of the progress to see what everyone thinks.