Skip to content

Instantly share code, notes, and snippets.

View prin53's full-sized avatar

Denys Fiediaiev prin53

View GitHub Profile
public class ViewsContainer : MvxIosViewsContainer
{
private const string PadPostfix = ".Pad";
private const string PhonePostfix = ".Phone";
private const string StoryboardResourceType = "storyboardc";
public override IMvxIosView CreateViewOfType(Type viewType, MvxViewModelRequest request)
{
var attribute = viewType.GetCustomAttribute<MvxFromStoryboardAttribute>();
[Register(nameof(ViewController))]
[MvxFromStoryboard("Storyboard")]
[MvxRootPresentation]
public partial class ViewController : MvxViewController<ViewModel>
{
public ViewController(IntPtr handle) : base(handle)
{
/* Required constructor */
}
public class ViewModel : MvxViewModel
{
public string Text { get; }
public ViewModel()
{
Text = "Hello!";
}
}
public abstract class MvxAlertViewController<TViewModel> : MvxViewController<TViewModel>, IMvxAlertViewController
where TViewModel : class, IMvxViewModel
{
private const string ContentViewControllerKey = "contentViewController";
private MvxIosViewPresenter _viewPresenter;
private UIAlertController _alertController;
public override string Title
{
protected UIAlertAction AddAction(ICommand command, string title, UIAlertActionStyle style, bool isPreferred)
{
var alertAction = UIAlertAction.Create(title, style, async _ =>
{
command.SafeExecute();
await _viewPresenter
.CloseModalViewController(_alertController, new MvxModalPresentationAttribute())
.ConfigureAwait(false);
});
[MvxAlertPresentation(PreferredStyle = UIAlertControllerStyle.Alert)]
public class LoginViewController : MvxAlertViewController<LoginViewModel>
{
public override void ViewDidLoad()
{
base.ViewDidLoad();
Title = "Login";
Message = "Enter your username and login in the fields below:";
public sealed class MvxAlertIosViewPresenter : MvxIosViewPresenter
{
public MvxAlertIosViewPresenter(IUIApplicationDelegate applicationDelegate, UIWindow window)
: base(applicationDelegate, window)
{
AttributeTypesToActionsDictionary.Register<MvxAlertPresentationAttribute>(
ShowAlertView,
CloseAlertView
);
}
private Task<bool> ShowAlertView(
Type viewType,
MvxAlertPresentationAttribute attribute,
MvxViewModelRequest request
)
{
var viewController = this.CreateViewControllerFor(request);
if (!(viewController is IMvxAlertViewController alertViewController))
{
public UIAlertController Wrap(MvxAlertPresentationAttribute attribute, MvxIosViewPresenter viewPresenter)
{
_viewPresenter = viewPresenter;
_alertController = UIAlertController.Create(
attribute.Title,
attribute.Message,
attribute.PreferredStyle
);
public class MvxAlertPresentationAttribute : MvxBasePresentationAttribute
{
public static UIAlertControllerStyle DefaultPreferredStyle = UIAlertControllerStyle.ActionSheet;
public UIAlertControllerStyle PreferredStyle { get; set; } = DefaultPreferredStyle;
public string Title { get; set; }
public string Message { get; set; }
}