OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 import '../animation/scroll_behavior.dart'; |
| 6 import 'basic.dart'; |
| 7 import 'scrollable.dart'; |
| 8 |
| 9 class ScrollableViewport extends Scrollable { |
| 10 |
| 11 ScrollableViewport({ String key, this.child }) : super(key: key); |
| 12 |
| 13 Widget child; |
| 14 |
| 15 void syncFields(ScrollableViewport source) { |
| 16 child = source.child; |
| 17 super.syncFields(source); |
| 18 } |
| 19 |
| 20 ScrollBehavior createScrollBehavior() => new FlingBehavior(); |
| 21 FlingBehavior get scrollBehavior => super.scrollBehavior; |
| 22 |
| 23 double _viewportHeight = 0.0; |
| 24 double _childHeight = 0.0; |
| 25 void _handleViewportSizeChanged(Size newSize) { |
| 26 setState(() { |
| 27 _viewportHeight = newSize.height; |
| 28 _updateScrollBehaviour(); |
| 29 }); |
| 30 } |
| 31 void _handleChildSizeChanged(Size newSize) { |
| 32 setState(() { |
| 33 _childHeight = newSize.height; |
| 34 _updateScrollBehaviour(); |
| 35 }); |
| 36 } |
| 37 void _updateScrollBehaviour() { |
| 38 scrollBehavior.contentsSize = _childHeight; |
| 39 scrollBehavior.containerSize = _viewportHeight; |
| 40 if (scrollOffset > scrollBehavior.maxScrollOffset) |
| 41 settleScrollOffset(); |
| 42 } |
| 43 |
| 44 Widget buildContent() { |
| 45 return new SizeObserver( |
| 46 callback: _handleViewportSizeChanged, |
| 47 child: new Viewport( |
| 48 offset: scrollOffset, |
| 49 child: new SizeObserver( |
| 50 callback: _handleChildSizeChanged, |
| 51 child: child |
| 52 ) |
| 53 ) |
| 54 ); |
| 55 } |
| 56 |
| 57 } |
| 58 |
| 59 class ScrollableBlock extends Component { |
| 60 |
| 61 ScrollableBlock(this.children, { String key }) : super(key: key); |
| 62 |
| 63 final List<Widget> children; |
| 64 |
| 65 Widget build() { |
| 66 return new ScrollableViewport( |
| 67 child: new Block(children) |
| 68 ); |
| 69 } |
| 70 |
| 71 } |
OLD | NEW |