Skip to content

Commit

Permalink
fix: fix renderObject detach error when fonts loading. (#596)
Browse files Browse the repository at this point in the history
  • Loading branch information
andycall authored May 30, 2024
2 parents 46297da + fe5fb62 commit d9aaff7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
7 changes: 7 additions & 0 deletions webf/lib/src/bridge/to_native.dart
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,13 @@ void flushUICommand(WebFViewController view, Pointer<NativeBindingObject> 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');
Expand Down
11 changes: 11 additions & 0 deletions webf/lib/src/launcher/controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -987,6 +987,8 @@ class WebFController {
_methodChannel = methodChannel;
WebFMethodChannel.setJSMethodCallCallback(this);

PaintingBinding.instance.systemFonts.addListener(_watchFontLoading);

_view = WebFViewController(
background: background,
enableDebug: enableDebug,
Expand Down Expand Up @@ -1058,6 +1060,14 @@ class WebFController {
_view.navigationDelegate = delegate;
}

bool isFontsLoading = false;
void _watchFontLoading() {
isFontsLoading = true;
SchedulerBinding.instance.scheduleFrameCallback((_) {
isFontsLoading = false;
});
}

Future<void> unload() async {
assert(!_view._disposed, 'WebF have already disposed');
// Should clear previous page cached ui commands
Expand Down Expand Up @@ -1461,6 +1471,7 @@ class WebFController {
bool get disposed => _disposed;
Future<void> dispose() async {
_module.dispose();
PaintingBinding.instance.systemFonts.removeListener(_watchFontLoading);
await _view.dispose();
_controllerMap[_view.contextId] = null;
_controllerMap.remove(_view.contextId);
Expand Down

0 comments on commit d9aaff7

Please sign in to comment.