Xamarin.Forms之UserDialogs 重制版本

在 forms 里面,目前使用比较多的弹出组件是 Acr.UserDialogs ,但是这个组件有些小问题,比如 loading .hide 会同时把 toast 给一起关掉,android 下的 toast 希望是 安卓原生的toast 样子,而不是 底部弹出一个横条(其实是 android 的 Snackbar),对于 ios 的toast 也希望类似android 的样子,但是 Acr.UserDialogs 里面 toast 是 snackbar 样式,这并不符合产品需求情况。 GitHub地址: https://github.com/jxnkwlp/UserDialogs2 因此,我重制了一个版本, 包地址:https://www.nuget.org/packages/Passingwind.UserDialogs/ 对 toast 和 snackbar 做了区分,同时 loading 的关闭不会影响 toast 。 接口有这些: 目前没有异步接口,因为觉得 Acr.UserDialogs 的 异步接口和同步接口 对比起来不太好理解。 复制代码 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); 复制代码 使用方法: 各个接口 Config 都可以先设置默认值,比如 alert 里面 的确定按钮,可以全局设置为 “确定” AlertConfig.DefaultOkText = "确定"; 这样设置后,就不用每次使用alert 的时候去设置 确定按钮的文本。 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-xamarinhttps://www.cnblogs.com/passingwind/p/10122705.html
50000+
5万行代码练就真实本领
17年
创办于2008年老牌培训机构
1000+
合作企业
98%
就业率

联系我们

电话咨询

0532-85025005

扫码添加微信