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..a64627fe1d5ff520007854f98cf0ff954bb2ec4a |
--- /dev/null |
+++ b/sky/sdk/lib/widgets/scrollable_viewport.dart |
@@ -0,0 +1,71 @@ |
+// 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 '../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 FlingBehavior(); |
+ FlingBehavior 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.contentsSize = _childHeight; |
+ scrollBehavior.containerSize = _viewportHeight; |
+ if (scrollOffset > scrollBehavior.maxScrollOffset) |
+ settleScrollOffset(); |
+ } |
+ |
+ Widget buildContent() { |
+ return new SizeObserver( |
+ callback: _handleViewportSizeChanged, |
+ child: new Viewport( |
+ offset: scrollOffset, |
+ child: new SizeObserver( |
+ callback: _handleChildSizeChanged, |
+ child: child |
+ ) |
+ ) |
+ ); |
+ } |
+ |
+} |
+ |
+class ScrollableBlock extends Component { |
+ |
+ ScrollableBlock(this.children, { String key }) : super(key: key); |
+ |
+ final List<Widget> children; |
+ |
+ Widget build() { |
+ return new ScrollableViewport( |
+ child: new Block(children) |
+ ); |
+ } |
+ |
+} |