From e6f845d36d6720646e24e8caefb69dac68b47d1b Mon Sep 17 00:00:00 2001 From: andycall Date: Fri, 11 Aug 2023 22:29:32 +0800 Subject: [PATCH] fix: support sliver recommendDeferredLoading --- webf/lib/src/dom/element.dart | 2 +- webf/lib/src/gesture/scroll_position.dart | 5 +++-- webf/lib/src/launcher/controller.dart | 4 +++- webf/lib/src/widget/webf.dart | 7 ++++++- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/webf/lib/src/dom/element.dart b/webf/lib/src/dom/element.dart index db48199240..8c08a821d3 100644 --- a/webf/lib/src/dom/element.dart +++ b/webf/lib/src/dom/element.dart @@ -1910,7 +1910,7 @@ abstract class Element extends ContainerNode with ElementBase, ElementEventMixin scrollable = (next?.parentElement!.renderer as RenderSliverListLayout).scrollable; } if(scrollable != null && scrollable.position != null) { - return scrollable.position!.recommendDeferredLoading(); + return scrollable.position!.recommendDeferredLoading(ownerDocument.controller.buildContext); } return false; } diff --git a/webf/lib/src/gesture/scroll_position.dart b/webf/lib/src/gesture/scroll_position.dart index db7b13ae3f..f256180ce8 100644 --- a/webf/lib/src/gesture/scroll_position.dart +++ b/webf/lib/src/gesture/scroll_position.dart @@ -14,7 +14,7 @@ import 'package:flutter/gestures.dart'; import 'package:flutter/physics.dart'; import 'package:flutter/rendering.dart'; import 'package:flutter/scheduler.dart'; -import 'package:flutter/widgets.dart' show ScrollPhysics, ScrollMetrics; +import 'package:flutter/widgets.dart' show BuildContext, ScrollMetrics, ScrollPhysics; import 'scroll_activity.dart'; import 'scroll_context.dart'; @@ -228,11 +228,12 @@ abstract class ScrollPosition extends ViewportOffset with ScrollMetrics { isScrollingNotifier.value = activity!.isScrolling; } - bool recommendDeferredLoading() { + bool recommendDeferredLoading(BuildContext buildContext) { assert(activity != null); return physics.recommendDeferredLoading( activity!.velocity + _impliedVelocity, copyWith(), + buildContext ); } diff --git a/webf/lib/src/launcher/controller.dart b/webf/lib/src/launcher/controller.dart index 67d1d85c3e..5a2720ccc0 100644 --- a/webf/lib/src/launcher/controller.dart +++ b/webf/lib/src/launcher/controller.dart @@ -17,7 +17,7 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/rendering.dart'; import 'package:flutter/scheduler.dart'; import 'package:flutter/widgets.dart' - show RouteInformation, WidgetsBinding, WidgetsBindingObserver, AnimationController; + show AnimationController, BuildContext, RouteInformation, WidgetsBinding, WidgetsBindingObserver; import 'package:webf/css.dart'; import 'package:webf/dom.dart'; import 'package:webf/gesture.dart'; @@ -769,6 +769,7 @@ class WebFController { final List? initialCookies; final ui.FlutterView ownerFlutterView; + final BuildContext buildContext; String? _name; String? get name => _name; @@ -810,6 +811,7 @@ class WebFController { this.uriParser, this.initialCookies, required this.ownerFlutterView, + required this.buildContext }) : _name = name, _entrypoint = entrypoint, _gestureListener = gestureListener { diff --git a/webf/lib/src/widget/webf.dart b/webf/lib/src/widget/webf.dart index e0ac45d15d..9984b06244 100644 --- a/webf/lib/src/widget/webf.dart +++ b/webf/lib/src/widget/webf.dart @@ -221,6 +221,7 @@ class WebFState extends State with RouteAware { onCustomElementAttached: onCustomElementWidgetAdd, onCustomElementDetached: onCustomElementWidgetRemove, children: customElementWidgets.toList(), + buildContext: context, ), ), ); @@ -296,10 +297,13 @@ class WebFRootRenderObjectWidget extends MultiChildRenderObjectWidget { required this.currentView, required this.onCustomElementAttached, required this.onCustomElementDetached, + required BuildContext buildContext }) : _webfWidget = widget, + _buildContext = buildContext, super(key: key, children: children); final WebF _webfWidget; + final BuildContext _buildContext; @override RenderObject createRenderObject(BuildContext context) { @@ -324,7 +328,8 @@ class WebFRootRenderObjectWidget extends MultiChildRenderObjectWidget { onCustomElementDetached: onCustomElementDetached, initialCookies: _webfWidget.initialCookies, uriParser: _webfWidget.uriParser, - ownerFlutterView: currentView); + ownerFlutterView: currentView, + buildContext: _buildContext); (context as _WebFRenderObjectElement).controller = controller;