Chromium Code Reviews| Index: sky/sdk/lib/widgets/scrollable_viewport.dart |
| diff --git a/sky/sdk/lib/widgets/scrollable_viewport.dart b/sky/sdk/lib/widgets/scrollable_viewport.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..81d64fd3c3be007912254116166f0c91b1d345c1 |
| --- /dev/null |
| +++ b/sky/sdk/lib/widgets/scrollable_viewport.dart |
| @@ -0,0 +1,56 @@ |
| +// 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:math' as math; |
| + |
| +import '../animation/scroll_behavior.dart'; |
| +import 'basic.dart'; |
| +import 'scrollable.dart'; |
| + |
| +class ScrollableViewport extends Scrollable { |
| + |
| + ScrollableViewport({ String key, this.child }) : super(key: key); |
| + |
| + Widget child; |
| + |
| + void syncFields(ScrollableViewport source) { |
| + child = source.child; |
| + super.syncFields(source); |
| + } |
| + |
| + ScrollBehavior createScrollBehavior() => new BoundedScrollBehavior(); |
| + BoundedScrollBehavior get scrollBehavior => super.scrollBehavior; |
| + |
| + double _viewportHeight = 0.0; |
| + double _childHeight = 0.0; |
| + void _handleViewportSizeChanged(Size newSize) { |
| + setState(() { |
| + _viewportHeight = newSize.height; |
| + updateScrollBehaviour(); |
| + }); |
| + } |
| + void _handleChildSizeChanged(Size newSize) { |
| + setState(() { |
| + _childHeight = newSize.height; |
| + updateScrollBehaviour(); |
| + }); |
| + } |
| + void updateScrollBehaviour() { |
| + scrollBehavior.maxOffset = math.max(0.0, _childHeight - _viewportHeight); |
| + } |
|
abarth-chromium
2015/07/09 23:39:35
You need to check scrollOffset to see if its out-o
|
| + |
| + Widget buildContent() { |
| + return new SizeObserver( |
| + callback: _handleViewportSizeChanged, |
| + child: new Viewport( |
| + offset: scrollOffset, |
| + child: new SizeObserver( |
| + callback: _handleChildSizeChanged, |
| + child: child |
| + ) |
| + ) |
| + ); |
| + } |
| + |
| +} |