Last active
August 29, 2015 14:00
-
-
Save Clancey/5a5f831bf8a989c81014 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 abstract class StoryBoardRenderer<T> : UIViewController, IViewRenderer where T : UIViewController | |
{ | |
string storyboardName; | |
string viewControllerStoryBoardId; | |
public StoryBoardRenderer (string storyboard, string viewControllerStoryBoardId = "") | |
{ | |
this.viewControllerStoryBoardId = viewControllerStoryBoardId; | |
this.storyboardName = storyboard; | |
} | |
public abstract void SetModel (VisualElement model); | |
public SizeRequest GetSizeRequest (double widthConstraint, double heightConstraint) | |
{ | |
return NativeView.GetSizeRequest (widthConstraint, heightConstraint); | |
} | |
public void SetModelSize (Size size) | |
{ | |
Model.Layout (new Rectangle (Model.X, Model.Y, size.Width, size.Height)); | |
} | |
public abstract VisualElement Model { get; } | |
public UIView NativeView { | |
get { return StoryboardViewController.View; } | |
} | |
public UIViewController ViewController { get { return StoryboardViewController; } } | |
T storyboardViewController; | |
public T StoryboardViewController { | |
get { | |
return storyboardViewController ?? (storyboardViewController = CreateViewController()); | |
} | |
} | |
protected T CreateViewController() | |
{ | |
var storyboard = UIStoryboard.FromName (storyboardName,null); | |
return string.IsNullOrEmpty(viewControllerStoryBoardId) ? (T)storyboard.InstantiateInitialViewController () : (T) storyboard.InstantiateViewController(viewControllerStoryBoardId); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment