From 63703ee7bc5a79bb9e6a360c31ae3f3c3a8bb9c9 Mon Sep 17 00:00:00 2001 From: duqingquan Date: Mon, 2 Dec 2024 15:10:32 +0800 Subject: [PATCH] =?UTF-8?q?waiting=20view=20=E5=A2=9E=E5=8A=A0=20topPageVi?= =?UTF-8?q?ew=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../utssdk/app-android/WaitingView.uts | 29 +++++----- .../utssdk/app-android/showToast.uts | 56 +++++++++---------- 2 files changed, 44 insertions(+), 41 deletions(-) diff --git a/uni_modules/uni-prompt/utssdk/app-android/WaitingView.uts b/uni_modules/uni-prompt/utssdk/app-android/WaitingView.uts index 09f9862..76face2 100644 --- a/uni_modules/uni-prompt/utssdk/app-android/WaitingView.uts +++ b/uni_modules/uni-prompt/utssdk/app-android/WaitingView.uts @@ -57,17 +57,19 @@ export class WaitingView{ private loadingHeight = 0 private LoadingIcon: string = "" private mBitmap: Bitmap | null = null; - - + + private mpopWindow?: PopupWindow = null - + private currentHandler: Handler - + + private hostView:View | null = null + //{"back":"transmit","height":"112px","loading":{"display":"block","height":"55px","icon":"__uniapperror.png","jSONArray":false},"padding":"10px","size":"16px","width":"140px"} - constructor(context?: Activity, style: UTSJSONObject) { - + constructor(context?: Activity, style: UTSJSONObject,view:View) { + this.context = context; this.style = style.toJSONObject() as JSONObject this.screenWidth = context?.getResources()?.getDisplayMetrics()!.widthPixels @@ -79,7 +81,8 @@ export class WaitingView{ this.textView = this.waitingView.findViewById(R.id.dcloud_tv_loading) this.seaparatorView = this.waitingView.findViewById(R.id.dcloud_view_seaparator) this.mImageView = this.waitingView.findViewById(R.id.dcloud_iv_loading) - + this.hostView = view + this.textView.setMaxLines(2) this.handlerArguments() @@ -92,7 +95,7 @@ export class WaitingView{ this.currentHandler = new Handler(Looper.getMainLooper()) this.initView() this.makeBitmap() - + } handlerArguments() { @@ -133,7 +136,7 @@ export class WaitingView{ this.textView.setGravity(Gravity.CENTER) this.textView.setText(this.title) this.textView.setTextSize(0, (16 * this.density).toFloat()) - + if(this.title.length < 1){ // 没有文本需要展示 this.textView.setVisibility(View.GONE) @@ -166,8 +169,8 @@ export class WaitingView{ } return this.context!.dispatchTouchEvent(ev) } - - + + showWaiting() { if(this.context != null && !this.context!.isFinishing()){ let width = -2; @@ -179,7 +182,7 @@ export class WaitingView{ } let mpop = new PopupWindow(this.waitingView, width.toInt(), height.toInt(), this.mask) this.mpopWindow = mpop - mpop.showAtLocation((this.context?.findViewById(android.R.id.content))?.getChildAt(0), Gravity.CENTER, 0, 0) + mpop.showAtLocation(hostView, Gravity.CENTER, 0, 0) mpop.setOutsideTouchable(true) mpop.setOnDismissListener(new WaitingDismissListener()) mpop.setTouchInterceptor(new TouchInterceptorListener(this.mask)) @@ -315,4 +318,4 @@ class TouchInterceptorListener implements View.OnTouchListener { override onTouch(v: View, event: MotionEvent): boolean { return this.interceptor } -} \ No newline at end of file +} diff --git a/uni_modules/uni-prompt/utssdk/app-android/showToast.uts b/uni_modules/uni-prompt/utssdk/app-android/showToast.uts index f181f0b..ff4d69a 100644 --- a/uni_modules/uni-prompt/utssdk/app-android/showToast.uts +++ b/uni_modules/uni-prompt/utssdk/app-android/showToast.uts @@ -31,7 +31,7 @@ let toastType : string | null = null export function showToastImpl(style : ShowToastOptions) { makeToast(style, 'toast', 'showToast') - + } export function hideToastImpl() { @@ -108,33 +108,33 @@ function makeLoading(style : ShowLoadingOptions, type : string, errMsg : string) options["width"] = "140" options["height"] = "112" - - + + // #ifndef UNI-APP-X /** * uni-app */ - const alert = new WaitingView(UTSAndroid.getTopPageActivity(), options) + const alert = new WaitingView(UTSAndroid.getTopPageActivity(), options,UTSAndroid.getTopPageView()) toast = alert alert?.showWaiting(); - + UTSAndroid.onAppActivityDestroy(function(){ toast?.close() toast = null }) - + // #endif // #ifdef UNI-APP-X /** * uni-app x - * 需要特殊处理生命周期 + * 需要特殊处理生命周期 */ const pages = getCurrentPages(); if (pages.length > 0) { const page = pages[pages.length - 1].vm! const instance = page.$ if (page.$isReady) { - const alert = new WaitingView(UTSAndroid.getTopPageActivity(), options) + const alert = new WaitingView(UTSAndroid.getTopPageActivity(), options,UTSAndroid.getTopPageView()) toast = alert alert?.showWaiting(); } else { @@ -142,24 +142,24 @@ function makeLoading(style : ShowLoadingOptions, type : string, errMsg : string) onReady(() => { if(onReadyToast.containsKey(page)){ options = onReadyToast.get(page) as UTSJSONObject; - - const alert = new WaitingView(UTSAndroid.getTopPageActivity(), options) + + const alert = new WaitingView(UTSAndroid.getTopPageActivity(), options,UTSAndroid.getTopPageView()) toast = alert alert?.showWaiting(); - + onReadyToast.remove(page) } }, instance) } - + onUnload(() => { toast?.close() toast = null }, instance) } // #endif - - + + const res : ShowLoadingSuccess = { } style.success?.(res) @@ -178,7 +178,7 @@ function makeToast(style : ShowToastOptions, type : string, errMsg : string) { style.complete?.(res) } else { - + toastType = type if (["top", "center", "bottom"].indexOf(style.position) >= 0) { androidToast = Toast.makeText(UTSAndroid.getAppContext(), style.title, Toast.LENGTH_SHORT); @@ -200,7 +200,7 @@ function makeToast(style : ShowToastOptions, type : string, errMsg : string) { androidToast!.show() const res : ShowToastSuccess = { } - + style.success?.(res) style.complete?.(res) } else { @@ -240,8 +240,8 @@ function makeToast(style : ShowToastOptions, type : string, errMsg : string) { } } - - + + // #ifndef UNI-APP-X /** * uni-app @@ -249,17 +249,17 @@ function makeToast(style : ShowToastOptions, type : string, errMsg : string) { const alert = new WaitingView(UTSAndroid.getTopPageActivity(), options) toast = alert alert?.showWaiting(); - + UTSAndroid.onAppActivityDestroy(function(){ toast?.close() toast = null }) - + // #endif // #ifdef UNI-APP-X /** * uni-app x - * 需要特殊处理生命周期 + * 需要特殊处理生命周期 */ const pages = getCurrentPages(); if (pages.length > 0) { @@ -274,24 +274,24 @@ function makeToast(style : ShowToastOptions, type : string, errMsg : string) { onReady(() => { if(onReadyToast.containsKey(page)){ options = onReadyToast.get(page) as UTSJSONObject; - + const alert = new WaitingView(UTSAndroid.getTopPageActivity(), options) toast = alert alert?.showWaiting(); - + onReadyToast.remove(page) } }, instance) } - + onUnload(() => { toast?.close() toast = null }, instance) } // #endif - - + + let duration : number | null = style.duration if (duration == null || duration <= 0) { duration = 1500 @@ -301,10 +301,10 @@ function makeToast(style : ShowToastOptions, type : string, errMsg : string) { toast?.close() }, duration) } - + const res : ShowToastSuccess = { } - + style.success?.(res) style.complete?.(res) } -- GitLab