Chromium Code Reviews| 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 'dart:math' as math; | |
| 6 | |
| 7 import '../animation/scroll_behavior.dart'; | |
| 8 import 'basic.dart'; | |
| 9 import 'scrollable.dart'; | |
| 10 | |
| 11 class ScrollableViewport extends Scrollable { | |
| 12 | |
| 13 ScrollableViewport({ String key, this.child }) : super(key: key); | |
| 14 | |
| 15 Widget child; | |
| 16 | |
| 17 void syncFields(ScrollableViewport source) { | |
| 18 child = source.child; | |
| 19 super.syncFields(source); | |
| 20 } | |
| 21 | |
| 22 ScrollBehavior createScrollBehavior() => new BoundedScrollBehavior(); | |
| 23 BoundedScrollBehavior get scrollBehavior => super.scrollBehavior; | |
| 24 | |
| 25 double _viewportHeight = 0.0; | |
| 26 double _childHeight = 0.0; | |
| 27 void _handleViewportSizeChanged(Size newSize) { | |
| 28 setState(() { | |
| 29 _viewportHeight = newSize.height; | |
| 30 updateScrollBehaviour(); | |
| 31 }); | |
| 32 } | |
| 33 void _handleChildSizeChanged(Size newSize) { | |
| 34 setState(() { | |
| 35 _childHeight = newSize.height; | |
| 36 updateScrollBehaviour(); | |
| 37 }); | |
| 38 } | |
| 39 void updateScrollBehaviour() { | |
| 40 scrollBehavior.maxOffset = math.max(0.0, _childHeight - _viewportHeight); | |
| 41 } | |
|
abarth-chromium
2015/07/09 23:39:35
You need to check scrollOffset to see if its out-o
| |
| 42 | |
| 43 Widget buildContent() { | |
| 44 return new SizeObserver( | |
| 45 callback: _handleViewportSizeChanged, | |
| 46 child: new Viewport( | |
| 47 offset: scrollOffset, | |
| 48 child: new SizeObserver( | |
| 49 callback: _handleChildSizeChanged, | |
| 50 child: child | |
| 51 ) | |
| 52 ) | |
| 53 ); | |
| 54 } | |
| 55 | |
| 56 } | |
| OLD | NEW |