2016-03-22 23:02:25 +03:00
using System ;
using System.Collections.Generic ;
using System.Linq ;
using System.Text ;
using System.Threading.Tasks ;
using Xamarin.Forms.CustomAttributes ;
2016-04-26 18:20:55 +03:00
using Xamarin.Forms.Internals ;
2016-03-22 23:02:25 +03:00
namespace Xamarin.Forms.Controls
{
[Preserve (AllMembers=true)]
[Issue (IssueTracker.Github, 1758, "LayoutTo needs to be smarted about using layout specific API calls", PlatformAffected.Android | PlatformAffected.iOS | PlatformAffected.WinPhone)]
public class Issue1758 : ContentPage
{
ListView _list ;
Button _button ;
public Issue1758 ( )
{
_list = new ListView { ItemsSource = new [ ] { "hello" , "world" , "from" , "xamarin" , "forms" } } ;
_button = new Button { Text = "Button" } ;
// The same behavior happens for both Absolute and Relative layout.
2016-04-07 09:03:59 +03:00
//var layout = true ? Relative() : Absolute();
var layout = Relative ( ) ;
2016-03-22 23:02:25 +03:00
Animate ( ) ;
Content = layout ;
}
Layout Relative ( )
{
var layout = new RelativeLayout ( ) ;
layout . Children . Add ( _list ,
Forms . Constraint . RelativeToParent ( p = > p . X ) ,
Forms . Constraint . RelativeToParent ( p = > p . Y ) ,
Forms . Constraint . RelativeToParent ( p = > p . Width ) ,
Forms . Constraint . RelativeToParent ( p = > p . Height )
) ;
layout . Children . Add ( _button ,
Forms . Constraint . Constant ( 0 ) ,
Forms . Constraint . Constant ( 300 ) ) ;
return layout ;
}
Layout Absolute ( )
{
var layout = new AbsoluteLayout { Children = { _list , _button } } ;
AbsoluteLayout . SetLayoutBounds ( _list , new Rectangle ( 0 , 0 , AbsoluteLayout . AutoSize , AbsoluteLayout . AutoSize ) ) ;
AbsoluteLayout . SetLayoutBounds ( _button , new Rectangle ( 0 , 300 , AbsoluteLayout . AutoSize , AbsoluteLayout . AutoSize ) ) ;
return layout ;
}
async void Animate ( )
{
// Comment this delay out to see the bug
// await Task.Delay(500);
2016-04-12 22:30:27 +03:00
await _button . LayoutTo ( new Rectangle ( 100 , 100 , 100 , 100 ) , 1000 ) ;
2016-03-22 23:02:25 +03:00
}
}
}