Created
November 25, 2016 11:53
-
-
Save oddbear/e3eda01e0f19182e03fa3e665a79a101 to your computer and use it in GitHub Desktop.
A Xamarin.Forms (2.3.2) hack, that short circuit the layout system.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class PresenterTest : ContentPresenter | |
{ | |
BoxView _testView; | |
public PresenterTest() | |
{ | |
_testView = new BoxView { | |
BackgroundColor = Color.Red, | |
WidthRequest = 30, | |
HorizontalOptions = LayoutOptions.Fill, | |
VerticalOptions = LayoutOptions.Fill | |
}; | |
var children = (ObservableCollection<Element>)((ILayoutController)this).Children; | |
children.Add(_testView); | |
var rand = new Random(); | |
Device.StartTimer(TimeSpan.FromMilliseconds(100), () => | |
{ | |
_testView.WidthRequest = rand.Next(50, 80); | |
if (relayouts > 20) | |
{ | |
System.Diagnostics.Debug.WriteLine(relayouts); | |
return false; | |
} | |
if (timer++ < 30) | |
{ | |
System.Diagnostics.Debug.WriteLine(relayouts); | |
return false; | |
} | |
return true; | |
}); | |
} | |
int timer = 0; | |
int relayouts = 0; | |
protected override void LayoutChildren(double x, double y, double width, double height) | |
{ | |
relayouts++; | |
LayoutChildIntoBoundingRegion(_testView, new Rectangle(width / 2 - _testView.WidthRequest / 2, 50, _testView.WidthRequest, _testView.WidthRequest)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment