Skip to content

Commit

Permalink
fix: support sliver recommendDeferredLoading
Browse files Browse the repository at this point in the history
  • Loading branch information
andycall committed Aug 11, 2023
1 parent c72b037 commit e6f845d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion webf/lib/src/dom/element.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
5 changes: 3 additions & 2 deletions webf/lib/src/gesture/scroll_position.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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
);
}

Expand Down
4 changes: 3 additions & 1 deletion webf/lib/src/launcher/controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -769,6 +769,7 @@ class WebFController {
final List<Cookie>? initialCookies;

final ui.FlutterView ownerFlutterView;
final BuildContext buildContext;

String? _name;
String? get name => _name;
Expand Down Expand Up @@ -810,6 +811,7 @@ class WebFController {
this.uriParser,
this.initialCookies,
required this.ownerFlutterView,
required this.buildContext
}) : _name = name,
_entrypoint = entrypoint,
_gestureListener = gestureListener {
Expand Down
7 changes: 6 additions & 1 deletion webf/lib/src/widget/webf.dart
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ class WebFState extends State<WebF> with RouteAware {
onCustomElementAttached: onCustomElementWidgetAdd,
onCustomElementDetached: onCustomElementWidgetRemove,
children: customElementWidgets.toList(),
buildContext: context,
),
),
);
Expand Down Expand Up @@ -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) {
Expand All @@ -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;

Expand Down

0 comments on commit e6f845d

Please sign in to comment.