Common UserDialogs interface for xamarin.forms(android/ios).
- Alert
- Confirm
- Toast
- ActionSheet
- Loading
- Progress
- DateTimePicker
- OptionsPicker
- Prompt
- Prompt with Multi-line (eg: Login Prompt )
- Android 7.1+
- iOS 10+
- NET Standard 2.0
Install nuget package in share/standard and platform projects. Passingwind.UserDialogs
Install-Package Passingwind.UserDialogs
a. Android Initialization (In your main activity)
UserDialogs.Init(this);
b. iOS (nothing to do)
void Toast(string message);
void Toast(ToastConfig config);
IDisposable Snackbar(string message, Action action = null);
IDisposable Snackbar(SnackbarConfig config);
void Alert(string message);
void Alert(AlertConfig config);
IDisposable ActionSheet(ActionSheetConfig config);
IDisposable Loading(LoadingConfig config);
IProgressDialog Progress(ProgressConfig config);
void Prompt(PromptConfig config);
void Form(PromptFormConfig config);
-
Alert
Set default field:
AlertConfig.DefaultOkText = "是"; // default 'yes' // AlertConfig.DefaultCancelText
Alert message:
UserDialogs.Instance.Alert("you message"); UserDialogs.Instance.Alert(new AlertConfig("you message").AddOkButton());
Confirm Message:
UserDialogs.Instance.Alert(new AlertConfig("you confirm message") .AddOkButton(action: () => { // ok handle }) .AddCancelButton());
-
Toast
UserDialogs.Instance.Toast("you message");
-
Snackbar
Set default field:
SnackbarConfig.DefaultTimeSpan = TimeSpan.FromSeconds(1.2); // default 1.2s SnackbarConfig.DefaultActionText = null; SnackbarConfig.DefaultBackgroundColor = null; SnackbarConfig.DefaultTextColor = null; SnackbarConfig.DefaultActionTextColor = null;
UserDialogs.Instance.Snackbar(new SnackbarConfig() { Message = "well down !!!", //Duration = TimeSpan.FromSeconds(3), //TextColor = Color.BurlyWood, //BackgroundColor = Color.Yellow, //ActionText = "sure", //ActionTextColor = Color.Red, Action = () => { // you handle here } });
-
ActionSheet
Set default field:
ActionSheetConfig.DefaultCancelText = "Cancel"; // default 'Cancel' ActionSheetConfig.DefaultDestructiveText = "Remove"; // default 'Remove' ActionSheetConfig.DefaultBottomSheet = false; // default false
var config = new ActionSheetConfig { Title = "Title", Message = "you message", // BottomSheet = false, // ItemTextAlgin = ActionSheetItemTextAlgin.Center; }; c.AddItem("item1"); c.AddItem("item2"); c.AddItem("item3", action: () => { // you handle }); //config.AddCancel(); //config.AddDestructive(); UserDialogs.Instance.ActionSheet(config);
-
Loading
Show loading hub when task start.
var dialog = UserDialogs.Instance.Loading(new LoadingConfig("please wait") { Cancellable = true, // can cancel loading when show loading CancelAction = () => // you action handle Duration = TimeSpan.FromSeconds(5), // show loading duration second // MarkType = MarkType.Black }); // close dialog if you need. dialog.Dispose();
-
Progress
show progress hub.
var dialog = UserDialogs.Instance.Progress(new ProgressConfig("download...") { Cancellable = true, // can cancel loading when show loading CancelAction = () => // you action handle }); // set current progress value when task update dialog.SetProgress(30); // 1-100 // close dialog if you need. dialog.Hide();
-
Form
show prompt form
UserDialogs.Instance.Form(new PromptFormConfig() { Title = "Please Login", OnAction = (result) => { if(result.Ok){ var username = result.Result["username"]; // then you code ... } } } .AddItem("username", "username", maxLength: 16) // add 'username' inputbox .AddItem("password", "password", InputType.Password, maxLength: 6) // add 'password' password inputbox );
- Android- Progress/Loading uses KProgressHUD
- iOS - Progress/Loading/Toast uses MBProgressHUD
- iOS - Snackbar uses TTGSnackbar