Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Spec: Visual #4435

Closed
davidortinau opened this issue Nov 15, 2018 · 5 comments · Fixed by #4449
Closed

Spec: Visual #4435

davidortinau opened this issue Nov 15, 2018 · 5 comments · Fixed by #4449

Comments

@davidortinau
Copy link
Contributor

davidortinau commented Nov 15, 2018

Rationale

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.

Goals

Stretch Goals

  • User control of rendering
    • In renderer
    • In cross-platform code
  • Support of Material-only properties
    • Elevation in particular would be neat
  • Implement a material switch into iOS
  • SearchBar

Limitations

  • The controls remain native controls, and as such there will naturally still be differences in areas such as fonts, shadows, elevation, and colors (consider how iOS does alpha blending on the navigation bar for example, resulting in visual color differences compared to Android).
  • Not all controls have a material implementation or style.

Implementation

Branch working from

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

[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>
	{
	}
}

Example CSS


* {
  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.

Implementation Notes

Currently just creating new renderers for material components

  • If a single renderer contains a reference to both the material text box and the normal one then the material one can't be linked out
  • When implementing the MaterialEntryRenderer on iOS the placeholder code will break it so for now I feel it's just easier to develop as it's own thing while it's being spiked and once it's in a happy place merging behavior can make sense

iOS

https://www.nuget.org/packages/Xamarin.iOS.MaterialComponents/

Android

@AmrAlSayed0
Copy link

So is this somehow supposed to be complementary to Shell/Material Shell spec?

@andersondamasio
Copy link

should this launch come only in 2019?

@davidortinau
Copy link
Contributor Author

@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.

@PureWeen
Copy link
Contributor

Added Button Icon APIs. Comments are welcome

@samhouts samhouts pinned this issue Mar 4, 2019
@samhouts samhouts modified the milestones: 4.0.0, 3.6.0 Mar 4, 2019
@samhouts
Copy link
Member

samhouts commented Mar 4, 2019

I think we'll go ahead and close this spec. We'll track remaining work on the sub issues linked above. Thanks!!

@samhouts samhouts closed this as completed Mar 4, 2019
@davidortinau davidortinau unpinned this issue Mar 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants