[web] Batch systemFontChange messages (flutter/engine#17885)

* Batch systemFontChange messages
* Update test for async
This commit is contained in:
Ferhat
2020-04-24 14:10:22 -07:00
committed by GitHub
parent 90c85fac98
commit 061c6b3f32
2 changed files with 21 additions and 5 deletions

View File

@@ -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,
(_) {},
);
});
}
}

View File

@@ -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"}');