| OLD | NEW |
| 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/base/lerp.dart'; | 9 import 'package:sky/base/lerp.dart'; |
| 10 import 'package:sky/painting/text_style.dart'; | 10 import 'package:sky/painting/text_style.dart'; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 const double _kDismissCardThreshold = 0.70; | 22 const double _kDismissCardThreshold = 0.70; |
| 23 | 23 |
| 24 class CardCollectionApp extends App { | 24 class CardCollectionApp extends App { |
| 25 | 25 |
| 26 final TextStyle cardLabelStyle = | 26 final TextStyle cardLabelStyle = |
| 27 new TextStyle(color: White, fontSize: 18.0, fontWeight: bold); | 27 new TextStyle(color: White, fontSize: 18.0, fontWeight: bold); |
| 28 | 28 |
| 29 CardCollectionApp() { | 29 CardCollectionApp() { |
| 30 _activeCardAnimation = new AnimationPerformance() | 30 _activeCardAnimation = new AnimationPerformance() |
| 31 ..variable = new AnimatedType(0.0, 1.0) | 31 ..variable = new AnimatedType(0.0, 1.0) |
| 32 ..duration = new Duration(milliseconds: _kCardDismissFadeoutMS); | 32 ..duration = new Duration(milliseconds: _kCardDismissFadeoutMS) |
| 33 _activeCardAnimation.timeline.onValueChanged.listen(_handleAnimationProgress
Changed); | 33 ..addListener(_handleAnimationProgressChanged); |
| 34 } | 34 } |
| 35 | 35 |
| 36 int _activeCardIndex = -1; | 36 int _activeCardIndex = -1; |
| 37 double _activeCardAnchorX; | 37 double _activeCardAnchorX; |
| 38 AnimationPerformance _activeCardAnimation; | 38 AnimationPerformance _activeCardAnimation; |
| 39 double _activeCardWidth; | 39 double _activeCardWidth; |
| 40 bool _activeCardDragUnderway = false; | 40 bool _activeCardDragUnderway = false; |
| 41 Set<int> _dismissedCardIndices = new Set<int>(); | 41 Set<int> _dismissedCardIndices = new Set<int>(); |
| 42 | 42 |
| 43 double get _activeCardOpacity => 1.0 - _activeCardAnimation.progress; | 43 double get _activeCardOpacity => 1.0 - _activeCardAnimation.progress; |
| 44 | 44 |
| 45 double get _activeCardOffset { | 45 double get _activeCardOffset { |
| 46 return _activeCardAnimation.progress * _activeCardWidth * _kDismissCardThres
hold; | 46 return _activeCardAnimation.progress * _activeCardWidth * _kDismissCardThres
hold; |
| 47 } | 47 } |
| 48 | 48 |
| 49 void _handleAnimationProgressChanged(_) { | 49 void _handleAnimationProgressChanged() { |
| 50 setState(() { | 50 setState(() { |
| 51 if (_activeCardAnimation.isCompleted && !_activeCardDragUnderway) | 51 if (_activeCardAnimation.isCompleted && !_activeCardDragUnderway) |
| 52 _dismissedCardIndices.add(_activeCardIndex); | 52 _dismissedCardIndices.add(_activeCardIndex); |
| 53 }); | 53 }); |
| 54 } | 54 } |
| 55 | 55 |
| 56 void _handleSizeChanged(Size newSize) { | 56 void _handleSizeChanged(Size newSize) { |
| 57 _activeCardWidth = newSize.width; | 57 _activeCardWidth = newSize.width; |
| 58 } | 58 } |
| 59 | 59 |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 body: _buildCardCollection( | 157 body: _buildCardCollection( |
| 158 [48.0, 64.0, 82.0, 46.0, 60.0, 55.0, 84.0, 96.0, 50.0, | 158 [48.0, 64.0, 82.0, 46.0, 60.0, 55.0, 84.0, 96.0, 50.0, |
| 159 48.0, 64.0, 82.0, 46.0, 60.0, 55.0, 84.0, 96.0, 50.0]) | 159 48.0, 64.0, 82.0, 46.0, 60.0, 55.0, 84.0, 96.0, 50.0]) |
| 160 ); | 160 ); |
| 161 } | 161 } |
| 162 } | 162 } |
| 163 | 163 |
| 164 void main() { | 164 void main() { |
| 165 runApp(new CardCollectionApp()); | 165 runApp(new CardCollectionApp()); |
| 166 } | 166 } |
| OLD | NEW |