From fe5fb621d78a7555d7c0731ef48c5654e07ea268 Mon Sep 17 00:00:00 2001 From: andycall Date: Mon, 8 Apr 2024 21:08:31 +0800 Subject: [PATCH] fix: fix renderObject detach error when fonts loading. --- webf/lib/src/bridge/to_native.dart | 7 +++++++ webf/lib/src/launcher/controller.dart | 11 +++++++++++ 2 files changed, 18 insertions(+) diff --git a/webf/lib/src/bridge/to_native.dart b/webf/lib/src/bridge/to_native.dart index f9ef25d428..bebe473ba0 100644 --- a/webf/lib/src/bridge/to_native.dart +++ b/webf/lib/src/bridge/to_native.dart @@ -788,6 +788,13 @@ void flushUICommand(WebFViewController view, Pointer selfPo assert(_allocatedPages.containsKey(view.contextId)); if (view.disposed) return; + if (view.rootController.isFontsLoading) { + SchedulerBinding.instance.scheduleFrameCallback((timeStamp) { + flushUICommand(view, selfPointer); + }); + return; + } + if (enableWebFProfileTracking) { WebFProfiler.instance.startTrackUICommand(); WebFProfiler.instance.startTrackUICommandStep('readNativeUICommandMemory'); diff --git a/webf/lib/src/launcher/controller.dart b/webf/lib/src/launcher/controller.dart index f91accccb7..d33f4faee8 100644 --- a/webf/lib/src/launcher/controller.dart +++ b/webf/lib/src/launcher/controller.dart @@ -981,6 +981,8 @@ class WebFController { _methodChannel = methodChannel; WebFMethodChannel.setJSMethodCallCallback(this); + PaintingBinding.instance.systemFonts.addListener(_watchFontLoading); + _view = WebFViewController( background: background, enableDebug: enableDebug, @@ -1052,6 +1054,14 @@ class WebFController { _view.navigationDelegate = delegate; } + bool isFontsLoading = false; + void _watchFontLoading() { + isFontsLoading = true; + SchedulerBinding.instance.scheduleFrameCallback((_) { + isFontsLoading = false; + }); + } + Future unload() async { assert(!_view._disposed, 'WebF have already disposed'); // Should clear previous page cached ui commands @@ -1455,6 +1465,7 @@ class WebFController { bool get disposed => _disposed; Future dispose() async { _module.dispose(); + PaintingBinding.instance.systemFonts.removeListener(_watchFontLoading); await _view.dispose(); _controllerMap[_view.contextId] = null; _controllerMap.remove(_view.contextId);