mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-05-14 21:24:02 +08:00
@@ -99,13 +99,24 @@ class PageView<T extends HorizontalDragGestureRecognizer>
|
||||
List<Widget> children = const <Widget>[],
|
||||
this.dragStartBehavior = DragStartBehavior.start,
|
||||
this.allowImplicitScrolling = false,
|
||||
ScrollCacheExtent? scrollCacheExtent,
|
||||
this.restorationId,
|
||||
this.clipBehavior = Clip.hardEdge,
|
||||
this.hitTestBehavior = HitTestBehavior.opaque,
|
||||
this.scrollBehavior,
|
||||
this.padEnds = true,
|
||||
required this.horizontalDragGestureRecognizer,
|
||||
}) : childrenDelegate = SliverChildListDelegate(children);
|
||||
}) : assert(
|
||||
scrollCacheExtent == null ||
|
||||
(scrollCacheExtent.value > 0.0) == allowImplicitScrolling,
|
||||
'scrollCacheExtent and allowImplicitScrolling must be consistent: '
|
||||
'scrollCacheExtent must be greater than 0.0 when allowImplicitScrolling is true, '
|
||||
'and must be 0.0 when allowImplicitScrolling is false.',
|
||||
),
|
||||
scrollCacheExtent =
|
||||
scrollCacheExtent ??
|
||||
ScrollCacheExtent.viewport(allowImplicitScrolling ? 1.0 : 0.0),
|
||||
childrenDelegate = SliverChildListDelegate(children);
|
||||
|
||||
final GestureRecognizerFactoryConstructor<T> horizontalDragGestureRecognizer;
|
||||
|
||||
@@ -147,13 +158,24 @@ class PageView<T extends HorizontalDragGestureRecognizer>
|
||||
int? itemCount,
|
||||
this.dragStartBehavior = DragStartBehavior.start,
|
||||
this.allowImplicitScrolling = false,
|
||||
ScrollCacheExtent? scrollCacheExtent,
|
||||
this.restorationId,
|
||||
this.clipBehavior = Clip.hardEdge,
|
||||
this.hitTestBehavior = HitTestBehavior.opaque,
|
||||
this.scrollBehavior,
|
||||
this.padEnds = true,
|
||||
required this.horizontalDragGestureRecognizer,
|
||||
}) : childrenDelegate = SliverChildBuilderDelegate(
|
||||
}) : assert(
|
||||
scrollCacheExtent == null ||
|
||||
(scrollCacheExtent.value > 0.0) == allowImplicitScrolling,
|
||||
'scrollCacheExtent and allowImplicitScrolling must be consistent: '
|
||||
'scrollCacheExtent must be greater than 0.0 when allowImplicitScrolling is true, '
|
||||
'and must be 0.0 when allowImplicitScrolling is false.',
|
||||
),
|
||||
scrollCacheExtent =
|
||||
scrollCacheExtent ??
|
||||
ScrollCacheExtent.viewport(allowImplicitScrolling ? 1.0 : 0.0),
|
||||
childrenDelegate = SliverChildBuilderDelegate(
|
||||
itemBuilder,
|
||||
findChildIndexCallback: findChildIndexCallback,
|
||||
childCount: itemCount,
|
||||
@@ -170,7 +192,7 @@ class PageView<T extends HorizontalDragGestureRecognizer>
|
||||
/// {@end-tool}
|
||||
///
|
||||
/// {@macro flutter.widgets.PageView.allowImplicitScrolling}
|
||||
const PageView.custom({
|
||||
PageView.custom({
|
||||
super.key,
|
||||
this.scrollDirection = Axis.horizontal,
|
||||
this.reverse = false,
|
||||
@@ -181,14 +203,25 @@ class PageView<T extends HorizontalDragGestureRecognizer>
|
||||
required this.childrenDelegate,
|
||||
this.dragStartBehavior = DragStartBehavior.start,
|
||||
this.allowImplicitScrolling = false,
|
||||
ScrollCacheExtent? scrollCacheExtent,
|
||||
this.restorationId,
|
||||
this.clipBehavior = Clip.hardEdge,
|
||||
this.hitTestBehavior = HitTestBehavior.opaque,
|
||||
this.scrollBehavior,
|
||||
this.padEnds = true,
|
||||
required this.horizontalDragGestureRecognizer,
|
||||
});
|
||||
}) : assert(
|
||||
scrollCacheExtent == null ||
|
||||
(scrollCacheExtent.value > 0.0) == allowImplicitScrolling,
|
||||
'scrollCacheExtent and allowImplicitScrolling must be consistent: '
|
||||
'scrollCacheExtent must be greater than 0.0 when allowImplicitScrolling is true, '
|
||||
'and must be 0.0 when allowImplicitScrolling is false.',
|
||||
),
|
||||
scrollCacheExtent =
|
||||
scrollCacheExtent ??
|
||||
ScrollCacheExtent.viewport(allowImplicitScrolling ? 1.0 : 0.0);
|
||||
|
||||
/// {@template flutter.widgets.PageView.allowImplicitScrolling}
|
||||
/// Controls whether the widget's pages will respond to
|
||||
/// [RenderObject.showOnScreen], which will allow for implicit accessibility
|
||||
/// scrolling.
|
||||
@@ -200,8 +233,37 @@ class PageView<T extends HorizontalDragGestureRecognizer>
|
||||
/// With this flag set to true, when accessibility focus reaches the end of
|
||||
/// the current page and user attempts to move it to the next element, focus
|
||||
/// will traverse to the next page in the page view.
|
||||
/// {@endtemplate}
|
||||
final bool allowImplicitScrolling;
|
||||
|
||||
/// {@macro flutter.rendering.RenderViewportBase.scrollCacheExtent}
|
||||
///
|
||||
/// In [PageView], the default [scrollCacheExtent] uses
|
||||
/// [ScrollCacheExtent.viewport], where the value represents the number of
|
||||
/// viewport lengths to cache beyond the visible area.
|
||||
///
|
||||
/// When [PageController.viewportFraction] is 1.0 (the default), this is
|
||||
/// equivalent to the number of pages. For example,
|
||||
/// `ScrollCacheExtent.viewport(2.0)` caches 2 pages before and after the
|
||||
/// visible page.
|
||||
///
|
||||
/// When [PageController.viewportFraction] is less than 1.0, multiple pages
|
||||
/// may be visible in a single viewport, so `ScrollCacheExtent.viewport(1.0)`
|
||||
/// may cache more than one additional page in each direction.
|
||||
///
|
||||
/// [ScrollCacheExtent.pixels] can also be used to specify the cache extent
|
||||
/// in logical pixels instead of viewport sizes.
|
||||
///
|
||||
/// If [scrollCacheExtent] is specified, its value must be consistent with
|
||||
/// [allowImplicitScrolling]: the value must be greater than 0.0 when
|
||||
/// [allowImplicitScrolling] is true, and must be 0.0 when
|
||||
/// [allowImplicitScrolling] is false.
|
||||
///
|
||||
/// Defaults to `ScrollCacheExtent.viewport(1.0)` if
|
||||
/// [allowImplicitScrolling] is true, and `ScrollCacheExtent.viewport(0.0)` if
|
||||
/// [allowImplicitScrolling] is false.
|
||||
final ScrollCacheExtent scrollCacheExtent;
|
||||
|
||||
/// {@macro flutter.widgets.scrollable.restorationId}
|
||||
final String? restorationId;
|
||||
|
||||
@@ -392,11 +454,7 @@ class _PageViewState<T extends HorizontalDragGestureRecognizer>
|
||||
ScrollConfiguration.of(context).copyWith(scrollbars: false),
|
||||
viewportBuilder: (BuildContext context, ViewportOffset position) {
|
||||
return Viewport(
|
||||
// TODO(dnfield): we should provide a way to set cacheExtent
|
||||
// independent of implicit scrolling:
|
||||
// https://github.com/flutter/flutter/issues/45632
|
||||
cacheExtent: widget.allowImplicitScrolling ? 1.0 : 0.0,
|
||||
cacheExtentStyle: CacheExtentStyle.viewport,
|
||||
scrollCacheExtent: widget.scrollCacheExtent,
|
||||
axisDirection: axisDirection,
|
||||
offset: position,
|
||||
clipBehavior: widget.clipBehavior,
|
||||
@@ -405,6 +463,7 @@ class _PageViewState<T extends HorizontalDragGestureRecognizer>
|
||||
viewportFraction: _controller.viewportFraction,
|
||||
delegate: widget.childrenDelegate,
|
||||
padEnds: widget.padEnds,
|
||||
allowImplicitScrolling: widget.allowImplicitScrolling,
|
||||
),
|
||||
],
|
||||
);
|
||||
@@ -447,6 +506,15 @@ class _PageViewState<T extends HorizontalDragGestureRecognizer>
|
||||
value: widget.allowImplicitScrolling,
|
||||
ifTrue: 'allow implicit scrolling',
|
||||
),
|
||||
)
|
||||
..add(
|
||||
DiagnosticsProperty<ScrollCacheExtent>(
|
||||
'scrollCacheExtent',
|
||||
widget.scrollCacheExtent,
|
||||
defaultValue: ScrollCacheExtent.viewport(
|
||||
widget.allowImplicitScrolling ? 1.0 : 0.0,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -948,9 +948,6 @@ class ScrollableState<T extends HorizontalDragGestureRecognizer>
|
||||
void _receivedPointerSignal(PointerSignalEvent event) {
|
||||
if (event is PointerScrollEvent && _position != null) {
|
||||
if (_physics != null && !_physics!.shouldAcceptUserOffset(position)) {
|
||||
// The handler won't use the `event`, so allow the platform to trigger
|
||||
// any default native actions.
|
||||
event.respond(allowPlatformDefault: true);
|
||||
return;
|
||||
}
|
||||
final double delta = _pointerSignalEventDelta(event);
|
||||
@@ -965,9 +962,6 @@ class ScrollableState<T extends HorizontalDragGestureRecognizer>
|
||||
);
|
||||
return;
|
||||
}
|
||||
// The `event` won't result in a scroll, so allow the platform to trigger
|
||||
// any default native actions.
|
||||
event.respond(allowPlatformDefault: true);
|
||||
} else if (event is PointerScrollInertiaCancelEvent) {
|
||||
position.pointerScroll(0);
|
||||
// Don't use the pointer signal resolver, all hit-tested scrollables should stop.
|
||||
@@ -976,12 +970,16 @@ class ScrollableState<T extends HorizontalDragGestureRecognizer>
|
||||
|
||||
void _handlePointerScroll(PointerEvent event) {
|
||||
assert(event is PointerScrollEvent);
|
||||
final double delta = _pointerSignalEventDelta(event as PointerScrollEvent);
|
||||
final scrollEvent = event as PointerScrollEvent;
|
||||
final double delta = _pointerSignalEventDelta(scrollEvent);
|
||||
final double targetScrollOffset = _targetScrollOffsetForPointerScroll(
|
||||
delta,
|
||||
);
|
||||
if (delta != 0.0 && targetScrollOffset != position.pixels) {
|
||||
position.pointerScroll(delta);
|
||||
// Tell engine this scrollable handled the event.
|
||||
// This prevents parent page from scrolling when nested scrollables exist.
|
||||
scrollEvent.respond(allowPlatformDefault: false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user