Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(935)

Unified Diff: sky/framework/components/fixed_height_scrollable.dart

Issue 1006533002: Factor a Scrollable base class out of FixedHeightScrollable (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | sky/framework/components/scrollable.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/framework/components/fixed_height_scrollable.dart
diff --git a/sky/framework/components/fixed_height_scrollable.dart b/sky/framework/components/fixed_height_scrollable.dart
index a3b789e78fbb7dadf236694d5055d2daa9da4015..fcb36da06c1763aa12e2261b34e21d582d93a913 100644
--- a/sky/framework/components/fixed_height_scrollable.dart
+++ b/sky/framework/components/fixed_height_scrollable.dart
@@ -2,11 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-import '../animation/fling_curve.dart';
import '../fn.dart';
import 'dart:sky' as sky;
+import 'scrollable.dart';
-abstract class FixedHeightScrollable extends Component {
+abstract class FixedHeightScrollable extends Scrollable {
// TODO(rafaelw): This component really shouldn't have an opinion
// about how it is sized. The owning component should decide whether
// it's explicitly sized or flexible or whatever...
@@ -22,29 +22,18 @@ abstract class FixedHeightScrollable extends Component {
will-change: transform;'''
);
- double minOffset;
- double maxOffset;
-
- double _scrollOffset = 0.0;
- FlingCurve _flingCurve;
- int _flingAnimationId;
double _height = 0.0;
double _itemHeight;
FixedHeightScrollable({
Object key,
- this.minOffset,
- this.maxOffset
- }) : super(key: key) {
- events.listen('gestureflingstart', _handleFlingStart);
- events.listen('gestureflingcancel', _handleFlingCancel);
- events.listen('gesturescrollupdate', _handleScrollUpdate);
- events.listen('wheel', _handleWheel);
+ double minOffset,
+ double maxOffset
+ }) : super(key: key, minOffset: minOffset, maxOffset: maxOffset) {
}
- List<Node> buildItems(int start, int count);
-
void didMount() {
+ super.didMount();
var root = getRoot();
var item = root.firstChild.firstChild;
sky.ClientRect scrollRect = root.getBoundingClientRect();
@@ -65,12 +54,12 @@ abstract class FixedHeightScrollable extends Component {
if (_height > 0.0) {
drawCount = (_height / _itemHeight).round() + 1;
- double alignmentDelta = -_scrollOffset % _itemHeight;
+ double alignmentDelta = -scrollOffset % _itemHeight;
if (alignmentDelta != 0.0) {
alignmentDelta -= _itemHeight;
}
- double drawStart = _scrollOffset + alignmentDelta;
+ double drawStart = scrollOffset + alignmentDelta;
itemNumber = (drawStart / _itemHeight).floor();
transformStyle =
@@ -88,65 +77,4 @@ abstract class FixedHeightScrollable extends Component {
]
);
}
-
- void didUnmount() {
- _stopFling();
- }
-
- bool _scrollBy(double scrollDelta) {
- var newScrollOffset = _scrollOffset + scrollDelta;
- if (minOffset != null && newScrollOffset < minOffset) {
- newScrollOffset = minOffset;
- } else if (maxOffset != null && newScrollOffset > maxOffset) {
- newScrollOffset = maxOffset;
- }
- if (newScrollOffset == _scrollOffset) {
- return false;
- }
-
- setState(() {
- _scrollOffset = newScrollOffset;
- });
- return true;
- }
-
- void _scheduleFlingUpdate() {
- _flingAnimationId = sky.window.requestAnimationFrame(_updateFling);
- }
-
- void _stopFling() {
- if (_flingAnimationId == null) {
- return;
- }
-
- sky.window.cancelAnimationFrame(_flingAnimationId);
- _flingCurve = null;
- _flingAnimationId = null;
- }
-
- void _updateFling(double timeStamp) {
- double scrollDelta = _flingCurve.update(timeStamp);
- if (!_scrollBy(scrollDelta))
- return _stopFling();
- _scheduleFlingUpdate();
- }
-
- void _handleScrollUpdate(sky.GestureEvent event) {
- _scrollBy(-event.dy);
- }
-
- void _handleFlingStart(sky.GestureEvent event) {
- setState(() {
- _flingCurve = new FlingCurve(-event.velocityY, event.timeStamp);
- _scheduleFlingUpdate();
- });
- }
-
- void _handleFlingCancel(sky.GestureEvent event) {
- _stopFling();
- }
-
- void _handleWheel(sky.WheelEvent event) {
- _scrollBy(-event.offsetY);
- }
}
« no previous file with comments | « no previous file | sky/framework/components/scrollable.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698