Xamarin.Forms之UserDialogs 重制版本

在 forms 里面,目前使用比较多的弹出组件是 Acr.UserDialogs ,可是这个组件有些小问题,好比 loading .hide 会同时把 toast 给一块儿关掉,android 下的 toast 但愿是 安卓原生的toast 样子,而不是 底部弹出一个横条(实际上是 android 的 Snackbar),对于 ios 的toast 也但愿相似android 的样子,可是 Acr.UserDialogs 里面 toast 是 snackbar 样式,这并不符合产品需求状况。android

 

GitHub地址: https://github.com/jxnkwlp/UserDialogs2ios

 

所以,我重制了一个版本, 包地址:https://www.nuget.org/packages/Passingwind.UserDialogs/git

对 toast 和 snackbar 作了区分,同时 loading 的关闭不会影响 toast 。github

 

接口有这些:异步

目前没有异步接口,由于以为 Acr.UserDialogs  的 异步接口和同步接口 对比起来不太好理解。ide

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);

 

使用方法:post

各个接口 Config 均可以先设置默认值,好比 alert 里面 的肯定按钮,能够全局设置为 “肯定”ui

AlertConfig.DefaultOkText = "肯定"; 

 

这样设置后,就不用每次使用alert 的时候去设置 肯定按钮的文本。spa

UserDialogs.Instance.Alert(new AlertConfig("您当前无权限操做!").AddOkButton());

 

相关依赖:翻译

Toast:  在android 上是原生的 toast 组件,在ios 上使用 MBProgressHUD

Snackbar:  在android 上是原生的 snackbar 组件,在ios 上使用 TTGSnackbar

Progress,Loading  在 android 上使用的是 KProgressHUD (https://github.com/jxnkwlp/KProgressHUD.csharp) 这个是代码翻译版本,  在 ios 上是使用 MBProgressHUD

 

更多说明能够查看 readme 文件 https://github.com/jxnkwlp/UserDialogs2

 

最后,以为好给个star 再走呗 😘 ~~~

 

原文连接:https://blog.wuliping.cn/post/rebuild-userdialogs-for-xamarin

相关文章
相关标签/搜索