From c8c1a33e37d498087cb0cfbc7ff1cfadf167c1cd Mon Sep 17 00:00:00 2001 From: lxm <1274844347@qq.com> Date: Tue, 3 Mar 2026 16:44:14 +0800 Subject: [PATCH] =?UTF-8?q?fix(share):=20=E4=BF=AE=E5=A4=8D=20iOS=20?= =?UTF-8?q?=E6=80=9D=E7=BB=B4=E5=AF=BC=E5=9B=BE=E6=88=AA=E5=9B=BE=E5=9C=A8?= =?UTF-8?q?=E9=9D=9E=E5=8F=AF=E8=A7=81=20tab=20=E6=97=A0=E6=B3=95=E6=89=A7?= =?UTF-8?q?=E8=A1=8C=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 针对 iOS WKWebView 通信在不可见 tab 会暂停的问题,切换到思维导图 tab 以确保 WebView 可见 - 优化截图操作,等待 WebView 加载完成后执行 JavaScript 截图 - 增加对 WebView 加载状态的判断和处理 - 保持其他平台和可见 tab 直接执行截图逻辑 - 统一了音频文件不存在时的错误提示显示逻辑 --- .../views/bottomSheet/share_bottom_sheet.dart | 50 ++++++++++++++----- 1 file changed, 38 insertions(+), 12 deletions(-) diff --git a/lib/modules/meeting/views/bottomSheet/share_bottom_sheet.dart b/lib/modules/meeting/views/bottomSheet/share_bottom_sheet.dart index 853c90106..c2936f43a 100644 --- a/lib/modules/meeting/views/bottomSheet/share_bottom_sheet.dart +++ b/lib/modules/meeting/views/bottomSheet/share_bottom_sheet.dart @@ -104,21 +104,48 @@ class _ShareBottomSheetState extends State { /// 处理思维导图操作(保存/分享) /// [actionType] 操作类型,使用 [_MindMapActionType] 常量 + /// + /// iOS 特殊处理: + /// WKWebView 在 tab 不可见时,JavaScriptChannel(ImageChannel)通信会被暂停, + /// 导致 JS 的 postMessage 回调无法触发。 + /// 修复方案:操作前先切换到思维导图 tab(index=3),确保 WebView 可见后再执行截图。 void _handleMindMapAction(int actionType) { Get.back(); final mindMapController = Get.find(); + final meetingController = Get.find(); mindMapController.imageType = actionType; - if (mindMapController.isWebViewReady) { - mindMapController.webViewController.runJavaScript('captureImage()'); + + // 思维导图 tab 的索引(TabBarView 第 4 个子项,index=3) + const int mindMapTabIndex = 3; + final bool isOnMindMapTab = + meetingController.tabController.index == mindMapTabIndex; + + void runCapture() { + if (mindMapController.isWebViewReady) { + mindMapController.webViewController.runJavaScript('captureImage()'); + } else { + // WebView 尚未加载完成,等待 onPageFinished 后执行 + mindMapController.webViewController.setNavigationDelegate( + NavigationDelegate( + onPageFinished: (String url) { + mindMapController.isWebViewReady = true; + mindMapController.webViewController + .runJavaScript('captureImage()'); + }, + ), + ); + } + } + + if (Platform.isIOS && !isOnMindMapTab) { + // iOS 上若当前不在思维导图 tab,先切换过去,确保 WKWebView 可见后再执行截图 + meetingController.tabController.animateTo(mindMapTabIndex); + // 等待下一帧渲染完成后执行截图,避免 WebView 尚未完成布局 + WidgetsBinding.instance.addPostFrameCallback((_) { + runCapture(); + }); } else { - mindMapController.webViewController.setNavigationDelegate( - NavigationDelegate( - onPageFinished: (String url) { - mindMapController.isWebViewReady = true; - mindMapController.webViewController.runJavaScript('captureImage()'); - }, - ), - ); + runCapture(); } } @@ -602,8 +629,7 @@ class _ShareBottomSheetState extends State { // 检查文件路径是否为空或文件是否存在 if (filepath.isEmpty || !File(filepath).existsSync()) { Logger.error('分享文件失败: 文件不存在 (path: $filepath)'); - EasyLoading.showToast( - 'audioFileNotFound'.tr); // 对应中文:音频文件不存在 + EasyLoading.showToast('audioFileNotFound'.tr); // 对应中文:音频文件不存在 return; } final result = await SharePlus.instance.share(ShareParams(