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 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>(); |
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
[Register(nameof(ViewController))] | |
[MvxFromStoryboard("Storyboard")] | |
[MvxRootPresentation] | |
public partial class ViewController : MvxViewController<ViewModel> | |
{ | |
public ViewController(IntPtr handle) : base(handle) | |
{ | |
/* Required constructor */ | |
} |
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 class ViewModel : MvxViewModel | |
{ | |
public string Text { get; } | |
public ViewModel() | |
{ | |
Text = "Hello!"; | |
} | |
} |
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 MvxAlertViewController<TViewModel> : MvxViewController<TViewModel>, IMvxAlertViewController | |
where TViewModel : class, IMvxViewModel | |
{ | |
private const string ContentViewControllerKey = "contentViewController"; | |
private MvxIosViewPresenter _viewPresenter; | |
private UIAlertController _alertController; | |
public override string Title | |
{ |
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
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); | |
}); |
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
[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:"; |
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 sealed class MvxAlertIosViewPresenter : MvxIosViewPresenter | |
{ | |
public MvxAlertIosViewPresenter(IUIApplicationDelegate applicationDelegate, UIWindow window) | |
: base(applicationDelegate, window) | |
{ | |
AttributeTypesToActionsDictionary.Register<MvxAlertPresentationAttribute>( | |
ShowAlertView, | |
CloseAlertView | |
); | |
} |
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
private Task<bool> ShowAlertView( | |
Type viewType, | |
MvxAlertPresentationAttribute attribute, | |
MvxViewModelRequest request | |
) | |
{ | |
var viewController = this.CreateViewControllerFor(request); | |
if (!(viewController is IMvxAlertViewController alertViewController)) | |
{ |
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 UIAlertController Wrap(MvxAlertPresentationAttribute attribute, MvxIosViewPresenter viewPresenter) | |
{ | |
_viewPresenter = viewPresenter; | |
_alertController = UIAlertController.Create( | |
attribute.Title, | |
attribute.Message, | |
attribute.PreferredStyle | |
); |
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 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; } | |
} |