Remove Scrollable1 (#8225)

All the clients have migrated to Scrollable2.
This commit is contained in:
Adam Barth
2017-02-16 16:41:24 -08:00
committed by GitHub
parent 9ec5330f32
commit 90574b0478
25 changed files with 94 additions and 2396 deletions

View File

@@ -321,7 +321,7 @@ class CardCollectionState extends State<CardCollection> {
Widget background = new Positioned.fill(
child: new Container(
margin: const EdgeInsets.all(4.0),
child: new Viewport(
child: new SingleChildScrollView(
child: new Container(
height: cardModel.height,
decoration: new BoxDecoration(backgroundColor: theme.primaryColor),

View File

@@ -53,7 +53,6 @@ export 'src/rendering/stack.dart';
export 'src/rendering/table.dart';
export 'src/rendering/tweens.dart';
export 'src/rendering/view.dart';
export 'src/rendering/viewport.dart';
export 'src/rendering/viewport_offset.dart';
export 'package:flutter/foundation.dart' show

View File

@@ -167,32 +167,6 @@ class MaterialApp extends StatefulWidget {
_MaterialAppState createState() => new _MaterialAppState();
}
class _ScrollLikeCupertinoDelegate extends ScrollConfigurationDelegate {
const _ScrollLikeCupertinoDelegate();
@override
TargetPlatform get platform => TargetPlatform.iOS;
@override
ExtentScrollBehavior createScrollBehavior() => new OverscrollWhenScrollableBehavior(platform: TargetPlatform.iOS);
@override
bool updateShouldNotify(ScrollConfigurationDelegate old) => false;
}
class _ScrollLikeMountainViewDelegate extends ScrollConfigurationDelegate {
const _ScrollLikeMountainViewDelegate(this.platform);
@override
final TargetPlatform platform;
@override
ExtentScrollBehavior createScrollBehavior() => new OverscrollWhenScrollableBehavior(platform: TargetPlatform.android);
@override
bool updateShouldNotify(ScrollConfigurationDelegate old) => false;
}
class _MaterialScrollBehavior extends ScrollBehavior2 {
@override
TargetPlatform getPlatform(BuildContext context) {
@@ -233,18 +207,6 @@ class _MaterialAppState extends State<MaterialApp> {
return null;
}
ScrollConfigurationDelegate _getScrollDelegate(TargetPlatform platform) {
switch (platform) {
case TargetPlatform.android:
return const _ScrollLikeMountainViewDelegate(TargetPlatform.android);
case TargetPlatform.fuchsia:
return const _ScrollLikeMountainViewDelegate(TargetPlatform.fuchsia);
case TargetPlatform.iOS:
return const _ScrollLikeCupertinoDelegate();
}
return null;
}
@override
Widget build(BuildContext context) {
ThemeData theme = config.theme ?? new ThemeData.fallback();
@@ -283,11 +245,6 @@ class _MaterialAppState extends State<MaterialApp> {
return true;
});
result = new ScrollConfiguration(
delegate: _getScrollDelegate(theme.platform),
child: result
);
return new ScrollConfiguration2(
behavior: new _MaterialScrollBehavior(),
child: result

View File

@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';
import 'package:meta/meta.dart';

View File

@@ -1,338 +0,0 @@
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:ui' as ui show window;
import 'package:vector_math/vector_math_64.dart';
import 'box.dart';
import 'object.dart';
/// The end of the viewport from which the paint offset is computed.
enum ViewportAnchor {
/// The start (e.g., top or left, depending on the axis) of the first item
/// should be aligned with the start (e.g., top or left, depending on the
/// axis) of the viewport.
start,
/// The end (e.g., bottom or right, depending on the axis) of the last item
/// should be aligned with the end (e.g., bottom or right, depending on the
/// axis) of the viewport.
end,
}
/// The interior and exterior dimensions of a viewport.
class ViewportDimensions {
/// Creates dimensions for a viewport.
///
/// By default, the content and container sizes are zero.
const ViewportDimensions({
this.contentSize: Size.zero,
this.containerSize: Size.zero
});
/// A viewport that has zero size, both inside and outside.
static const ViewportDimensions zero = const ViewportDimensions();
/// The size of the content inside the viewport.
final Size contentSize;
/// The size of the outside of the viewport.
final Size containerSize;
bool get _debugHasAtLeastOneCommonDimension {
return contentSize.width == containerSize.width
|| contentSize.height == containerSize.height;
}
/// Returns the offset at which to paint the content, accounting for the given
/// anchor and the dimensions of the viewport.
Offset getAbsolutePaintOffset({ Offset paintOffset, ViewportAnchor anchor }) {
assert(_debugHasAtLeastOneCommonDimension);
switch (anchor) {
case ViewportAnchor.start:
return paintOffset;
case ViewportAnchor.end:
return paintOffset + (containerSize - contentSize);
}
assert(anchor != null);
return null;
}
@override
bool operator ==(dynamic other) {
if (identical(this, other))
return true;
if (other is! ViewportDimensions)
return false;
final ViewportDimensions typedOther = other;
return contentSize == typedOther.contentSize &&
containerSize == typedOther.containerSize;
}
@override
int get hashCode => hashValues(contentSize, containerSize);
@override
String toString() => 'ViewportDimensions(container: $containerSize, content: $contentSize)';
}
/// A base class for render objects that are bigger on the inside.
///
/// This class holds the common fields for viewport render objects but does not
/// have a child model. See [RenderViewport] for a viewport with a single child
/// and [RenderVirtualViewport] for a viewport with multiple children.
class RenderViewportBase extends RenderBox {
/// Initializes fields for subclasses.
///
/// The [paintOffset] and [mainAxis] arguments must not be null.
///
/// This constructor uses positional arguments rather than named arguments to
/// work around limitations of mixins.
RenderViewportBase(
Offset paintOffset,
Axis mainAxis,
ViewportAnchor anchor
) : _paintOffset = paintOffset,
_mainAxis = mainAxis,
_anchor = anchor {
assert(paintOffset != null);
assert(mainAxis != null);
assert(_offsetIsSane(_paintOffset, mainAxis));
}
bool _offsetIsSane(Offset offset, Axis direction) {
switch (direction) {
case Axis.horizontal:
return offset.dy == 0.0;
case Axis.vertical:
return offset.dx == 0.0;
}
assert(direction != null);
return null;
}
/// The offset at which to paint the child.
///
/// The offset can be non-zero only in the [mainAxis].
Offset get paintOffset => _paintOffset;
Offset _paintOffset;
set paintOffset(Offset value) {
assert(value != null);
if (value == _paintOffset)
return;
assert(_offsetIsSane(value, mainAxis));
_paintOffset = value;
markNeedsPaint();
markNeedsSemanticsUpdate();
}
/// The direction in which the child is permitted to be larger than the viewport.
///
/// The child is given layout constraints that are fully unconstrained along
/// the main axis (e.g., the child can be as tall as it wants if the main axis
/// is vertical).
Axis get mainAxis => _mainAxis;
Axis _mainAxis;
set mainAxis(Axis value) {
assert(value != null);
if (value == _mainAxis)
return;
assert(_offsetIsSane(_paintOffset, value));
_mainAxis = value;
markNeedsLayout();
}
/// The end of the viewport from which the paint offset is computed.
///
/// See [ViewportAnchor] for more detail.
ViewportAnchor get anchor => _anchor;
ViewportAnchor _anchor;
set anchor(ViewportAnchor value) {
assert(value != null);
if (value == _anchor)
return;
_anchor = value;
markNeedsPaint();
markNeedsSemanticsUpdate();
}
/// The interior and exterior extent of the viewport.
ViewportDimensions get dimensions => _dimensions;
ViewportDimensions _dimensions = ViewportDimensions.zero;
set dimensions(ViewportDimensions value) {
assert(debugDoingThisLayout);
_dimensions = value;
}
Offset get _effectivePaintOffset {
final double devicePixelRatio = ui.window.devicePixelRatio;
int dxInDevicePixels = (_paintOffset.dx * devicePixelRatio).round();
int dyInDevicePixels = (_paintOffset.dy * devicePixelRatio).round();
return _dimensions.getAbsolutePaintOffset(
paintOffset: new Offset(dxInDevicePixels / devicePixelRatio, dyInDevicePixels / devicePixelRatio),
anchor: _anchor
);
}
@override
void applyPaintTransform(RenderBox child, Matrix4 transform) {
final Offset effectivePaintOffset = _effectivePaintOffset;
super.applyPaintTransform(child, transform..translate(effectivePaintOffset.dx, effectivePaintOffset.dy));
}
@override
void debugFillDescription(List<String> description) {
super.debugFillDescription(description);
description.add('paintOffset: $paintOffset');
description.add('mainAxis: $mainAxis');
description.add('anchor: $anchor');
}
}
/// Signature for notifications about [RenderViewport] dimensions changing.
///
/// Used by [RenderViewport.onPaintOffsetUpdateNeeded].
typedef Offset ViewportDimensionsChangeCallback(ViewportDimensions dimensions);
/// A render object that's bigger on the inside.
///
/// The child of a viewport can layout to a larger size along the viewport's
/// [mainAxis] than the viewport itself. If that happens, only a portion of the
/// child will be visible through the viewport. The portion of the child that is
/// visible can be controlled with the [paintOffset].
///
/// See also:
///
/// * [RenderVirtualViewport] (which works with more than one child)
class RenderViewport extends RenderViewportBase with RenderObjectWithChildMixin<RenderBox> {
/// Creates a render object that's bigger on the inside.
///
/// The [paintOffset] and [mainAxis] arguments must not be null.
RenderViewport({
RenderBox child,
Offset paintOffset: Offset.zero,
Axis mainAxis: Axis.vertical,
ViewportAnchor anchor: ViewportAnchor.start,
this.onPaintOffsetUpdateNeeded
}) : super(paintOffset, mainAxis, anchor) {
this.child = child;
}
/// Called during [layout] to report the dimensions of the viewport
/// and its child.
///
/// The return value of this function is used as the new [paintOffset] and
/// must not be null.
ViewportDimensionsChangeCallback onPaintOffsetUpdateNeeded;
BoxConstraints _getInnerConstraints(BoxConstraints constraints) {
BoxConstraints innerConstraints;
switch (mainAxis) {
case Axis.horizontal:
innerConstraints = constraints.heightConstraints();
break;
case Axis.vertical:
innerConstraints = constraints.widthConstraints();
break;
}
return innerConstraints;
}
@override
double computeMinIntrinsicWidth(double height) {
if (child != null)
return child.getMinIntrinsicWidth(height);
return 0.0;
}
@override
double computeMaxIntrinsicWidth(double height) {
if (child != null)
return child.getMaxIntrinsicWidth(height);
return 0.0;
}
@override
double computeMinIntrinsicHeight(double width) {
if (child != null)
return child.getMinIntrinsicHeight(width);
return 0.0;
}
@override
double computeMaxIntrinsicHeight(double width) {
if (child != null)
return child.getMaxIntrinsicHeight(width);
return 0.0;
}
// We don't override computeDistanceToActualBaseline(), because we
// want the default behavior (returning null). Otherwise, as you
// scroll the RenderViewport, it would shift in its parent if the
// parent was baseline-aligned, which makes no sense.
@override
void performLayout() {
final ViewportDimensions oldDimensions = dimensions;
if (child != null) {
child.layout(_getInnerConstraints(constraints), parentUsesSize: true);
size = constraints.constrain(child.size);
final BoxParentData childParentData = child.parentData;
childParentData.offset = Offset.zero;
dimensions = new ViewportDimensions(containerSize: size, contentSize: child.size);
} else {
performResize();
dimensions = new ViewportDimensions(containerSize: size);
}
if (onPaintOffsetUpdateNeeded != null && dimensions != oldDimensions)
paintOffset = onPaintOffsetUpdateNeeded(dimensions);
assert(paintOffset != null);
}
bool _shouldClipAtPaintOffset(Offset paintOffset) {
assert(child != null);
return paintOffset < Offset.zero || !(Offset.zero & size).contains((paintOffset & child.size).bottomRight);
}
@override
void paint(PaintingContext context, Offset offset) {
if (child != null) {
final Offset effectivePaintOffset = _effectivePaintOffset;
void paintContents(PaintingContext context, Offset offset) {
context.paintChild(child, offset + effectivePaintOffset);
}
if (_shouldClipAtPaintOffset(effectivePaintOffset)) {
context.pushClipRect(needsCompositing, offset, Point.origin & size, paintContents);
} else {
paintContents(context, offset);
}
}
}
@override
Rect describeApproximatePaintClip(RenderObject child) {
if (child != null && _shouldClipAtPaintOffset(_effectivePaintOffset))
return Point.origin & size;
return null;
}
// Workaround for https://github.com/dart-lang/sdk/issues/25232
@override
void applyPaintTransform(RenderBox child, Matrix4 transform) {
super.applyPaintTransform(child, transform);
}
@override
bool hitTestChildren(HitTestResult result, { Point position }) {
if (child != null) {
assert(child.parentData is BoxParentData);
Point transformed = position + -_effectivePaintOffset;
return child.hitTest(result, position: transformed);
}
return false;
}
}

View File

@@ -11,6 +11,7 @@ import 'package:flutter/services.dart';
import 'debug.dart';
import 'framework.dart';
export 'package:flutter/foundation.dart' show TargetPlatform;
export 'package:flutter/animation.dart';
export 'package:flutter/painting.dart';
export 'package:flutter/rendering.dart' show
@@ -43,10 +44,7 @@ export 'package:flutter/rendering.dart' show
SingleChildLayoutDelegate,
TextOverflow,
ValueChanged,
ValueGetter,
ViewportAnchor,
ViewportDimensions,
ViewportDimensionsChangeCallback;
ValueGetter;
// PAINTING NODES
@@ -1375,72 +1373,6 @@ class Baseline extends SingleChildRenderObjectWidget {
}
}
/// A widget that's bigger on the inside.
///
/// The child of a viewport can layout to a larger size along the viewport's
/// [mainAxis] than the viewport itself. If that happens, only a portion of the
/// child will be visible through the viewport. The portion of the child that is
/// visible is controlled by the scroll offset.
///
/// Viewport is the core scrolling primitive in the system, but it can be used
/// in other situations.
class Viewport extends SingleChildRenderObjectWidget {
/// Creates a widget that's bigger on the inside.
///
/// The [mainAxis] and [paintOffset] arguments must not be null.
Viewport({
Key key,
this.paintOffset: Offset.zero,
this.mainAxis: Axis.vertical,
this.anchor: ViewportAnchor.start,
this.onPaintOffsetUpdateNeeded,
Widget child
}) : super(key: key, child: child) {
assert(mainAxis != null);
assert(paintOffset != null);
}
/// The offset at which to paint the child.
///
/// The offset can be non-zero only in the [mainAxis].
final Offset paintOffset;
/// The direction in which the child is permitted to be larger than the viewport.
///
/// The child is given layout constraints that are fully unconstrained along
/// the main axis (e.g., the child can be as tall as it wants if the main axis
/// is vertical).
final Axis mainAxis;
/// The end of the viewport from which the paint offset is computed.
///
/// See [ViewportAnchor] for more detail.
final ViewportAnchor anchor;
/// Called when the interior or exterior dimensions of the viewport change.
final ViewportDimensionsChangeCallback onPaintOffsetUpdateNeeded;
@override
RenderViewport createRenderObject(BuildContext context) {
return new RenderViewport(
paintOffset: paintOffset,
mainAxis: mainAxis,
anchor: anchor,
onPaintOffsetUpdateNeeded: onPaintOffsetUpdateNeeded
);
}
@override
void updateRenderObject(BuildContext context, RenderViewport renderObject) {
// Order dependency: RenderViewport validates scrollOffset based on mainAxis.
renderObject
..mainAxis = mainAxis
..anchor = anchor
..paintOffset = paintOffset
..onPaintOffsetUpdateNeeded = onPaintOffsetUpdateNeeded;
}
}
// SLIVERS

View File

@@ -1,122 +0,0 @@
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
////////////////////////////////////////////////////////////////////////////////
// DELETE THIS FILE WHEN REMOVING LEGACY SCROLLING CODE
////////////////////////////////////////////////////////////////////////////////
import 'package:flutter/foundation.dart';
import 'framework.dart';
import 'scrollable.dart';
/// A widget that controls whether viewport descendants will overscroll their contents.
/// Overscrolling is clamped at the beginning or end or both according to the
/// [edge] parameter.
///
/// Scroll offset limits are defined by the enclosing Scrollable's [ScrollBehavior].
class ClampOverscrolls extends InheritedWidget {
/// Creates a widget that controls whether viewport descendants will overscroll
/// their contents.
///
/// The [edge] and [child] arguments must not be null.
ClampOverscrolls({
Key key,
this.edge: ScrollableEdge.none,
@required Widget child,
}) : super(key: key, child: child) {
assert(edge != null);
assert(child != null);
}
/// Creates a widget that controls whether viewport descendants will overscroll
/// based on the given [edge] and the inherited ClampOverscrolls widget for
/// the given [context]. For example if edge is ScrollableEdge.leading
/// and a ClampOverscrolls ancestor exists that specified ScrollableEdge.trailing,
/// then this widget would clamp both scrollable edges.
///
/// The [context], [edge] and [child] arguments must not be null.
factory ClampOverscrolls.inherit({
Key key,
@required BuildContext context,
@required ScrollableEdge edge: ScrollableEdge.none,
@required Widget child
}) {
assert(context != null);
assert(edge != null);
assert(child != null);
// The child's clamped edge is the union of the given edge and the
// parent's clamped edge.
ScrollableEdge parentEdge = ClampOverscrolls.of(context)?.edge ?? ScrollableEdge.none;
ScrollableEdge childEdge = edge;
switch (parentEdge) {
case ScrollableEdge.leading:
if (edge == ScrollableEdge.trailing || edge == ScrollableEdge.both)
childEdge = ScrollableEdge.both;
break;
case ScrollableEdge.trailing:
if (edge == ScrollableEdge.leading || edge == ScrollableEdge.both)
childEdge = ScrollableEdge.both;
break;
case ScrollableEdge.both:
childEdge = ScrollableEdge.both;
break;
case ScrollableEdge.none:
break;
}
return new ClampOverscrolls(
key: key,
edge: childEdge,
child: child
);
}
/// Defines when viewport scrollOffsets are clamped in terms of the scrollDirection.
/// If edge is `leading` the viewport's scrollOffset will be clamped at its minimum
/// value (often 0.0). If edge is `trailing` then the scrollOffset will be clamped
/// to its maximum value. If edge is `both` then both the leading and trailing
/// constraints are applied.
final ScrollableEdge edge;
/// Return the [newScrollOffset] clamped according to [edge] and [scrollable]'s
/// scroll behavior. The value of [newScrollOffset] defaults to `scrollable.scrollOffset`.
double clampScrollOffset(ScrollableState scrollable, [double newScrollOffset]) {
final double scrollOffset = newScrollOffset ?? scrollable.scrollOffset;
final double minScrollOffset = scrollable.scrollBehavior.minScrollOffset;
final double maxScrollOffset = scrollable.scrollBehavior.maxScrollOffset;
switch (edge) {
case ScrollableEdge.both:
return scrollOffset.clamp(minScrollOffset, maxScrollOffset);
case ScrollableEdge.leading:
return scrollOffset.clamp(minScrollOffset, double.INFINITY);
case ScrollableEdge.trailing:
return scrollOffset.clamp(double.NEGATIVE_INFINITY, maxScrollOffset);
case ScrollableEdge.none:
return scrollOffset;
}
return scrollOffset;
}
/// The closest instance of this class that encloses the given context.
///
/// Typical usage is as follows:
///
/// ```dart
/// ScrollableEdge edge = ClampOverscrolls.of(context).edge;
/// ```
static ClampOverscrolls of(BuildContext context) {
return context.inheritFromWidgetOfExactType(ClampOverscrolls);
}
@override
bool updateShouldNotify(ClampOverscrolls old) => edge != old.edge;
@override
void debugFillDescription(List<String> description) {
super.debugFillDescription(description);
description.add('edge: $edge');
}
}

View File

@@ -192,7 +192,6 @@ class Focus extends StatefulWidget {
_FocusScope focusScope = key.currentContext.ancestorWidgetOfExactType(_FocusScope);
if (focusScope != null) {
focusScope.focusState._setFocusedWidget(key);
Scrollable.ensureVisible(focusedContext); // ignore: DEPRECATED_MEMBER_USE
Scrollable2.ensureVisible(focusedContext);
}
}
@@ -360,7 +359,6 @@ class _FocusState extends State<Focus> {
BuildContext focusedContext = _focusedWidget?.currentContext;
if (focusedContext == null)
return;
Scrollable.ensureVisible(focusedContext); // ignore: DEPRECATED_MEMBER_USE
Scrollable2.ensureVisible(focusedContext);
}

View File

@@ -1,318 +0,0 @@
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
////////////////////////////////////////////////////////////////////////////////
// DELETE THIS FILE WHEN REMOVING LEGACY SCROLLING CODE
////////////////////////////////////////////////////////////////////////////////
import 'dart:math' as math;
import 'package:flutter/foundation.dart';
import 'package:flutter/physics.dart';
import 'scroll_simulation.dart';
export 'package:flutter/foundation.dart' show TargetPlatform;
Simulation _createSnapScrollSimulation(double startOffset, double endOffset, double startVelocity, double endVelocity) {
return new FrictionSimulation.through(startOffset, endOffset, startVelocity, endVelocity);
}
// TODO(hansmuller): Simplify these classes. We're no longer using the ScrollBehavior<T, U>
// base class directly. Only LazyBlock uses BoundedBehavior's updateExtents minScrollOffset
// parameter; simpler to move that into ExtentScrollBehavior. All of the classes should
// be called FooScrollBehavior. See https://github.com/flutter/flutter/issues/5281
/// An interface for controlling the behavior of scrollable widgets.
///
/// The type argument T is the type that describes the scroll offset.
/// The type argument U is the type that describes the scroll velocity.
abstract class ScrollBehavior<T, U> {
/// Abstract const constructor. This constructor enables subclasses to provide
/// const constructors so that they can be used in const expressions.
///
/// The [platform] must not be null.
const ScrollBehavior({
@required this.platform
});
/// The platform for which physics constants should be approximated.
///
/// This is what makes flings go further on iOS than Android.
///
/// Must not be null.
final TargetPlatform platform;
/// Returns a simulation that propels the scrollOffset.
///
/// This function is called when a drag gesture ends.
///
/// Returns `null` if the behavior is to do nothing.
Simulation createScrollSimulation(T position, U velocity) => null;
/// Returns an animation that ends at the snap offset.
///
/// This function is called when a drag gesture ends and a
/// [SnapOffsetCallback] is specified for the scrollable.
///
/// Returns `null` if the behavior is to do nothing.
Simulation createSnapScrollSimulation(T startOffset, T endOffset, U startVelocity, U endVelocity) => null;
/// Returns the scroll offset to use when the user attempts to scroll
/// from the given offset by the given delta.
T applyCurve(T scrollOffset, T scrollDelta) => scrollOffset;
/// Whether this scroll behavior currently permits scrolling.
bool get isScrollable => true;
@override
String toString() {
List<String> description = <String>[];
debugFillDescription(description);
return '$runtimeType(${description.join("; ")})';
}
/// Accumulates a list of strings describing the current node's fields, one
/// field per string. Subclasses should override this to have their
/// information included in [toString].
@protected
@mustCallSuper
void debugFillDescription(List<String> description) {
description.add(isScrollable ? 'scrollable' : 'not scrollable');
}
}
/// A scroll behavior for a scrollable widget with linear extent (i.e.
/// that only scrolls along one axis).
abstract class ExtentScrollBehavior extends ScrollBehavior<double, double> {
/// Creates a scroll behavior for a scrollable widget with linear extent.
/// We start with an INFINITE contentExtent so that we don't accidentally
/// clamp a scrollOffset until we receive an accurate value in updateExtents.
///
/// The extents and the [platform] must not be null.
ExtentScrollBehavior({
double contentExtent: double.INFINITY,
double containerExtent: 0.0,
@required TargetPlatform platform
}) : _contentExtent = contentExtent,
_containerExtent = containerExtent,
super(platform: platform);
/// The linear extent of the content inside the scrollable widget.
double get contentExtent => _contentExtent;
double _contentExtent;
/// The linear extent of the exterior of the scrollable widget.
double get containerExtent => _containerExtent;
double _containerExtent;
/// Updates either content or container extent (or both)
///
/// Returns the new scroll offset of the widget after the change in extent.
///
/// The [scrollOffset] parameter is the scroll offset of the widget before the
/// change in extent.
double updateExtents({
double contentExtent,
double containerExtent,
double scrollOffset: 0.0
}) {
assert(minScrollOffset <= maxScrollOffset);
if (contentExtent != null)
_contentExtent = contentExtent;
if (containerExtent != null)
_containerExtent = containerExtent;
return scrollOffset.clamp(minScrollOffset, maxScrollOffset);
}
/// The minimum value the scroll offset can obtain.
double get minScrollOffset;
/// The maximum value the scroll offset can obtain.
double get maxScrollOffset;
@override
void debugFillDescription(List<String> description) {
super.debugFillDescription(description);
description.add('content: ${contentExtent.toStringAsFixed(1)}');
description.add('container: ${containerExtent.toStringAsFixed(1)}');
description.add('range: ${minScrollOffset?.toStringAsFixed(1)} .. ${maxScrollOffset?.toStringAsFixed(1)}');
}
}
/// A scroll behavior that prevents the user from exceeding scroll bounds.
class BoundedBehavior extends ExtentScrollBehavior {
/// Creates a scroll behavior that does not overscroll.
BoundedBehavior({
double contentExtent: double.INFINITY,
double containerExtent: 0.0,
double minScrollOffset: 0.0,
@required TargetPlatform platform
}) : _minScrollOffset = minScrollOffset,
super(
contentExtent: contentExtent,
containerExtent: containerExtent,
platform: platform
);
double _minScrollOffset;
@override
double updateExtents({
double contentExtent,
double containerExtent,
double minScrollOffset,
double scrollOffset: 0.0
}) {
if (minScrollOffset != null) {
_minScrollOffset = minScrollOffset;
assert(minScrollOffset <= maxScrollOffset);
}
return super.updateExtents(
contentExtent: contentExtent,
containerExtent: containerExtent,
scrollOffset: scrollOffset
);
}
@override
double get minScrollOffset => _minScrollOffset;
@override
double get maxScrollOffset => math.max(minScrollOffset, minScrollOffset + _contentExtent - _containerExtent);
@override
double applyCurve(double scrollOffset, double scrollDelta) {
return (scrollOffset + scrollDelta).clamp(minScrollOffset, maxScrollOffset);
}
}
/// A scroll behavior that does not prevent the user from exceeding scroll bounds.
class UnboundedBehavior extends ExtentScrollBehavior {
/// Creates a scroll behavior with no scrolling limits.
UnboundedBehavior({
double contentExtent: double.INFINITY,
double containerExtent: 0.0,
@required TargetPlatform platform
}) : super(
contentExtent: contentExtent,
containerExtent: containerExtent,
platform: platform
);
@override
Simulation createScrollSimulation(double position, double velocity) {
return new ScrollSimulation(
position: position,
velocity: velocity,
leadingExtent: double.NEGATIVE_INFINITY,
trailingExtent: double.INFINITY,
platform: platform,
);
}
@override
Simulation createSnapScrollSimulation(double startOffset, double endOffset, double startVelocity, double endVelocity) {
return _createSnapScrollSimulation(startOffset, endOffset, startVelocity, endVelocity);
}
@override
double get minScrollOffset => double.NEGATIVE_INFINITY;
@override
double get maxScrollOffset => double.INFINITY;
@override
double applyCurve(double scrollOffset, double scrollDelta) {
return scrollOffset + scrollDelta;
}
}
/// A scroll behavior that lets the user scroll beyond the scroll bounds with some resistance.
class OverscrollBehavior extends BoundedBehavior {
/// Creates a scroll behavior that resists, but does not prevent, scrolling beyond its limits.
OverscrollBehavior({
double contentExtent: double.INFINITY,
double containerExtent: 0.0,
double minScrollOffset: 0.0,
@required TargetPlatform platform
}) : super(
contentExtent: contentExtent,
containerExtent: containerExtent,
minScrollOffset: minScrollOffset,
platform: platform
);
@override
Simulation createScrollSimulation(double position, double velocity) {
return new ScrollSimulation(
position: position,
velocity: velocity,
leadingExtent: minScrollOffset,
trailingExtent: maxScrollOffset,
platform: platform,
);
}
@override
Simulation createSnapScrollSimulation(double startOffset, double endOffset, double startVelocity, double endVelocity) {
return _createSnapScrollSimulation(startOffset, endOffset, startVelocity, endVelocity);
}
@override
double applyCurve(double scrollOffset, double scrollDelta) {
double newScrollOffset = scrollOffset + scrollDelta;
// If we're overscrolling, we want move the scroll offset 2x
// slower than we would otherwise. Therefore, we "rewind" the
// newScrollOffset by half the amount that we moved it above.
// Notice that we clamp the "old" value to 0.0 so that we only
// reduce the portion of scrollDelta that's applied beyond 0.0. We
// do similar things for overscroll in the other direction.
if (newScrollOffset < minScrollOffset) {
newScrollOffset -= (newScrollOffset - math.min(minScrollOffset, scrollOffset)) / 2.0;
} else if (newScrollOffset > maxScrollOffset) {
newScrollOffset -= (newScrollOffset - math.max(maxScrollOffset, scrollOffset)) / 2.0;
}
return newScrollOffset;
}
}
/// A scroll behavior that lets the user scroll beyond the scroll bounds only when the bounds are disjoint.
class OverscrollWhenScrollableBehavior extends OverscrollBehavior {
/// Creates a scroll behavior that allows overscrolling only when some amount of scrolling is already possible.
OverscrollWhenScrollableBehavior({
double contentExtent: double.INFINITY,
double containerExtent: 0.0,
double minScrollOffset: 0.0,
@required TargetPlatform platform
}) : super(
contentExtent: contentExtent,
containerExtent: containerExtent,
minScrollOffset: minScrollOffset,
platform: platform
);
@override
bool get isScrollable => contentExtent > containerExtent;
@override
Simulation createScrollSimulation(double position, double velocity) {
if ((isScrollable && velocity.abs() > 0) || position < minScrollOffset || position > maxScrollOffset) {
// If the triggering gesture starts at or beyond the contentExtent's limits
// then the simulation only serves to settle the scrollOffset back to its
// minimum or maximum value.
if (position < minScrollOffset || position > maxScrollOffset)
velocity = 0.0;
return super.createScrollSimulation(position, velocity);
}
return null;
}
@override
double applyCurve(double scrollOffset, double scrollDelta) {
if (isScrollable)
return super.applyCurve(scrollOffset, scrollDelta);
return minScrollOffset;
}
}

View File

@@ -6,7 +6,6 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/rendering.dart';
import 'framework.dart';
import 'scroll_behavior.dart';
import 'scroll_physics.dart';
import 'overscroll_indicator.dart';
@@ -78,101 +77,3 @@ class ScrollConfiguration2 extends InheritedWidget {
|| behavior.shouldNotify(old.behavior);
}
}
////////////////////////////////////////////////////////////////////////////////
// DELETE EVERYTHING BELOW THIS LINE WHEN REMOVING LEGACY SCROLLING CODE
////////////////////////////////////////////////////////////////////////////////
/// Controls how [Scrollable] widgets in a subtree behave.
///
/// Used by [ScrollConfiguration].
abstract class ScrollConfigurationDelegate {
/// Abstract const constructor. This constructor enables subclasses to provide
/// const constructors so that they can be used in const expressions.
const ScrollConfigurationDelegate();
/// Returns the platform whose scroll physics should be approximated. See
/// [ScrollBehavior.platform].
TargetPlatform get platform;
/// Returns the ScrollBehavior to be used by generic scrolling containers like
/// [Block].
ExtentScrollBehavior createScrollBehavior();
/// Generic scrolling containers like [Block] will apply this function to the
/// Scrollable they create. It can be used to add widgets that wrap the
/// Scrollable, like scrollbars or overscroll indicators. By default the
/// [scrollWidget] parameter is returned unchanged.
Widget wrapScrollWidget(BuildContext context, Widget scrollWidget) => scrollWidget;
/// Overrides should return true if this ScrollConfigurationDelegate differs
/// from the provided old delegate in a way that requires rebuilding its
/// scrolling container descendants.
bool updateShouldNotify(@checked ScrollConfigurationDelegate old);
}
class _DefaultScrollConfigurationDelegate extends ScrollConfigurationDelegate {
const _DefaultScrollConfigurationDelegate();
@override
TargetPlatform get platform => defaultTargetPlatform;
@override
ExtentScrollBehavior createScrollBehavior() => new OverscrollWhenScrollableBehavior(platform: platform);
@override
bool updateShouldNotify(ScrollConfigurationDelegate old) => false;
}
/// A widget that controls descendant [Scrollable] widgets.
///
/// Classes that create Scrollables are not required to depend on this
/// Widget. The following general purpose scrolling widgets do depend
/// on [ScrollConfiguration]: [Block], [LazyBlock], [ScrollableViewport],
/// [ScrollableList], [ScrollableLazyList]. The [Scrollable] base class uses
/// [ScrollConfiguration] to create its [ScrollBehavior].
class ScrollConfiguration extends InheritedWidget {
/// Creates a widget that controls descendant [Scrollable] widgets.
///
/// If the [delegate] argument is null, the scroll configuration for this
/// subtree is controlled by the default implementation of
/// [ScrollConfigurationDelegate].
ScrollConfiguration({
Key key,
this.delegate,
@required Widget child
}) : super(key: key, child: child);
static const ScrollConfigurationDelegate _defaultDelegate = const _DefaultScrollConfigurationDelegate();
/// Defines the ScrollBehavior and scrollable wrapper for descendants.
final ScrollConfigurationDelegate delegate;
/// The delegate property of the closest instance of this class that encloses
/// the given context.
///
/// If no such instance exists, returns a default
/// [ScrollConfigurationDelegate] that approximates the scrolling physics of
/// the current platform (see [defaultTargetPlatform]) using a
/// [OverscrollWhenScrollableBehavior] behavior model.
///
/// Typical usage is as follows:
///
/// ```dart
/// ScrollConfigurationDelegate scrollConfiguration = ScrollConfiguration.of(context);
/// ```
static ScrollConfigurationDelegate of(BuildContext context) {
ScrollConfiguration configuration = context.inheritFromWidgetOfExactType(ScrollConfiguration);
return configuration?.delegate ?? _defaultDelegate;
}
/// A utility function that calls [ScrollConfigurationDelegate.wrapScrollWidget].
static Widget wrap(BuildContext context, Widget scrollWidget) {
return ScrollConfiguration.of(context).wrapScrollWidget(context, scrollWidget);
}
@override
bool updateShouldNotify(ScrollConfiguration old) {
return delegate?.updateShouldNotify(old.delegate) ?? false;
}
}

View File

@@ -73,7 +73,7 @@ class BouncingScrollPhysics extends ScrollPhysics {
return new BouncingScrollSimulation(
spring: spring,
position: position.pixels,
velocity: velocity,
velocity: velocity * 0.91, // TODO(abarth): We should move this constant closer to the drag end.
leadingExtent: position.minScrollExtent,
trailingExtent: position.maxScrollExtent,
)..tolerance = tolerance;

View File

@@ -81,7 +81,7 @@ class BouncingScrollSimulation extends SimulationGroup {
_currentSimulation = new ScrollSpringSimulation(_spring, position, _leadingExtent, velocity);
return true;
} else if (_currentSimulation == null) {
_currentSimulation = new FrictionSimulation(0.135, position, velocity * 0.91);
_currentSimulation = new FrictionSimulation(0.135, position, velocity);
return true;
}
}
@@ -196,139 +196,3 @@ class ClampingScrollSimulation extends Simulation {
return time >= _duration;
}
}
////////////////////////////////////////////////////////////////////////////////
// DELETE EVERYTHING BELOW THIS LINE WHEN REMOVING LEGACY SCROLLING CODE
////////////////////////////////////////////////////////////////////////////////
final SpringDescription _kScrollSpring = new SpringDescription.withDampingRatio(mass: 0.5, springConstant: 100.0, ratio: 1.1);
final double _kDrag = 0.025;
class _CupertinoSimulation extends FrictionSimulation {
static const double drag = 0.135;
_CupertinoSimulation({ double position, double velocity })
: super(drag, position, velocity * 0.91);
}
class _MountainViewSimulation extends ClampingScrollSimulation {
_MountainViewSimulation({
double position,
double velocity,
double friction: 0.015,
}) : super(
position: position,
velocity: velocity,
friction: friction,
);
}
/// Composite simulation for scrollable interfaces.
///
/// Simulates kinetic scrolling behavior between a leading and trailing
/// boundary. Friction is applied within the extents and a spring action is
/// applied at the boundaries. This simulation can only step forward.
class ScrollSimulation extends SimulationGroup {
/// Creates a [ScrollSimulation] with the given parameters.
///
/// The position and velocity arguments must use the same units as will be
/// expected from the [x] and [dx] methods respectively.
///
/// The leading and trailing extents must use the unit of length, the same
/// unit as used for the position argument and as expected from the [x]
/// method.
///
/// The units used with the provided [SpringDescription] must similarly be
/// consistent with the other arguments.
///
/// The final argument is the coefficient of friction, which is unitless.
ScrollSimulation({
@required double position,
@required double velocity,
@required double leadingExtent,
@required double trailingExtent,
SpringDescription spring,
double drag,
TargetPlatform platform,
}) : _leadingExtent = leadingExtent,
_trailingExtent = trailingExtent,
_spring = spring ?? _kScrollSpring,
_drag = drag ?? _kDrag,
_platform = platform {
assert(position != null);
assert(velocity != null);
assert(_leadingExtent != null);
assert(_trailingExtent != null);
assert(_spring != null);
_chooseSimulation(position, velocity, 0.0);
}
final double _leadingExtent;
final double _trailingExtent;
final SpringDescription _spring;
final double _drag;
final TargetPlatform _platform;
bool _isSpringing = false;
Simulation _currentSimulation;
double _offset = 0.0;
@override
bool step(double time) => _chooseSimulation(
_currentSimulation.x(time - _offset),
_currentSimulation.dx(time - _offset), time);
@override
Simulation get currentSimulation => _currentSimulation;
@override
double get currentIntervalOffset => _offset;
bool _chooseSimulation(double position, double velocity, double intervalOffset) {
if (_spring == null && (position > _trailingExtent || position < _leadingExtent))
return false;
// This simulation can only step forward.
if (!_isSpringing) {
if (position > _trailingExtent) {
_isSpringing = true;
_offset = intervalOffset;
_currentSimulation = new ScrollSpringSimulation(_spring, position, _trailingExtent, velocity);
return true;
} else if (position < _leadingExtent) {
_isSpringing = true;
_offset = intervalOffset;
_currentSimulation = new ScrollSpringSimulation(_spring, position, _leadingExtent, velocity);
return true;
}
}
if (_currentSimulation == null) {
switch (_platform) {
case TargetPlatform.android:
case TargetPlatform.fuchsia:
_currentSimulation = new _MountainViewSimulation(
position: position,
velocity: velocity,
);
break;
case TargetPlatform.iOS:
_currentSimulation = new _CupertinoSimulation(
position: position,
velocity: velocity,
);
break;
}
// No platform specified
_currentSimulation ??= new FrictionSimulation(_drag, position, velocity);
return true;
}
return false;
}
@override
String toString() {
return 'ScrollSimulation(leadingExtent: $_leadingExtent, trailingExtent: $_trailingExtent)';
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -14,7 +14,6 @@ export 'src/widgets/async.dart';
export 'src/widgets/banner.dart';
export 'src/widgets/basic.dart';
export 'src/widgets/binding.dart';
export 'src/widgets/clamp_overscrolls.dart';
export 'src/widgets/container.dart';
export 'src/widgets/debug.dart';
export 'src/widgets/dismissable.dart';
@@ -45,7 +44,6 @@ export 'src/widgets/placeholder.dart';
export 'src/widgets/primary_scroll_controller.dart';
export 'src/widgets/raw_keyboard_listener.dart';
export 'src/widgets/routes.dart';
export 'src/widgets/scroll_behavior.dart';
export 'src/widgets/scroll_configuration.dart';
export 'src/widgets/scroll_controller.dart';
export 'src/widgets/scroll_notification.dart';

View File

@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';

View File

@@ -78,8 +78,7 @@ void main() {
});
testWidgets('Drawer scrolling', (WidgetTester tester) async {
GlobalKey<ScrollableState<Scrollable>> drawerKey =
new GlobalKey<ScrollableState<Scrollable>>(debugLabel: 'drawer');
Key drawerKey = new UniqueKey();
const double appBarHeight = 256.0;
ScrollController scrollOffset = new ScrollController();

View File

@@ -313,7 +313,7 @@ void main() {
await tester.pump(const Duration(milliseconds: 100));
expect(scrollableState.position.pixels, greaterThan(0.0));
}, skip: Scrollable != Scrollable2); // TODO(abarth): re-enable when ensureVisible is implemented
});
testWidgets('Stepper index test', (WidgetTester tester) async {
await tester.pumpWidget(

View File

@@ -33,7 +33,7 @@ void main() {
final Map<String, WidgetBuilder> routes = <String, WidgetBuilder>{
'/': (_) {
return new Material(
child: new Viewport(
child: new SingleChildScrollView(
child: new TwoLevelList(
children: <Widget>[
new TwoLevelListItem(title: new Text('Top'), key: topKey),
@@ -91,7 +91,7 @@ void main() {
final Map<String, WidgetBuilder> routes = <String, WidgetBuilder>{
'/': (_) {
return new Material(
child: new Viewport(
child: new SingleChildScrollView(
child: new TwoLevelList(
children: <Widget>[
new TwoLevelSublist(

View File

@@ -206,26 +206,24 @@ void main() {
SpringDescription spring = new SpringDescription.withDampingRatio(
mass: 1.0, springConstant: 50.0, ratio: 0.5);
ScrollSimulation scroll = new ScrollSimulation(
BouncingScrollSimulation scroll = new BouncingScrollSimulation(
position: 100.0,
velocity: 800.0,
leadingExtent: 0.0,
trailingExtent: 300.0,
spring: spring,
drag: 0.3
);
scroll.tolerance = const Tolerance(velocity: 0.5, distance: 0.1);
expect(scroll.isDone(0.0), false);
expect(scroll.isDone(0.5), false); // switch from friction to spring
expect(scroll.isDone(3.5), true);
ScrollSimulation scroll2 = new ScrollSimulation(
BouncingScrollSimulation scroll2 = new BouncingScrollSimulation(
position: 100.0,
velocity: -800.0,
leadingExtent: 0.0,
trailingExtent: 300.0,
spring: spring,
drag: 0.3
);
scroll2.tolerance = const Tolerance(velocity: 0.5, distance: 0.1);
expect(scroll2.isDone(0.0), false);
@@ -237,13 +235,12 @@ void main() {
SpringDescription spring = new SpringDescription.withDampingRatio(
mass: 1.0, springConstant: 50.0, ratio: 0.5);
ScrollSimulation scroll = new ScrollSimulation(
BouncingScrollSimulation scroll = new BouncingScrollSimulation(
position: 100.0,
velocity: 400.0,
leadingExtent: 0.0,
trailingExtent: double.INFINITY,
spring: spring,
drag: 0.3,
);
scroll.tolerance = const Tolerance(velocity: 1.0);
@@ -251,15 +248,14 @@ void main() {
expect(scroll.x(0.0), 100);
expect(scroll.dx(0.0), 400.0);
expect(scroll.x(1.0) > 330 && scroll.x(1.0) < 335, true);
expect(scroll.x(1.0), closeTo(272.0, 1.0));
expect(scroll.dx(1.0), 120.0);
expect(scroll.dx(2.0), 36.0);
expect(scroll.dx(3.0), 10.8);
expect(scroll.dx(4.0) < 3.5, true);
expect(scroll.dx(1.0), closeTo(54.0, 1.0));
expect(scroll.dx(2.0), closeTo(7.0, 1.0));
expect(scroll.dx(3.0), lessThan(1.0));
expect(scroll.isDone(5.0), true);
expect(scroll.x(5.0) > 431 && scroll.x(5.0) < 432, true);
expect(scroll.x(5.0), closeTo(300.0, 1.0));
// We should never switch
expect(scroll.currentIntervalOffset, 0.0);
@@ -267,13 +263,12 @@ void main() {
test('over/under scroll spring', () {
SpringDescription spring = new SpringDescription.withDampingRatio(mass: 1.0, springConstant: 170.0, ratio: 1.1);
ScrollSimulation scroll = new ScrollSimulation(
BouncingScrollSimulation scroll = new BouncingScrollSimulation(
position: 500.0,
velocity: -7500.0,
leadingExtent: 0.0,
trailingExtent: 1000.0,
spring: spring,
drag: 0.025,
);
scroll.tolerance = const Tolerance(velocity: 45.0, distance: 1.5);
@@ -282,8 +277,8 @@ void main() {
expect(scroll.dx(0.0), closeTo(-7500.0, .0001));
expect(scroll.isDone(0.025), false);
expect(scroll.x(0.025), closeTo(320.0, 1.0));
expect(scroll.dx(0.25), closeTo(-2982, 1.0));
expect(scroll.x(0.025), closeTo(317.0, 1.0));
expect(scroll.dx(0.25), closeTo(-4546, 1.0));
expect(scroll.isDone(2.0), true);
expect(scroll.x(2.0), 0.0);

View File

@@ -10,17 +10,19 @@ import 'rendering_tester.dart';
class TestLayout {
TestLayout() {
// viewport incoming constraints are tight 800x600
// viewport is vertical by default
root = new RenderViewport(
child: new RenderCustomPaint(
painter: new TestCallbackPainter(
onPaint: () { painted = true; }
// incoming constraints are tight 800x600
root = new RenderPositionedBox(
child: new RenderConstrainedBox(
additionalConstraints: const BoxConstraints.tightFor(width: 800.0),
child: new RenderCustomPaint(
painter: new TestCallbackPainter(
onPaint: () { painted = true; }
),
child: child = new RenderConstrainedBox(
additionalConstraints: const BoxConstraints.tightFor(height: 10.0, width: 10.0),
),
),
child: child = new RenderConstrainedBox(
additionalConstraints: const BoxConstraints.tightFor(height: 10.0, width: 10.0)
)
)
),
);
}
RenderBox root;

View File

@@ -12,19 +12,21 @@ void main() {
test("offstage", () {
RenderBox child;
bool painted = false;
// viewport incoming constraints are tight 800x600
// viewport is vertical by default
RenderBox root = new RenderViewport(
child: new RenderOffstage(
child: new RenderCustomPaint(
painter: new TestCallbackPainter(
onPaint: () { painted = true; }
// incoming constraints are tight 800x600
RenderBox root = new RenderPositionedBox(
child: new RenderConstrainedBox(
additionalConstraints: const BoxConstraints.tightFor(width: 800.0),
child: new RenderOffstage(
child: new RenderCustomPaint(
painter: new TestCallbackPainter(
onPaint: () { painted = true; },
),
child: child = new RenderConstrainedBox(
additionalConstraints: const BoxConstraints.tightFor(height: 10.0, width: 10.0),
),
),
child: child = new RenderConstrainedBox(
additionalConstraints: const BoxConstraints.tightFor(height: 10.0, width: 10.0)
)
)
)
),
),
);
expect(child.hasSize, isFalse);
expect(painted, isFalse);

View File

@@ -10,30 +10,32 @@ import 'rendering_tester.dart';
class TestTree {
TestTree() {
// viewport incoming constraints are tight 800x600
// viewport is vertical by default
root = new RenderViewport(
// Place the child to be evaluated within both a repaint boundary and a
// layout-root element (in this case a tightly constrained box). Otherwise
// the act of transplanting the root into a new container will cause the
// relayout/repaint of the new parent node to satisfy the test.
child: new RenderRepaintBoundary(
child: new RenderConstrainedBox(
additionalConstraints: const BoxConstraints.tightFor(height: 20.0, width: 20.0),
child: new RenderRepaintBoundary(
child: new RenderCustomPaint(
painter: new TestCallbackPainter(
onPaint: () { painted = true; }
// incoming constraints are tight 800x600
root = new RenderPositionedBox(
child: new RenderConstrainedBox(
additionalConstraints: const BoxConstraints.tightFor(width: 800.0),
// Place the child to be evaluated within both a repaint boundary and a
// layout-root element (in this case a tightly constrained box). Otherwise
// the act of transplanting the root into a new container will cause the
// relayout/repaint of the new parent node to satisfy the test.
child: new RenderRepaintBoundary(
child: new RenderConstrainedBox(
additionalConstraints: const BoxConstraints.tightFor(height: 20.0, width: 20.0),
child: new RenderRepaintBoundary(
child: new RenderCustomPaint(
painter: new TestCallbackPainter(
onPaint: () { painted = true; },
),
child: new RenderPositionedBox(
child: child = new RenderConstrainedBox(
additionalConstraints: const BoxConstraints.tightFor(height: 20.0, width: 20.0),
),
),
),
child: new RenderPositionedBox(
child: child = new RenderConstrainedBox(
additionalConstraints: const BoxConstraints.tightFor(height: 20.0, width: 20.0)
)
)
)
)
)
)
),
),
),
),
);
}
RenderObject root;
@@ -50,24 +52,26 @@ class MutableCompositor extends RenderProxyBox {
class TestCompositingBitsTree {
TestCompositingBitsTree() {
// viewport incoming constraints are tight 800x600
// viewport is vertical by default
root = new RenderViewport(
// Place the child to be evaluated within a repaint boundary. Otherwise
// the act of transplanting the root into a new container will cause the
// repaint of the new parent node to satisfy the test.
child: new RenderRepaintBoundary(
child: compositor = new MutableCompositor(
child: new RenderCustomPaint(
painter: new TestCallbackPainter(
onPaint: () { painted = true; }
// incoming constraints are tight 800x600
root = new RenderPositionedBox(
child: new RenderConstrainedBox(
additionalConstraints: const BoxConstraints.tightFor(width: 800.0),
// Place the child to be evaluated within a repaint boundary. Otherwise
// the act of transplanting the root into a new container will cause the
// repaint of the new parent node to satisfy the test.
child: new RenderRepaintBoundary(
child: compositor = new MutableCompositor(
child: new RenderCustomPaint(
painter: new TestCallbackPainter(
onPaint: () { painted = true; },
),
child: child = new RenderConstrainedBox(
additionalConstraints: const BoxConstraints.tightFor(height: 20.0, width: 20.0)
),
),
child: child = new RenderConstrainedBox(
additionalConstraints: const BoxConstraints.tightFor(height: 20.0, width: 20.0)
)
)
)
)
),
),
),
);
}
RenderObject root;

View File

@@ -1,40 +0,0 @@
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/rendering.dart';
import 'package:test/test.dart';
import 'rendering_tester.dart';
void main() {
test('Should be able to hit with positive paint offset', () {
RenderBox green = new RenderDecoratedBox(
decoration: const BoxDecoration(
backgroundColor: const Color(0xFF00FF00)
));
RenderBox size = new RenderConstrainedBox(
additionalConstraints: new BoxConstraints.tight(const Size(100.0, 100.0)),
child: green);
RenderBox red = new RenderDecoratedBox(
decoration: const BoxDecoration(
backgroundColor: const Color(0xFFFF0000)
),
child: size);
RenderViewport viewport = new RenderViewport(child: red, paintOffset: const Offset(0.0, 10.0));
layout(viewport);
HitTestResult result;
result = new HitTestResult();
renderer.renderView.hitTest(result, position: const Point(15.0, 0.0));
expect(result.path.first.target.runtimeType, equals(RenderView));
result = new HitTestResult();
renderer.renderView.hitTest(result, position: const Point(15.0, 15.0));
expect(result.path.first.target, equals(green));
});
}

View File

@@ -35,8 +35,8 @@ void main() {
Key childKey = new UniqueKey();
await tester.pumpWidget(
new Center(
child: new Viewport(
mainAxis: Axis.horizontal,
child: new SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: new AspectRatio(
aspectRatio: 2.0,
child: new Container(

View File

@@ -248,7 +248,6 @@ class _FlutterDriverExtension {
Future<ScrollResult> _scrollIntoView(Command command) async {
ScrollIntoView scrollIntoViewCommand = command;
Finder target = await _waitForElement(_createFinder(scrollIntoViewCommand.finder));
await Scrollable.ensureVisible(target.evaluate().single, duration: const Duration(milliseconds: 100));
await Scrollable2.ensureVisible(target.evaluate().single, duration: const Duration(milliseconds: 100), alignment: scrollIntoViewCommand.alignment ?? 0.0);
return new ScrollResult();
}