Skip to content

Instantly share code, notes, and snippets.

@lubiepomaranczki
Last active May 6, 2020 06:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lubiepomaranczki/844ec05a225804545c68d908043e08f3 to your computer and use it in GitHub Desktop.
Save lubiepomaranczki/844ec05a225804545c68d908043e08f3 to your computer and use it in GitHub Desktop.
Solution proposed by Ryan Davis to the problem described here https://twitter.com/lawiluk/status/1257661151258820608 . This sample is for MVVMCross but you should be fine with other Frameworks.
public class FormsTestView : BaseViewController<FormsTestViewModel>
{
public override void ViewDidLoad()
{
base.ViewDidLoad();
EdgesForExtendedLayout = UIRectEdge.None;
Xamarin.Forms.Forms.Init();
var page = new FormsTestPage { BindingContext = ViewModel };
var formsViewController = page.CreateViewController();
var nativeView = formsViewController.View;
nativeView.TranslatesAutoresizingMaskIntoConstraints = false;
formsViewController.WillMoveToParentViewController(this);
formsViewController.ViewWillAppear(true);
View.Add(nativeView);
nativeView.LeftAnchor.ConstraintEqualTo(View.LeftAnchor).Active = true;
nativeView.TopAnchor.ConstraintEqualTo(View.TopAnchor).Active = true;
nativeView.RightAnchor.ConstraintEqualTo(View.RightAnchor).Active = true;
nativeView.BottomAnchor.ConstraintEqualTo(View.BottomAnchor).Active = true;
formsViewController.ViewDidAppear(true);
formsViewController.DidMoveToParentViewController(this);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment