Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

[C, iOS, Android] LayoutCompression #1136

Merged
merged 4 commits into from Sep 13, 2017

Conversation

Projects
None yet
6 participants
Member

StephaneDelcroix commented Sep 12, 2017 edited

Description of Change

Enable Layout Compression for iOS and Android.

NOTE: this feature is still in beta, and opt-in only

Layout Compression allows the user to avoid creating renderers for Layouts (i.e. StackLayout, ContentView, ...).

Pros:

  • less renderers to create, manage and dispose
  • less UI elements on screen

Cons:

  • compressed layouts can't have BG colors, gesture recognizers
  • no transformation
  • ...

Sample:

<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
	xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
	x:Class="Xamarin.Forms.Controls.CompressedLayout"
	Padding="0,20,0,0">
	<StackLayout Padding="6" CompressedLayout.IsHeadless="true">
		<Label Text="First"/>
		<StackLayout Padding="6" CompressedLayout.IsHeadless="true">
			<Label Text="Second"/>
			<ContentView Padding="6" CompressedLayout.IsHeadless="true" BackgroundColor="Pink" >
				<Label x:Name="this" Text="Third"/>
			</ContentView>
			<Label Text="Fourth"/>
		</StackLayout>
		<Label Text="Fifth"/>
	</StackLayout>
</ContentPage>

Enabling LayoutCompression for this layout only creates a Renderer for the page, and one for each label. The BackgroundColor property on the inner ContentView is ignored.

Bugs Fixed

/

API Changes

Added:

public static readonly BindableProperty CompressedLayout.IsHeadlessProperty;

Behavioral Changes

/

PR Checklist

  • Has tests (if omitted, state reason in description)
  • Rebased on top of master at time of PR
  • Changes adhere to coding standard
  • Consolidate commits as makes sense

@StephaneDelcroix StephaneDelcroix requested review from jassmith and hartez Sep 12, 2017

@@ -34,7 +34,9 @@ public static NumberKeyListener Create(InputTypes inputTypes)
if ((inputTypes & InputTypes.NumberFlagDecimal) == 0)
{
// If decimal isn't allowed, we can just use the Android version
+#pragma warning disable 0618 // Find issues with Android API usage
@hartez

hartez Sep 12, 2017

Member

Which part of the next line is giving an obsolete warning?

@StephaneDelcroix

StephaneDelcroix Sep 13, 2017

Member

On X.A 7.5.0.15 (Alpha channel at this time): 'DigitsKeyListener.GetInstance(bool, bool)' is obsolete

[Register ("getInstance", "(ZZ)Landroid/text/method/DigitsKeyListener;", ""), Obsolete ("deprecated")]
public unsafe static DigitsKeyListener GetInstance (bool sign, bool @decimal);
@StephaneDelcroix

StephaneDelcroix Sep 13, 2017

Member

fixed in master

- public VisualElementPackager(IVisualElementRenderer renderer)
+ VisualElement _element;
+
+ IElementController ElementController => _element;// _renderer.Element as IElementController;
@hartez

hartez Sep 12, 2017

Member

Can probably remove this comment.

+ if (CompressedLayout.GetIsHeadless(child)) {
+ child.IsPlatformEnabled = true;
+ FillChildrenWithRenderers(child);
+ } else {
@hartez

hartez Sep 12, 2017

Member

Missing a tab on the next line.

@@ -13,16 +13,20 @@ public class VisualElementPackager : IDisposable
bool _isDisposed;
- IElementController ElementController => Renderer.Element as IElementController;
+ IElementController ElementController => _element;// Renderer.Element as IElementController;
@hartez

hartez Sep 12, 2017

Member

Can probably remove this comment.

Xamarin.Forms.Core/Layout.cs
@@ -237,6 +237,13 @@ protected void UpdateChildrenLayout()
double w = Math.Max(0, width - Padding.HorizontalThickness);
double h = Math.Max(0, height - Padding.VerticalThickness);
+ var isHeadless = CompressedLayout.GetIsHeadless(this);
+ var headlessOffset = CompressedLayout.GetHeadlessOffset(this);
+ for (var i = 0; i < LogicalChildrenInternal.Count; i++) {
@samhouts

samhouts Sep 12, 2017

Member

Braces on their own lines. You're in Core territory, now! muwahaha

@StephaneDelcroix

StephaneDelcroix Sep 13, 2017

Member

don't scratch that itch! :)

fixed by removing the braces.

- public VisualElementPackager(IVisualElementRenderer renderer)
+ VisualElement _element;
+
+ IElementController ElementController => _element;// _renderer.Element as IElementController;
@samhouts

samhouts Sep 12, 2017

Member

Remove commented code

- if (_childViews == null)
- _childViews = new List<IVisualElementRenderer>();
+ if (CompressedLayout.GetIsHeadless(view)) {
+ var _packager = new VisualElementPackager(_renderer, view);
@samhouts

samhouts Sep 12, 2017

Member

the underscore in the variable name is a little confusing here, I think.

@StephaneDelcroix

StephaneDelcroix Sep 13, 2017

Member

fixed. at some point that variable was a field...

Contributor

adrianknight89 commented Sep 13, 2017

compressed layouts can't have BG colors, gesture recognizers
no transformation

Are these limitations permanent or to be fixed in the future?

<ContentView Padding="6" CompressedLayout.IsHeadless="true" BackgroundColor="Pink" >

Should there be a compile-time / run-time error for this instead of silent fail of the bgcolor set? The reason I ask this is I don't like it when people pollute their visual tree with redundant stuff. If bgcolor has no use there, then it shouldn't be there?

Member

StephaneDelcroix commented Sep 13, 2017

@adrianknight89 at this point we have no plan for supporting BgColor on headless layouts, nor do we have plans for validating that case

StephaneDelcroix added some commits Sep 13, 2017

@StephaneDelcroix StephaneDelcroix merged commit 8ee62e8 into master Sep 13, 2017

3 of 7 checks passed

VSTS: Android API19 Validation Legacy Renderers UITests Running
Details
VSTS: Android API23 Validation Legacy Renderers UITests Running
Details
VSTS: Android API25 Validation Legacy Renderers UITests Running
Details
VSTS: iOS Validation UITests Running
Details
VSTS: Xamarin Forms OSX pull-1136 - (987939) Succeeded
Details
VSTS: Xamarin Forms Windows 987939 Succeeded
Details
VSTS: Xamarin Forms Windows (PR Builds) Started PR process 979026
Details

@StephaneDelcroix StephaneDelcroix deleted the LayoutCompression branch Sep 13, 2017

@StephaneDelcroix thank you for this PR and this feature. Wondering, where can one read about limitations and why they are there. Maybe it's just me can't find the information

@samhouts samhouts added D-15.5 and removed cla-not-required labels Oct 10, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment