|
|
|
|
|
|
this.initialPage = initialPage; |
|
|
|
this.keepPage = keepPage; |
|
|
|
this.viewportFraction = viewportFraction; |
|
|
|
D.assert(viewportFraction > 0.0); |
|
|
|
D.assert(viewportFraction > 0.0f); |
|
|
|
} |
|
|
|
|
|
|
|
public readonly int initialPage; |
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public Future animateToPage(int page, TimeSpan duration, Curve curve) { |
|
|
|
public Future animateToPage( |
|
|
|
int page, |
|
|
|
TimeSpan? duration = null, |
|
|
|
Curve curve = null) { |
|
|
|
duration, |
|
|
|
duration ?? new TimeSpan(0,0,0,0,0), |
|
|
|
curve |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
position.jumpTo(position.getPixelsFromPage(page)); |
|
|
|
} |
|
|
|
|
|
|
|
public Future nextPage(TimeSpan duration, Curve curve) { |
|
|
|
public Future nextPage( |
|
|
|
TimeSpan? duration = null, Curve curve = null) { |
|
|
|
public Future previousPage(TimeSpan duration, Curve curve) { |
|
|
|
public Future previousPage(TimeSpan? duration = null, Curve curve = null) { |
|
|
|
public override ScrollPosition createScrollPosition(ScrollPhysics physics, ScrollContext context, |
|
|
|
public override ScrollPosition createScrollPosition( |
|
|
|
ScrollPhysics physics, |
|
|
|
ScrollContext context, |
|
|
|
ScrollPosition oldPosition) { |
|
|
|
return new _PagePosition( |
|
|
|
physics: physics, |
|
|
|
|
|
|
public interface IPageMetrics : ScrollMetrics { |
|
|
|
float page { get; } |
|
|
|
float viewportFraction { get; } |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
public class PageMetrics : FixedScrollMetrics, IPageMetrics { |
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
public readonly float _viewportFraction; |
|
|
|
|
|
|
|
public PageMetrics copyWith( |
|
|
|
float? minScrollExtent = null, |
|
|
|
float? maxScrollExtent = null, |
|
|
|
float? pixels = null, |
|
|
|
float? viewportDimension = null, |
|
|
|
AxisDirection? axisDirection = null, |
|
|
|
float? viewportFraction = null |
|
|
|
) { |
|
|
|
return new PageMetrics( |
|
|
|
minScrollExtent: minScrollExtent ?? this.minScrollExtent, |
|
|
|
maxScrollExtent: maxScrollExtent ?? this.maxScrollExtent, |
|
|
|
pixels: pixels ?? this.pixels, |
|
|
|
viewportDimension: viewportDimension ?? this.viewportDimension, |
|
|
|
axisDirection: axisDirection ?? this.axisDirection, |
|
|
|
viewportFraction: viewportFraction ?? this.viewportFraction |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
public float page { |
|
|
|
get { |
|
|
|
|
|
|
bool keepPage = true, |
|
|
|
float viewportFraction = 1.0f, |
|
|
|
ScrollPosition oldPosition = null |
|
|
|
) : |
|
|
|
base( |
|
|
|
) : base( |
|
|
|
physics: physics, |
|
|
|
context: context, |
|
|
|
initialPixels: null, |
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
public float getPageFromPixels(float pixels, float viewportDimension) { |
|
|
|
return (Mathf.Max(0.0f, pixels) / Mathf.Max(1.0f, viewportDimension * viewportFraction)); |
|
|
|
float actual = Mathf.Max(0.0f, pixels - _initialPageOffset) / Mathf.Max(1.0f, viewportDimension * viewportFraction); |
|
|
|
float round = (int)actual * 1.0f; |
|
|
|
if ((actual - round).abs() < 1e-10) { |
|
|
|
return round; |
|
|
|
} |
|
|
|
return actual; |
|
|
|
} |
|
|
|
|
|
|
|
public float getPixelsFromPage(float page) { |
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
public override bool applyViewportDimension(float viewportDimension) { |
|
|
|
float oldViewportDimensions = 0.0f; |
|
|
|
if (haveDimensions) { |
|
|
|
oldViewportDimensions = this.viewportDimension; |
|
|
|
} |
|
|
|
|
|
|
|
float oldViewportDimensions = this.viewportDimension; |
|
|
|
float? oldPixels = null; |
|
|
|
if (havePixels) { |
|
|
|
oldPixels = pixels; |
|
|
|
} |
|
|
|
|
|
|
|
float page = (oldPixels == null || oldViewportDimensions == 0.0f) |
|
|
|
? _pageToUseOnStartup |
|
|
|
: getPageFromPixels(oldPixels.Value, oldViewportDimensions); |
|
|
|
float oldPixels = pixels; |
|
|
|
float page = (oldPixels == null || oldViewportDimensions == 0.0) ? _pageToUseOnStartup : getPageFromPixels(oldPixels, oldViewportDimensions); |
|
|
|
|
|
|
|
|
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
return base.applyContentDimensions( |
|
|
|
return base.applyContentDimensions( |
|
|
|
public PageMetrics copyWith( |
|
|
|
float? minScrollExtent = null, |
|
|
|
float? maxScrollExtent = null, |
|
|
|
float? pixels = null, |
|
|
|
float? viewportDimension = null, |
|
|
|
AxisDirection? axisDirection = null, |
|
|
|
float? viewportFraction = null |
|
|
|
) { |
|
|
|
return new PageMetrics( |
|
|
|
minScrollExtent: minScrollExtent ?? this.minScrollExtent, |
|
|
|
maxScrollExtent: maxScrollExtent ?? this.maxScrollExtent, |
|
|
|
pixels: pixels ?? this.pixels, |
|
|
|
viewportDimension: viewportDimension ?? this.viewportDimension, |
|
|
|
axisDirection: axisDirection ?? this.axisDirection, |
|
|
|
viewportFraction: viewportFraction ?? this.viewportFraction |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public class _ForceImplicitScrollPhysics : ScrollPhysics { |
|
|
|
|
|
|
) : base(parent: parent) { |
|
|
|
D.assert(allowImplicitScrolling != null); |
|
|
|
this.allowImplicitScrolling = allowImplicitScrolling; |
|
|
|
} |
|
|
|
|
|
|
|
public override ScrollPhysics applyTo(ScrollPhysics ancestor) { |
|
|
|
|
|
|
ValueChanged<int> onPageChanged = null, |
|
|
|
List<Widget> children = null, |
|
|
|
DragStartBehavior dragStartBehavior = DragStartBehavior.start, |
|
|
|
IndexedWidgetBuilder itemBuilder = null, |
|
|
|
SliverChildDelegate childDelegate = null, |
|
|
|
int itemCount = 0, |
|
|
|
bool allowImplicitScrolling = false |
|
|
|
) : base(key: key) { |
|
|
|
this.scrollDirection = scrollDirection; |
|
|
|
|
|
|
this.dragStartBehavior = dragStartBehavior; |
|
|
|
this.controller = controller ?? PageViewUtils._defaultPageController; |
|
|
|
this.allowImplicitScrolling = allowImplicitScrolling; |
|
|
|
if (itemBuilder != null) { |
|
|
|
childrenDelegate = new SliverChildBuilderDelegate(itemBuilder, childCount: itemCount); |
|
|
|
} |
|
|
|
else if (childDelegate != null) { |
|
|
|
childrenDelegate = childDelegate; |
|
|
|
} |
|
|
|
else { |
|
|
|
childrenDelegate = new SliverChildListDelegate(children ?? new List<Widget>()); |
|
|
|
} |
|
|
|
childrenDelegate = new SliverChildListDelegate(children); |
|
|
|
IndexedWidgetBuilder itemBuilder, |
|
|
|
Key key = null, |
|
|
|
Axis scrollDirection = Axis.horizontal, |
|
|
|
bool reverse = false, |
|
|
|
|
|
|
ValueChanged<int> onPageChanged = null, |
|
|
|
IndexedWidgetBuilder itemBuilder = null, |
|
|
|
bool allowImplicitScrolling = false, |
|
|
|
DragStartBehavior dragStartBehavior = DragStartBehavior.start |
|
|
|
DragStartBehavior dragStartBehavior = DragStartBehavior.start, |
|
|
|
bool allowImplicitScrolling = false |
|
|
|
return new PageView( |
|
|
|
itemBuilder: itemBuilder, |
|
|
|
var page = new PageView( |
|
|
|
controller: controller, |
|
|
|
controller: controller ?? PageViewUtils._defaultPageController, |
|
|
|
itemCount: itemCount, |
|
|
|
allowImplicitScrolling: allowImplicitScrolling, |
|
|
|
allowImplicitScrolling: allowImplicitScrolling, |
|
|
|
page.childrenDelegate = new SliverChildBuilderDelegate(itemBuilder, childCount: itemCount); |
|
|
|
return page; |
|
|
|
} |
|
|
|
|
|
|
|
public static PageView custom( |
|
|
|
Key key = null, |
|
|
|
Axis scrollDirection = Axis.horizontal, |
|
|
|
bool reverse = false, |
|
|
|
PageController controller = null, |
|
|
|
ScrollPhysics physics = null, |
|
|
|
bool pageSnapping = true, |
|
|
|
ValueChanged<int> onPageChanged = null, |
|
|
|
SliverChildDelegate childrenDelegate = null, |
|
|
|
DragStartBehavior dragStartBehavior = DragStartBehavior.start, |
|
|
|
bool allowImplicitScrolling = false |
|
|
|
) { |
|
|
|
D.assert(childrenDelegate != null); |
|
|
|
var page = new PageView( |
|
|
|
key: key, |
|
|
|
scrollDirection: scrollDirection, |
|
|
|
reverse: reverse, |
|
|
|
controller: controller ?? PageViewUtils._defaultPageController, |
|
|
|
physics: physics, |
|
|
|
pageSnapping: pageSnapping, |
|
|
|
onPageChanged: onPageChanged, |
|
|
|
allowImplicitScrolling: allowImplicitScrolling, |
|
|
|
dragStartBehavior: dragStartBehavior |
|
|
|
); |
|
|
|
page.childrenDelegate = childrenDelegate; |
|
|
|
return page; |
|
|
|
} |
|
|
|
|
|
|
|
// TODO: PageView.custom
|
|
|
|
|
|
|
|
|
|
|
public readonly ValueChanged<int> onPageChanged; |
|
|
|
|
|
|
|
public readonly SliverChildDelegate childrenDelegate; |
|
|
|
public SliverChildDelegate childrenDelegate; |
|
|
|
|
|
|
|
public readonly DragStartBehavior dragStartBehavior; |
|
|
|
|
|
|
|