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

Side by Side Diff: sky/sdk/lib/framework/widgets/fixed_height_scrollable.dart

Issue 1177383006: Rename all the things (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: fix imports Created 5 years, 6 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 unified diff | Download patch
OLDNEW
(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 'package:vector_math/vector_math.dart';
8
9 import '../animation/scroll_behavior.dart';
10 import 'scrollable.dart';
11 import 'basic.dart';
12
13 abstract class FixedHeightScrollable extends Scrollable {
14
15 FixedHeightScrollable({ this.itemHeight, Object key }) : super(key: key) {
16 assert(itemHeight != null);
17 }
18
19 double itemHeight;
20
21 void syncFields(FixedHeightScrollable source) {
22 itemHeight = source.itemHeight;
23 super.syncFields(source);
24 }
25
26 ScrollBehavior createScrollBehavior() => new OverscrollBehavior();
27 OverscrollBehavior get scrollBehavior => super.scrollBehavior as OverscrollBeh avior;
28
29 int _itemCount = 0;
30 int get itemCount => _itemCount;
31 void set itemCount (int value) {
32 if (_itemCount != value) {
33 _itemCount = value;
34 scrollBehavior.contentsHeight = itemHeight * _itemCount;
35 }
36 }
37
38 double _height;
39 void _handleSizeChanged(Size newSize) {
40 setState(() {
41 _height = newSize.height;
42 scrollBehavior.containerHeight = _height;
43 });
44 }
45
46 UINode buildContent() {
47 var itemShowIndex = 0;
48 var itemShowCount = 0;
49
50 Matrix4 transform = new Matrix4.identity();
51
52 if (_height != null && _height > 0.0) {
53 if (scrollOffset < 0.0) {
54 double visibleHeight = _height + scrollOffset;
55 itemShowCount = (visibleHeight / itemHeight).round() + 1;
56 transform.translate(0.0, -scrollOffset);
57 } else {
58 itemShowCount = (_height / itemHeight).ceil() + 1;
59 double alignmentDelta = -scrollOffset % itemHeight;
60 if (alignmentDelta != 0.0)
61 alignmentDelta -= itemHeight;
62
63 double drawStart = scrollOffset + alignmentDelta;
64 itemShowIndex = math.max(0, (drawStart / itemHeight).floor());
65
66 transform.translate(0.0, alignmentDelta);
67 }
68 }
69
70 return new SizeObserver(
71 callback: _handleSizeChanged,
72 child: new ClipRect(
73 child: new Transform(
74 transform: transform,
75 child: new Block(buildItems(itemShowIndex, itemShowCount))
76 )
77 )
78 );
79 }
80
81 List<UINode> buildItems(int start, int count);
82
83 }
OLDNEW
« no previous file with comments | « sky/sdk/lib/framework/widgets/drawer_header.dart ('k') | sky/sdk/lib/framework/widgets/floating_action_button.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698