| OLD | NEW |
| 1 <!-- | 1 <!-- |
| 2 // Copyright 2015 The Chromium Authors. All rights reserved. | 2 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 3 // Use of this source code is governed by a BSD-style license that can be | 3 // Use of this source code is governed by a BSD-style license that can be |
| 4 // found in the LICENSE file. | 4 // found in the LICENSE file. |
| 5 --> | 5 --> |
| 6 <import src="animation/controller.sky" as="AnimationController" /> | 6 <import src="animation/controller.sky" as="AnimationController" /> |
| 7 <import src="animation/curves.sky" as="Curves" /> | 7 <import src="animation/curves.sky" as="Curves" /> |
| 8 <import src="sky-element/sky-element.sky" as="SkyElement" /> | 8 <import src="sky-element/sky-element.sky" as="SkyElement" /> |
| 9 <import src="sky-scrollable.sky" /> | 9 <import src="sky-scrollable.sky" /> |
| 10 | 10 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 background-color: yellow; | 29 background-color: yellow; |
| 30 will-change: transform; | 30 will-change: transform; |
| 31 position: absolute; | 31 position: absolute; |
| 32 width: 256px; | 32 width: 256px; |
| 33 top: 0; | 33 top: 0; |
| 34 left: 0; | 34 left: 0; |
| 35 bottom: 0; | 35 bottom: 0; |
| 36 } | 36 } |
| 37 </style> | 37 </style> |
| 38 <div id="mask" on-click="handleMaskClick" /> | 38 <div id="mask" on-click="handleMaskClick" /> |
| 39 <div id="content"> | 39 <div id="content" on-gestureflingstart="handleFlingStart"> |
| 40 <content/> | 40 <content/> |
| 41 </div> | 41 </div> |
| 42 </template> | 42 </template> |
| 43 <script> | 43 <script> |
| 44 const kWidth = 256; | 44 const kWidth = 256; |
| 45 const kMinAnimationDurationMS = 120; | 45 const kMinFlingVelocity = 0.4; |
| 46 const kMaxAnimationDurationMS = 500; | 46 const kMinAnimationDurationMS = 246; |
| 47 const kMaxAnimationDurationMS = 600; |
| 47 const kAnimationCurve = Curves.easeInOut; | 48 const kAnimationCurve = Curves.easeInOut; |
| 48 | 49 |
| 49 module.exports = class extends SkyElement { | 50 module.exports = class extends SkyElement { |
| 50 created() { | 51 created() { |
| 51 this.position_ = 0; | 52 this.position_ = 0; |
| 52 this.mask_ = null; | 53 this.mask_ = null; |
| 53 this.content_ = null; | 54 this.content_ = null; |
| 54 this.animation_ = new AnimationController(this); | 55 this.animation_ = new AnimationController(this); |
| 55 } | 56 } |
| 56 | 57 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 | 98 |
| 98 settle_() { | 99 settle_() { |
| 99 if (this.isMostlyClosed) | 100 if (this.isMostlyClosed) |
| 100 this.close(); | 101 this.close(); |
| 101 else | 102 else |
| 102 this.open(); | 103 this.open(); |
| 103 } | 104 } |
| 104 | 105 |
| 105 animateToPosition_(targetPosition) { | 106 animateToPosition_(targetPosition) { |
| 106 var currentPosition = this.position_; | 107 var currentPosition = this.position_; |
| 107 var animationDistance = Math.abs(targetPosition - currentPosition); | 108 var distance = Math.abs(targetPosition - currentPosition); |
| 108 var duration = kMaxAnimationDurationMS * animationDistance / kWidth; | 109 var duration = kMaxAnimationDurationMS * distance / kWidth; |
| 109 this.animation_.start({ | 110 this.animation_.start({ |
| 110 begin: currentPosition, | 111 begin: currentPosition, |
| 111 end: targetPosition, | 112 end: targetPosition, |
| 112 duration: Math.max(kMinAnimationDurationMS, duration), | 113 duration: Math.max(kMinAnimationDurationMS, duration), |
| 113 curve: kAnimationCurve, | 114 curve: kAnimationCurve, |
| 114 }); | 115 }); |
| 115 } | 116 } |
| 116 | 117 |
| 117 updateAnimation(position) { | 118 updateAnimation(position) { |
| 118 this.position = position; | 119 this.position = position; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 132 | 133 |
| 133 handlePointerUp(event) { | 134 handlePointerUp(event) { |
| 134 if (!this.animation_.isAnimating) | 135 if (!this.animation_.isAnimating) |
| 135 this.settle_(); | 136 this.settle_(); |
| 136 } | 137 } |
| 137 | 138 |
| 138 handlePointerCancel(event) { | 139 handlePointerCancel(event) { |
| 139 if (!this.animation_.isAnimating) | 140 if (!this.animation_.isAnimating) |
| 140 this.settle_(); | 141 this.settle_(); |
| 141 } | 142 } |
| 143 |
| 144 handleFlingStart(event) { |
| 145 var direction = Math.sign(event.velocityX); |
| 146 var velocityX = Math.abs(event.velocityX) / 1000; |
| 147 if (velocityX < kMinFlingVelocity) |
| 148 return; |
| 149 var targetPosition = direction < 0 ? -kWidth : 0; |
| 150 var currentPosition = this.position_; |
| 151 var distance = Math.abs(targetPosition - currentPosition); |
| 152 var duration = distance / velocityX; |
| 153 this.animation_.start({ |
| 154 begin: currentPosition, |
| 155 end: targetPosition, |
| 156 duration: duration, |
| 157 curve: Curves.linear, |
| 158 }); |
| 159 } |
| 142 }.register(); | 160 }.register(); |
| 143 </script> | 161 </script> |
| 144 </sky-element> | 162 </sky-element> |
| OLD | NEW |