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-xamarin


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM