diff --git a/webf/lib/src/bridge/to_native.dart b/webf/lib/src/bridge/to_native.dart index f9ef25d42..bebe473ba 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 1f43e2814..62435c375 100644 --- a/webf/lib/src/launcher/controller.dart +++ b/webf/lib/src/launcher/controller.dart @@ -987,6 +987,8 @@ class WebFController { _methodChannel = methodChannel; WebFMethodChannel.setJSMethodCallCallback(this); + PaintingBinding.instance.systemFonts.addListener(_watchFontLoading); + _view = WebFViewController( background: background, enableDebug: enableDebug, @@ -1058,6 +1060,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 @@ -1461,6 +1471,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);