From 5f23085b070c8eb9ef540479f1f14f820c503033 Mon Sep 17 00:00:00 2001 From: anchi Date: Wed, 20 Nov 2024 11:45:06 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=92=E5=B8=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: anchi --- packages/flutter/lib/src/scheduler/binding.dart | 5 +++++ packages/flutter/lib/src/services/system_channels.dart | 5 +++++ packages/flutter/lib/src/widgets/scroll_position.dart | 1 + packages/flutter/lib/src/widgets/scrollable.dart | 2 ++ 4 files changed, 13 insertions(+) diff --git a/packages/flutter/lib/src/scheduler/binding.dart b/packages/flutter/lib/src/scheduler/binding.dart index 8820c7cf04..3a2dc87e87 100644 --- a/packages/flutter/lib/src/scheduler/binding.dart +++ b/packages/flutter/lib/src/scheduler/binding.dart @@ -9,6 +9,7 @@ import 'dart:ui' show AppLifecycleState, DartPerformanceMode, FramePhase, FrameT import 'package:collection/collection.dart' show HeapPriorityQueue, PriorityQueue; import 'package:flutter/foundation.dart'; +import 'package:flutter/services.dart'; import 'debug.dart'; import 'priority.dart'; @@ -1310,6 +1311,10 @@ mixin SchedulerBinding on BindingBase { return true; }()); } + + void setDVsyncSwitch(bool isEnable) { + SystemChannels.nativeVsync.send({"isEnable": isEnable}); + } } /// The default [SchedulingStrategy] for [SchedulerBinding.schedulingStrategy]. diff --git a/packages/flutter/lib/src/services/system_channels.dart b/packages/flutter/lib/src/services/system_channels.dart index c69c7e5e77..13531d3fb1 100644 --- a/packages/flutter/lib/src/services/system_channels.dart +++ b/packages/flutter/lib/src/services/system_channels.dart @@ -465,4 +465,9 @@ class SystemChannels { /// /// * [DefaultPlatformMenuDelegate], which uses this channel. static const MethodChannel menu = OptionalMethodChannel('flutter/menu'); + + static const BasicMessageChannel nativeVsync = BasicMessageChannel( + 'flutter/nativevsync', + StandardMessageCodec(), + ); } diff --git a/packages/flutter/lib/src/widgets/scroll_position.dart b/packages/flutter/lib/src/widgets/scroll_position.dart index db363517c3..e9f8de32d2 100644 --- a/packages/flutter/lib/src/widgets/scroll_position.dart +++ b/packages/flutter/lib/src/widgets/scroll_position.dart @@ -916,6 +916,7 @@ abstract class ScrollPosition extends ViewportOffset with ScrollMetrics { /// /// This also saves the scroll offset using [saveScrollOffset]. void didEndScroll() { + SchedulerBinding.instance.setDVsyncSwitch(false); activity!.dispatchScrollEndNotification(copyWith(), context.notificationContext!); saveOffset(); if (keepScrollOffset) { diff --git a/packages/flutter/lib/src/widgets/scrollable.dart b/packages/flutter/lib/src/widgets/scrollable.dart index 158228c23a..1415fc363e 100644 --- a/packages/flutter/lib/src/widgets/scrollable.dart +++ b/packages/flutter/lib/src/widgets/scrollable.dart @@ -709,6 +709,7 @@ class ScrollableState extends State with TickerProviderStateMixin, R // triggers a new activity to begin. assert(_drag == null); _drag = position.drag(details, _disposeDrag); + SchedulerBinding.instance.setDVsyncSwitch(false); assert(_drag != null); assert(_hold == null); } @@ -723,6 +724,7 @@ class ScrollableState extends State with TickerProviderStateMixin, R // _drag might be null if the drag activity ended and called _disposeDrag. assert(_hold == null || _drag == null); _drag?.end(details); + SchedulerBinding.instance.setDVsyncSwitch(true); assert(_drag == null); } -- Gitee