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

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
« no previous file with comments | « sky/sdk/BUILD.gn ('k') | sky/sdk/lib/widgets/block_viewport.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/animation_builder.dart'; 12 import 'package:sky/widgets/animation_builder.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.containerSize = newSize.height;
51 scrollBehavior.contentsSize = 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 AnimationBuilder() 42 _activeCardTransform = new AnimationBuilder()
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 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 return new Scaffold( 182 return new Scaffold(
222 toolbar: new ToolBar(center: new Text('Swipe Away')), 183 toolbar: new ToolBar(center: new Text('Swipe Away')),
223 body: new SizeObserver(child: cardCollection, callback: _handleSizeChanged ) 184 body: new SizeObserver(child: cardCollection, callback: _handleSizeChanged )
224 ); 185 );
225 } 186 }
226 } 187 }
227 188
228 void main() { 189 void main() {
229 runApp(new CardCollectionApp()); 190 runApp(new CardCollectionApp());
230 } 191 }
OLDNEW
« no previous file with comments | « sky/sdk/BUILD.gn ('k') | sky/sdk/lib/widgets/block_viewport.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698