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

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

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

Powered by Google App Engine
This is Rietveld 408576698