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

Side by Side Diff: sky/sdk/example/widgets/card_collection.dart

Issue 1227823012: Move VariableHeightScrollable to sdk/lib/widgets (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 5 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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 import 'dart:sky' as sky; 5 import 'dart:sky' as sky;
6 6
7 import 'package:vector_math/vector_math.dart'; 7 import 'package:vector_math/vector_math.dart';
8 import 'package:sky/animation/animation_performance.dart'; 8 import 'package:sky/animation/animation_performance.dart';
9 import 'package:sky/animation/scroll_behavior.dart';
10 import 'package:sky/base/lerp.dart'; 9 import 'package:sky/base/lerp.dart';
11 import 'package:sky/painting/text_style.dart'; 10 import 'package:sky/painting/text_style.dart';
12 import 'package:sky/theme/colors.dart'; 11 import 'package:sky/theme/colors.dart';
13 import 'package:sky/widgets/animated_container.dart'; 12 import 'package:sky/widgets/animated_container.dart';
14 import 'package:sky/widgets/basic.dart'; 13 import 'package:sky/widgets/basic.dart';
15 import 'package:sky/widgets/block_viewport.dart';
16 import 'package:sky/widgets/card.dart'; 14 import 'package:sky/widgets/card.dart';
17 import 'package:sky/widgets/scaffold.dart'; 15 import 'package:sky/widgets/scaffold.dart';
18 import 'package:sky/widgets/scrollable.dart'; 16 import 'package:sky/widgets/variable_height_scrollable.dart';
19 import 'package:sky/widgets/theme.dart'; 17 import 'package:sky/widgets/theme.dart';
20 import 'package:sky/widgets/tool_bar.dart'; 18 import 'package:sky/widgets/tool_bar.dart';
21 import 'package:sky/widgets/widget.dart'; 19 import 'package:sky/widgets/widget.dart';
22 20
23 21
24 const int _kCardDismissFadeoutMS = 300; 22 const int _kCardDismissFadeoutMS = 300;
25 const double _kMinFlingVelocity = 700.0; 23 const double _kMinFlingVelocity = 700.0;
26 const double _kMinFlingVelocityDelta = 400.0; 24 const double _kMinFlingVelocityDelta = 400.0;
27 const double _kDismissCardThreshold = 0.6; 25 const double _kDismissCardThreshold = 0.6;
28 26
29 class VariableHeightScrollable extends Scrollable {
30 VariableHeightScrollable({
31 String key,
32 this.builder,
33 this.token
34 }) : super(key: key);
35
36 IndexedBuilder builder;
37 Object token;
38
39 void syncFields(VariableHeightScrollable source) {
40 builder = source.builder;
41 token = source.token;
42 super.syncFields(source);
43 }
44
45 ScrollBehavior createScrollBehavior() => new OverscrollBehavior();
46 OverscrollBehavior get scrollBehavior => super.scrollBehavior;
47
48 void _handleSizeChanged(Size newSize) {
49 setState(() {
50 scrollBehavior.containerHeight = newSize.height;
51 scrollBehavior.contentsHeight = 5000.0;
52 });
53 }
54
55 Widget buildContent() {
56 return new SizeObserver(
57 callback: _handleSizeChanged,
58 child: new BlockViewport(
59 builder: builder,
60 startOffset: scrollOffset,
61 token: token
62 )
63 );
64 }
65 }
66
67 class CardCollectionApp extends App { 27 class CardCollectionApp extends App {
68 28
69 final TextStyle cardLabelStyle = 29 final TextStyle cardLabelStyle =
70 new TextStyle(color: White, fontSize: 18.0, fontWeight: bold); 30 new TextStyle(color: White, fontSize: 18.0, fontWeight: bold);
71 31
72 final List<double> cardHeights = [ 32 final List<double> cardHeights = [
73 48.0, 64.0, 82.0, 46.0, 60.0, 55.0, 84.0, 96.0, 50.0, 33 48.0, 64.0, 82.0, 46.0, 60.0, 55.0, 84.0, 96.0, 50.0,
74 48.0, 64.0, 82.0, 46.0, 60.0, 55.0, 84.0, 96.0, 50.0, 34 48.0, 64.0, 82.0, 46.0, 60.0, 55.0, 84.0, 96.0, 50.0,
35 48.0, 64.0, 82.0, 46.0, 60.0, 55.0, 84.0, 96.0, 50.0,
75 48.0, 64.0, 82.0, 46.0, 60.0, 55.0, 84.0, 96.0, 50.0 36 48.0, 64.0, 82.0, 46.0, 60.0, 55.0, 84.0, 96.0, 50.0
76 ]; 37 ];
77 38
78 List<int> visibleCardIndices; 39 List<int> visibleCardIndices;
79 40
80 CardCollectionApp() { 41 CardCollectionApp() {
81 _activeCardTransform = new AnimatedContainer() 42 _activeCardTransform = new AnimatedContainer()
82 ..position = new AnimatedType<Point>(Point.origin) 43 ..position = new AnimatedType<Point>(Point.origin)
83 ..opacity = new AnimatedType<double>(1.0, end: 0.0); 44 ..opacity = new AnimatedType<double>(1.0, end: 0.0);
84 45
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 return null; 168 return null;
208 return _buildCard(visibleCardIndices[index]); 169 return _buildCard(visibleCardIndices[index]);
209 } 170 }
210 171
211 Widget build() { 172 Widget build() {
212 Widget cardCollection = new Container( 173 Widget cardCollection = new Container(
213 padding: const EdgeDims.symmetric(vertical: 12.0, horizontal: 8.0), 174 padding: const EdgeDims.symmetric(vertical: 12.0, horizontal: 8.0),
214 decoration: new BoxDecoration(backgroundColor: Theme.of(this).primarySwatc h[50]), 175 decoration: new BoxDecoration(backgroundColor: Theme.of(this).primarySwatc h[50]),
215 child: new VariableHeightScrollable( 176 child: new VariableHeightScrollable(
216 builder: _builder, 177 builder: _builder,
217 token: visibleCardIndices.length 178 token: visibleCardIndices.length,
179 itemCount: visibleCardIndices.length
218 ) 180 )
219 ); 181 );
220 182
221 return new Scaffold( 183 return new Scaffold(
222 toolbar: new ToolBar(center: new Text('Swipe Away')), 184 toolbar: new ToolBar(center: new Text('Swipe Away')),
223 body: new SizeObserver(child: cardCollection, callback: _handleSizeChanged ) 185 body: new SizeObserver(child: cardCollection, callback: _handleSizeChanged )
224 ); 186 );
225 } 187 }
226 } 188 }
227 189
228 void main() { 190 void main() {
229 runApp(new CardCollectionApp()); 191 runApp(new CardCollectionApp());
230 } 192 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698