Index: sky/framework/components/drawer.dart |
diff --git a/sky/framework/components/drawer.dart b/sky/framework/components/drawer.dart |
deleted file mode 100644 |
index 5959bab73c4c11753120738a7bcf340061bc336d..0000000000000000000000000000000000000000 |
--- a/sky/framework/components/drawer.dart |
+++ /dev/null |
@@ -1,156 +0,0 @@ |
-// Copyright 2015 The Chromium Authors. All rights reserved. |
-// Use of this source code is governed by a BSD-style license that can be |
-// found in the LICENSE file. |
- |
-import 'animated_component.dart'; |
-import '../animation/animated_value.dart'; |
-import '../animation/curves.dart'; |
-import '../fn.dart'; |
-import '../theme/colors.dart'; |
-import 'dart:math' as math; |
-import 'dart:sky' as sky; |
-import 'material.dart'; |
- |
-const double _kWidth = 304.0; |
-const double _kMinFlingVelocity = 0.4; |
-const double _kBaseSettleDurationMS = 246.0; |
-const double _kMaxSettleDurationMS = 600.0; |
-const Curve _kAnimationCurve = parabolicRise; |
- |
-typedef void DrawerStatusChangeHandler (bool showing); |
- |
-class DrawerController { |
- |
- DrawerController(this.onStatusChange) { |
- position = new AnimatedValue(-_kWidth, onChange: _checkValue); |
- } |
- final DrawerStatusChangeHandler onStatusChange; |
- AnimatedValue position; |
- |
- bool _oldClosedState = true; |
- void _checkValue() { |
- var newClosedState = isClosed; |
- if (onStatusChange != null && _oldClosedState != newClosedState) { |
- onStatusChange(!newClosedState); |
- _oldClosedState = newClosedState; |
- } |
- } |
- |
- bool get isClosed => position.value == -_kWidth; |
- bool get _isMostlyClosed => position.value <= -_kWidth / 2; |
- void toggle(_) => _isMostlyClosed ? _open() : _close(); |
- |
- void handleMaskTap(_) => _close(); |
- void handlePointerDown(_) => position.stop(); |
- |
- void handlePointerMove(sky.PointerEvent event) { |
- if (position.isAnimating) |
- return; |
- position.value = math.min(0.0, math.max(position.value + event.dx, -_kWidth)); |
- } |
- |
- void handlePointerUp(_) { |
- if (!position.isAnimating) |
- _settle(); |
- } |
- |
- void handlePointerCancel(_) { |
- if (!position.isAnimating) |
- _settle(); |
- } |
- |
- void _open() => _animateToPosition(0.0); |
- |
- void _close() => _animateToPosition(-_kWidth); |
- |
- void _settle() => _isMostlyClosed ? _close() : _open(); |
- |
- void _animateToPosition(double targetPosition) { |
- double distance = (targetPosition - position.value).abs(); |
- if (distance != 0) { |
- double targetDuration = distance / _kWidth * _kBaseSettleDurationMS; |
- double duration = math.min(targetDuration, _kMaxSettleDurationMS); |
- position.animateTo(targetPosition, duration, curve: _kAnimationCurve); |
- } |
- } |
- |
- void handleFlingStart(event) { |
- double direction = event.velocityX.sign; |
- double velocityX = event.velocityX.abs() / 1000; |
- if (velocityX < _kMinFlingVelocity) |
- return; |
- |
- double targetPosition = direction < 0.0 ? -_kWidth : 0.0; |
- double distance = (targetPosition - position.value).abs(); |
- double duration = distance / velocityX; |
- |
- if (distance > 0) |
- position.animateTo(targetPosition, duration, curve: linear); |
- } |
-} |
- |
-class Drawer extends AnimatedComponent { |
- // TODO(abarth): We need a better way to become a container for absolutely |
- // positioned elements. |
- static final Style _style = new Style(''' |
- transform: translateX(0);'''); |
- |
- static final Style _maskStyle = new Style(''' |
- background-color: black; |
- will-change: opacity;''' |
- ); |
- |
- static final Style _contentStyle = new Style(''' |
- background-color: ${Grey[50]}; |
- will-change: transform; |
- width: ${_kWidth}px;''' |
- ); |
- |
- List<UINode> children; |
- int level; |
- DrawerController controller; |
- |
- double _position; |
- |
- Drawer({ |
- Object key, |
- this.controller, |
- this.children, |
- this.level: 0 |
- }) : super(key: key) { |
- animateField(controller.position, #_position); |
- } |
- |
- UINode build() { |
- String maskInlineStyle = 'opacity: ${(_position / _kWidth + 1) * 0.5}'; |
- String contentInlineStyle = 'transform: translateX(${_position}px)'; |
- |
- var mask = new EventListenerNode( |
- new Container( |
- style: _maskStyle, |
- inlineStyle: maskInlineStyle |
- ), |
- onGestureTap: controller.handleMaskTap, |
- onGestureFlingStart: controller.handleFlingStart |
- ); |
- |
- Material content = new Material( |
- content: new Container( |
- style: _contentStyle, |
- inlineStyle: contentInlineStyle, |
- children: children |
- ), |
- level: level); |
- |
- return new EventListenerNode( |
- new FillStackContainer( |
- style: _style, |
- children: [ mask, content ] |
- ), |
- onPointerDown: controller.handlePointerDown, |
- onPointerMove: controller.handlePointerMove, |
- onPointerUp: controller.handlePointerUp, |
- onPointerCancel: controller.handlePointerCancel |
- ); |
- } |
-} |