未验证 提交 cade0e90 编写于 作者: F Ferhat 提交者: GitHub

[web] Batch systemFontChange messages (#17885)

* Batch systemFontChange messages
* Update test for async
上级 4bcfae82
......@@ -461,11 +461,23 @@ void applyWebkitClipFix(html.Element containerElement) {
final ByteData _fontChangeMessage = JSONMessageCodec().encodeMessage(<String, dynamic>{'type': 'fontsChange'});
// Font load callbacks will typically arrive in sequence, we want to prevent
// sendFontChangeMessage of causing multiple synchronous rebuilds.
// This flag ensures we properly schedule a single call to framework.
bool _fontChangeScheduled = false;
FutureOr<void> sendFontChangeMessage() async {
if (window._onPlatformMessage != null)
window.invokeOnPlatformMessage(
'flutter/system',
_fontChangeMessage,
(_) {},
);
if (!_fontChangeScheduled) {
_fontChangeScheduled = true;
// Batch updates into next animationframe.
html.window.requestAnimationFrame((num _) {
_fontChangeScheduled = false;
window.invokeOnPlatformMessage(
'flutter/system',
_fontChangeMessage,
(_) {},
);
});
}
}
......@@ -3,6 +3,7 @@
// found in the LICENSE file.
// @dart = 2.6
import 'dart:async';
import 'dart:convert';
import 'dart:html' as html;
import 'dart:typed_data';
......@@ -85,6 +86,9 @@ Future<void> main() async {
responseType: 'arraybuffer');
await ui.loadFontFromList(Uint8List.view(response.response),
fontFamily: 'Blehm');
final Completer<void> completer = Completer();
html.window.requestAnimationFrame( (_) { completer.complete(true); } );
await(completer.future);
window.onPlatformMessage = oldHandler;
expect(actualName, 'flutter/system');
expect(message, '{"type":"fontsChange"}');
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册